OpenCV(C ++):如何保存16位图像? [英] OpenCV (C++): how to save a 16bit image?
问题描述
我使用kinect,我需要保存RAW深度图像。这意味着我不应该保存它与转换为8位(这是什么imwrite是做!),但保存为16位,没有任何位深度减少。我希望这个问题不会太微不足道,但我是新来的OpenCV编程。我试过下面的,但它不工作:
I'm working with kinect, and I need to save RAW depth image. This means that I shouldn't save it with a conversion to 8 bit (that is what imwrite is doing!) but save it as 16 bit, without have any bit-depth reducing. I hope that this question will not be too trivial, but I'm new to OpenCV programming. I tried the following, but it doesn't work:
[...]
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时)。
它不保存为16bit,因为VideoCapture;实际上我做了以下:
The problem wasn't in the way the image was saved, that was all right (if someone will have the same problem, be sure to save in PNG/TIFF format and specify CV_16UC1 when reading). It wasn't saved as 16bit because of VideoCapture; in fact I did the following:
if ( capture.retrieve( imageDepth, CAP_OPENNI_DISPARITY_MAP ) ) {
imwrite( fileDepth, imageDepth );
}
但正确的做法是:
if ( capture.retrieve( imageDepth, CAP_OPENNI_DEPTH_MAP ) ) {
imwrite( fileDepth, imageDepth );
}
这是一个愚蠢的问题。
所有尝试帮助我的人。
So it was a silly problem.
Thanks to all the people who tried to help me.
这篇关于OpenCV(C ++):如何保存16位图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!