Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.