Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

background substraction of an image

Actually, I'm trying to substract the background from this image. Apparantly, I just want to substract the green background and here is the code I'm using:

Mat img_object = imread(patternImageName);
Mat imageInHSV;
cvtColor(img_object, imageInHSV, CV_BGR2HSV);

Mat chan[3],imgThreshed, processed;
split( imageInHSV, chan );
Mat H = chan[0];
// compute statistics for Hue value
cv::Scalar mean, stddev;
cv::meanStdDev(H, mean, stddev);

// ensure we get 95% of all valid Hue samples (statistics 3*sigma rule)
float minHue = 80;
float maxHue = 95;
cout << "MinValue :" << mean[0] << " MaxHue:" << stddev[0] << endl;
cout << H << endl;
// STEP 2: detection phase
cv::inRange(H, cv::Scalar(minHue), cv::Scalar(maxHue), imgThreshed);
imshow("thresholded", imgThreshed);

I checked the values of the channel H to decide the minHue and maxHue so I choosed the interval of the most frequent values in the matrix which will definitely be the green one. But, I got this result which is obsiously not what I'm looking for because there is missing stuff in it. Any idea how to improve it? how to get better substract the background from this kind of images?