Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detection of table tennis balls and color correction

Hello

I am making a robot project and I am trying to detect the tables tennis balls in pictures (from a webcam) like this.

Hej

I have tried different smoothing functions and tried a lot different numbers in the parameters to the functions, but the image (pre-processed) that gives best results look like this.

image description

The camera stand foot got detected as a circle but I removed that result and 4 balls are not found. This is the balls I find at the end.

So far

This is my code:

src = Highgui.imread("Picture 10.jpg",1);
Mat srcH = new Mat();
src.convertTo(srcH, -1, 0.7, 0);
Highgui.imwrite("contrast.jpg", srcH);

Imgproc.cvtColor(srcH, src_gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(src_gray, src_gray);
Highgui.imwrite("outgray.jpg", src_gray);
Imgproc.GaussianBlur(src_gray, smooth, new Size(11,11),4, 4);
Highgui.imwrite("blur.jpg", smooth);
Imgproc.HoughCircles(smooth, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 20, 81, 29, 10, 13);

System.out.println("Found "+circles.cols() + " circles.");
for (int i = 0; i < circles.cols(); i++) {
    double[] circle = circles.get(0,i);
    if (src.get((int)circle[1], (int)circle[0])[2]>140){
        list.add(new Ball((int)circle[0],(int)circle[1]));
        Point center = new Point((int)circle[0], (int)circle[1]);

    int radius =  (int) circle[2];
    // circle center
    Core.circle( src, center, 3, new Scalar(0,255,0), -1, 8, 0 );
    // circle outline
    Core.circle( src, center, radius, new Scalar(0,0,255), 3, 8, 0 );
    }
}

Do you guys have any ideas about why the last 4 balls are not detected and how the pre-processing can be improved?

I am also having trouble detecting the colored circles on the robot. Sometimes it works, sometimes it doesn't. I think the sunlight affects the detection. I found this color balance technique which is implemented in Matlab (I think) and I have no idea how I would translate that to OpenCV. Any advice on how to translate that would also be appreciated.

Detection of table tennis balls and color correction

Hello

I am making a robot project and I am trying to detect the tables tennis balls in pictures (from a webcam) like this.

Hej

I have tried different smoothing functions and tried a lot different numbers in the parameters to the functions, but the image (pre-processed) that gives best results look like this.

image description

The camera stand foot got detected as a circle but I removed that result and 4 balls are not found. This is the balls I find at the end.

So far

This is my code:

src = Highgui.imread("Picture 10.jpg",1);
Mat srcH = new Mat();
src.convertTo(srcH, -1, 0.7, 0);
Highgui.imwrite("contrast.jpg", srcH);

Imgproc.cvtColor(srcH, src_gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(src_gray, src_gray);
Highgui.imwrite("outgray.jpg", src_gray);
Imgproc.GaussianBlur(src_gray, smooth, new Size(11,11),4, 4);
Highgui.imwrite("blur.jpg", smooth);
Imgproc.HoughCircles(smooth, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 20, 81, 29, 10, 13);

System.out.println("Found "+circles.cols() + " circles.");
for (int i = 0; i < circles.cols(); i++) {
    double[] circle = circles.get(0,i);
    if (src.get((int)circle[1], (int)circle[0])[2]>140){
        list.add(new Ball((int)circle[0],(int)circle[1]));
        Point center = new Point((int)circle[0], (int)circle[1]);

     int radius =  (int) circle[2];
     // circle center
     Core.circle( src, center, 3, new Scalar(0,255,0), -1, 8, 0 );
     // circle outline
     Core.circle( src, center, radius, new Scalar(0,0,255), 3, 8, 0 );
 }
}

Do you guys have any ideas about why the last 4 balls are not detected and how the pre-processing can be improved?

I am also having trouble detecting the colored circles on the robot. Sometimes it works, sometimes it doesn't. I think the sunlight affects the detection. I found this color balance technique which is implemented in Matlab (I think) and I have no idea how I would translate that to OpenCV. Any advice on how to translate that would also be appreciated.

Detection of table tennis balls and color correction

Hello

I am making a robot project and I am trying to detect the tables tennis balls in pictures (from a webcam) like this.

Hej

I have tried different smoothing functions and tried a lot different numbers in the parameters to the functions, but the image (pre-processed) that gives best results look like this.

image description

The camera stand foot got detected as a circle but I removed that result and 4 balls are not found. This is the balls I find at the end.

So far

This is my code:

src = Highgui.imread("Picture 10.jpg",1);
Mat srcH = new Mat();
src.convertTo(srcH, -1, 0.7, 0);
Highgui.imwrite("contrast.jpg", srcH);

Imgproc.cvtColor(srcH, src_gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(src_gray, src_gray);
Highgui.imwrite("outgray.jpg", src_gray);
Imgproc.GaussianBlur(src_gray, smooth, new Size(11,11),4, 4);
Highgui.imwrite("blur.jpg", smooth);
Imgproc.HoughCircles(smooth, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 20, 81, 29, 10, 13);

System.out.println("Found "+circles.cols() + " circles.");
for (int i = 0; i < circles.cols(); i++) {
    double[] circle = circles.get(0,i);
    if (src.get((int)circle[1], (int)circle[0])[2]>140){
        list.add(new Ball((int)circle[0],(int)circle[1]));
        Point center = new Point((int)circle[0], (int)circle[1]);

        int radius =  (int) circle[2];
        // circle center
        Core.circle( src, center, 3, new Scalar(0,255,0), -1, 8, 0 );
        // circle outline
        Core.circle( src, center, radius, new Scalar(0,0,255), 3, 8, 0 );
 }
}

Do you guys have any ideas about why the last 4 balls are not detected and how the pre-processing can be improved?

I am also having trouble detecting the colored circles on the robot. Sometimes it works, sometimes it doesn't. I think the sunlight affects the detection. I found this color balance technique which is implemented in Matlab (I think) and I have no idea how I would translate that to OpenCV. Any advice on how to translate that would also be appreciated.

Detection of table tennis balls and color correction

Hello

I am making a robot project and I am trying to detect the tables tennis balls in pictures (from a webcam) like this.

Hej

I have tried different smoothing functions and tried a lot different numbers in the parameters to the functions, but the image (pre-processed) that gives best results look like this.

image description

The camera stand foot got detected as a circle but I removed that result and 4 balls are not found. This is the balls I find at the end.

So far

This is my code:

src = Highgui.imread("Picture 10.jpg",1);
Mat srcH = new Mat();
src.convertTo(srcH, -1, 0.7, 0);
Highgui.imwrite("contrast.jpg", srcH);

Imgproc.cvtColor(srcH, src_gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(src_gray, src_gray);
Highgui.imwrite("outgray.jpg", src_gray);
Imgproc.GaussianBlur(src_gray, smooth, new Size(11,11),4, 4);
Highgui.imwrite("blur.jpg", smooth);
Imgproc.HoughCircles(smooth, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 20, 81, 29, 10, 13);

System.out.println("Found "+circles.cols() + " circles.");
for (int i = 0; i < circles.cols(); i++) {
    double[] circle = circles.get(0,i);
    if (src.get((int)circle[1], (int)circle[0])[2]>140){
        list.add(new Ball((int)circle[0],(int)circle[1]));
        Point center = new Point((int)circle[0], (int)circle[1]);

        int radius =  (int) circle[2];
        // circle center
        Core.circle( src, center, 3, new Scalar(0,255,0), -1, 8, 0 );
        // circle outline
        Core.circle( src, center, radius, new Scalar(0,0,255), 3, 8, 0 );
     }
}

Do you guys have any ideas about why the last 4 balls are not detected and how the pre-processing can be improved?

I am also having trouble detecting the colored circles on the robot. Sometimes it works, sometimes it doesn't. I think the sunlight affects the detection. I found this color balance technique which is implemented in Matlab (I think) and I have no idea how I would translate that to OpenCV. Any advice on how to translate that would also be appreciated.