how to remove green ground from a soccer footage
Hi all,
I am trying to perform player and ball tracking from video footage. How having some issues. Below is a sample code:
Mat grayInputimage = Mat(size(inputImage),CV_8UC1);
int blue,green, red;
cvtColor(inputImage,grayInputimage, CV_BGR2GRAY);
for (int i = 0; i < inputImage.rows; i++) {
for (int j = 0; j < inputImage.cols; j++) {
blue = inputImage.at<Vec3b>(i, j)[0];
green = inputImage.at<Vec3b>(i, j)[1];
red = inputImage.at<Vec3b>(i, j)[2];
if (green > red && (green > blue && red > blue) ) {
grayInputimage.at<uchar>(i, j) = 0;
}
else {
grayInputimage.at<uchar>(i, j) = 1;
}
}
}
The input image is the frame from the video, while the grayimage should be image without the ground color green of the football pitch. However am getting this result. I will like if anyone can help.
You do not need extra parenthesis in the if condition if you use just ANDs; and you have not posted any image. Did it removed some info? Maybe the problem is in red > blue. Another remark: you could use a mask for that condition and setTo(0) instead of that for loop
hi @valentine, hope you don't mind, i removed the duplicate ...
imho, you should use inRange , and not write loops
(also, HSV might work better than BGR)