Reputation: 5182
I would like to segment a part of an image (video stream), between 2 gray images.
When the stream starts, I take an image. Then I make another IplImage but where each pixel's intensity is added by a number. Now i would like to keep everything between these 2 image.
My code atm
// 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);
The 2 threshold images are : depthInit and depthInitLayer2
The stream is the variable "result"
Now to use these 2 image to threshold the stream
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);
Though unfortunately this is not working.
My question why ?
Thx in advance
Upvotes: 1
Views: 538
Reputation: 5182
The method "inrange" by opencv does the trick . In my case (with some renamed variables)
cvInRange(result, threshold1, threshold2, difference2);
The results of 1 pixel in the stream (output) :
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)
This pixel with intensity 189 is in the interval of [217,187] so it's gets a 255 (white)
On the other hand this pixel with intensity 240 is not in the interval , so gets 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)
Upvotes: 1