Question

i'm working on color tracking.. and i'm specifically tracking an orange ball, a basketball ball perhaps, along with kinect for the body, i'm making a free throw shooting guide. here's my case

i have already thresholded my image, eroded it to remove noise, and other insignificant objects (non-ball) and then dilated a few times to emphasize the ball.. and so i've come to a final binary image - where i've successfully isolated the ball.. there are other blobs..(smaller blobs that aren't the ball).. how do i get the largest blob(the ball) and put a bounding box?

i've tried hough circles btw, however this is very slow,,..thanks! some code would be useful

Was it helpful?

Solution

This is the code I used to get the largest blob in the image:

public static Blob FindLargestObject(Image<Gray, byte> block, Rectangle rectangle)
    {
        Image<Gray, byte> mask = block.CopyBlank();

        Contour<Point> largestContour = null;
        double largestarea = 0;

        for (var contours = block.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
            RETR_TYPE.CV_RETR_EXTERNAL); contours != null; contours = contours.HNext)
        {
            if (contours.Area > largestarea)
            {
                largestarea = contours.Area;
                largestContour = contours;
            }
        }

        // fill the largest contour
        mask.Draw(largestContour, new Gray(255), -1);

        return new Blob(mask, largestContour, rectangle);
    }

For Blob:

public class Blob 
{
    Image<Gray,byte> Mask{ get; set; }
    Contour<Point> Contour { get; set; }
    Rectangle Rectangle { get; set; }
}

The blob will contain all the information that you want to get.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top