将 16 位深度 CvMat* 转换为 8 位深度
我正在使用 Kinect 和 OpenCV。我已经在这个论坛中搜索过,但没有找到与我的问题类似的内容。 我保留来自 Kinect(16 位)的原始深度数据,将其存储在 CvMat* 中,然后将其传递给 cvGetImage 以从中创建 IplImage*:
CvMat* depthMetersMat = cvCreateMat( 480, 640, CV_16UC1 );
[...]
cvGetImage(depthMetersMat,temp);
但现在我需要处理该图像才能执行 cvThreshdold并找到轮廓。这两个函数需要输入 8 位深度的图像。如何将 CvMat* heightMetersMat 转换为 8 位深度-CvMat* ?
I'm working with Kinect and OpenCV. I already search in this forum but I didn't find anything like my problem.
I keep the raw depth data from Kinect (16 bit), I store it in a CvMat* and then I pass it to the cvGetImage to create an IplImage* from it:
CvMat* depthMetersMat = cvCreateMat( 480, 640, CV_16UC1 );
[...]
cvGetImage(depthMetersMat,temp);
But now I need to work on this image in order to do cvThreshdold and find contours. These 2 functions need an 8-bit-depth-image in input. How can I convert the CvMat* depthMetersMat in an 8-bit-depth-CvMat* ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@SSteve 给出的答案几乎对我有用,但是对
convertTo
的调用似乎只是砍掉了高位字节,而不是实际将值缩放到 8 位范围。由于@Sirnino 没有指定想要哪种行为,我想我应该发布将执行(线性)缩放的代码,以防其他人想要这样做。SSteve 的原始代码:
要缩放值,您只需添加比例因子(1/256,或 0.00390625,对于 16 位到 8 位缩放)作为第三个参数(alpha)对
convertTo
的调用您还可以添加第四个参数 (delta),该参数将在乘以 alpha 后添加到每个值。有关详细信息,请参阅文档。
The answer that @SSteve gave almost did the trick for me, but the call to
convertTo
seemed to just chop off the high order byte instead of actually scaling the values to an 8-bit range. Since @Sirnino didn't specify which behavior was wanted, I thought I'd post the code that will do the (linear) scaling, in case anyone else is wanting to do that.SSteve's original code:
To scale the values, you just need to add the scale factor (1/256, or 0.00390625, for 16-bit to 8-bit scaling) as the third parameter (alpha) to the call to
convertTo
You can also add a fourth parameter (delta) that will be added to each value after it is multiplied by alpha. See the docs for more info.
这应该有效:
但是根据OpenCV文档,CvMat是过时的。你应该使用 Mat 来代替。
This should work:
But according to the OpenCV docs, CvMat is obsolete. You should use Mat instead.