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,它没有保存为16位;事实上,我做了以下事情:
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;
相关文章:
- 将浮动的heightmap数组导出为16位原始值
- 宽度为奇数的16位纹理为片状
- OpenGL 16 位模板缓冲区?
- 为什么将双精度转换为 int 似乎在第 16 位数字之后将其四舍五入?
- 16 位到 10 位转换代码说明
- AVX2 整数乘以有符号 8 位元素,产生有符号 16 位结果?
- C++将 16 位值转换为 32 位值
- 24 位地址和 24 位算术与 24 位地址与 16 位地址算术之间的区别?
- 16 位系统中的程序如何访问大于 65535 的整数,但不能访问地址
- 将 Uint8(浮点AUDIO_F32)转换为int16_t(16 位 PCM)
- AVX2 SIMD Instrinsics 16 位到 8 位,反之亦然
- 如何打开和读取16位.raw文件Vc++(Wince 平台)
- MongoDB C++ 驱动程序 - 8 位和 16 位整数?
- 使用 OpenCV 和 C++将 16 位灰度图像更改为彩色图像
- 对 32 位整数进行哈希处理比对 3 个 16 位整数的哈希进行按位运算慢?
- OpenCV 实感 16 位深度图像
- 有没有办法让32位C 编译器遵循16位整数促销规则
- 如何将 16 位无符号 int 转换为 8 位无符号字符并最终返回无符号字符*?
- 为什么16位编译器会给未知的char []声明提供错误
- OpenCV(C++):如何保存16位图像