Ask Your Question
0

background substraction of an image

asked 2015-03-23 11:03:22 -0600

maystroh gravatar 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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-03-23 12:10:55 -0600

Potato gravatar image

There is OpenCV functionality for calculating background subtraction. However, you would need an image of the plain green background. This would be the bottleneck as I am assuming that you have only the one picture to work with.

Take a look at this link, it might be of some help --> http://docs.opencv.org/trunk/doc/tuto...

What this functionality does is that it calculates the foreground over a sequence of images and through a thresholding function, gives you the output you desire.

Everything is well documented and well explained. There might be a different way to implement it because of the changes with OpenCV 3.0.0. If you choose this method and have trouble implementing it, do not hesitate to ask,

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-23 11:03:22 -0600

Seen: 342 times

Last updated: Mar 23 '15