繁体   English   中英

OpenCV(C ++):如何保存16位图像?

[英]OpenCV (C++): how to save a 16bit image?

我正在使用kinect,我需要保存RAW深度图像。 这意味着我不应该通过转换为8位来保存它(这就是imwrite正在做的事情!)但是将其保存为16位,而没有任何位深度减少。 我希望这个问题不会太微不足道,但我是OpenCV编程的新手。 我尝试了以下,但它不起作用:

[...]

Mat imageDepth ( 480, 640, CV_16UC1 );
Mat imageRGB;

// Video stream settings
VideoCapture capture;
capture.open( CAP_OPENNI );

if ( !capture.isOpened() ) {
  cerr << "Cannot get video stream!" << endl;
  exit ( EXIT_WITH_ERROR );
}

if ( !capture.grab() ) {
  cerr << "Cannot grab images!" << endl;
  exit ( EXIT_WITH_ERROR );
}

// Getting frames
if ( capture.retrieve( imageDepth, CAP_OPENNI_DISPARITY_MAP ) ) {
  imwrite( fileDepth, imageDepth );
}
if( capture.retrieve( imageRGB, CAP_OPENNI_BGR_IMAGE ) ) {
  imwrite( fileRGB, imageRGB );
}

return EXIT_WITH_SUCCESS;

提前致谢。

问题不在于图像的保存方式,这样就可以了(如果有人遇到同样的问题,请确保以PNG / TIFF格式保存并在阅读时指定CV_16UC1)。 由于VideoCapture,它没有保存为16bit; 事实上我做了以下事情:

if ( capture.retrieve( imageDepth, CAP_OPENNI_DISPARITY_MAP ) ) {
   imwrite( fileDepth, imageDepth );
}

但正确的方法是:

if ( capture.retrieve( imageDepth, CAP_OPENNI_DEPTH_MAP ) ) {
  imwrite( fileDepth, imageDepth );
}

所以这是一个愚蠢的问题。
感谢所有试图帮助我的人。

我在opencv中的imwrite似乎不支持16位图像存储。 所以,我使用了OpenCV FileStorage类。

接下来是相关的代码段。 写作:

cv::FileStorage fp("depth_file.xml", cv::FileStorage::WRITE);
fp << "dframe" << dframe;
fp.release();

读:

cv::FileStorage fs(dframeName, cv::FileStorage::READ);
if( fs.isOpened() == false)
{
    cerr<< "No More....Quitting...!";
    return 0;
}
fs["dframe"] >> dframe;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM