1

我想在 2 个灰色图像之间分割图像(视频流)的一部分。

当流开始时,我会拍一张照片。然后我制作另一个 IplImage 但每个像素的强度都加上一个数字。现在我想保留这两个图像之间的所有内容。

我的自动取款机

 // Get the initial image 
 depthInit.copyFrom(result.getBufferedImage());  

 //Create an image where every intensity is 10, which will be added to the initial image.
 cvSet(scalarImage,cvScalar(10, 0, 0, 0));

 // De init image wordt verhoogt met de hoogte van de laag 
 cvAdd(depthInit, scalarImage, depthInitLayer2, null);

2 个阈值图像是:depthInit 和 depthInitLayer2

流是变量“结果”

现在使用这两个图像来阈值流

cvZero(difference);

// Select everything that is greater than the depthInit image
cvCmp(result, depthInit, difference, CV_CMP_GT);


cvZero(difference2);

// Select everything that is smaler than the depthInitLayer2 
cvCmp(difference, depthInitLayer2, difference2, CV_CMP_LT);

虽然不幸的是这不起作用。

我的问题为什么?

提前谢谢

4

1 回答 1

1

opencv 的“inrange”方法可以解决问题。在我的情况下(有一些重命名的变量)

 cvInRange(result, threshold1, threshold2,  difference2);

流中 1 个像素的结果(输出):

Stream value (189.0, 0.0, 0.0, 0.0)
threshold1 value (187.0, 0.0, 0.0, 0.0)
threshold2 value (217.0, 0.0, 0.0, 0.0)
After thresholding value (255.0, 0.0, 0.0, 0.0)

这个强度为 189 的像素在 [217,187] 的区间内,因此它得到 255(白色)

另一方面,这个强度为 240 的像素不在区间内,因此为 0

Stream value (240.0, 0.0, 0.0, 0.0)
threshold1 value (187.0, 0.0, 0.0, 0.0)
threshold2 value (217.0, 0.0, 0.0, 0.0)
After thresholding value (0.0, 0.0, 0.0, 0.0)
于 2012-03-23T10:40:11.983 回答