Ask Your Question
0

Identify Pepperoni Slice: Houghs Circles is Slow

asked 2015-12-04 20:48:45 -0600

Sqzr gravatar image

Hello

I am making a simple fun project that identifies how many pepperoni pieces/slices are on a pizza. The algorithm to count the no. of pepperoni slices is based off this example and is as follows:

  • For each video frame:
    • Convert to gray scale
    • Apply Gaussian Blur to reduce noise
    • Use Hough's Circle to identify all pepperoni slices and the pizza itself
    • If a circle sits inside another circle (pizza): then its a pepperoni slice

Example of the frame input: image description

The execution of the program is incredibly slow (as in 1 frame per second) and the algorithm is very hit and miss. Can you provide advice on why its slow, how I can achieve any speed increases and improve/alternative algorithms? Should I identify slices by their colour instead?

VideoCapture gCapture.open(VIDEO_SAMPLE_PATH);

while (true) {

    if (!gCapture.read(gCameraFeed))
    return -1;

    vector <Vec3f> circles;
    IdentifyCircles(gCameraFeed, circles);
    DrawPepperoni(gCameraFeed, circles);

    imshow(MAIN_WND_TITLE, gCameraFeed);

    // Exit on escape key down
    int c = waitKey(30);
    if ((char)c == 27)
        break;
}

int IdentifyCircles(const Mat& frame, vector<Vec3f>& circles)
{
    // Post: Use Hough Circles algorithm to identify all circles in frame

    Mat grayScaleFrame;
    circles.clear();

    cvtColor(frame, grayScaleFrame, CV_BGR2GRAY);
    GaussianBlur(grayScaleFrame, grayScaleFrame, Size(9, 9), 2, 2);
    HoughCircles(grayScaleFrame, circles, CV_HOUGH_GRADIENT, 1, grayScaleFrame.rows/8, 50, 50, 0, 0);
    putText(gCameraFeed, "Circles Identified: " + to_string(circles.size()), Point(20, 50), 1, 2, Scalar::all(200), 1, 8);

    return 1;
}
edit retag flag offensive close merge delete

Comments

HoughCircles is not very efficient so for real time application I don't think it is a good idea. If you want to use Hough circle try first to locate pizza to have a ROI and then use hough circle only on this ROI.

If you want to know surface Pepperoni Slice may you can use histogram only on ROI (one pizza). In that case I think a parametric model is necessary...

LBerger gravatar imageLBerger ( 2015-12-05 02:39:44 -0600 )edit

@LBerger thanks for your comment. Can you let me know what ROI stands for? I'm new to OpenCV, it doesn't mean return on investment? I'm not committed to hough circles so if there is another algorithm please let me know.

Sqzr gravatar imageSqzr ( 2015-12-05 04:08:58 -0600 )edit

About Region Of Interest there is this post to start. What do you want to measure on pizza?

LBerger gravatar imageLBerger ( 2015-12-05 04:50:20 -0600 )edit

@LBerger The objective is to count how many pepperoni slices are on each pizza - those pizzas with less than 7 will get a circle drawn around them. Any suggestions of the most appropriate algorithm that can achieve this?

Sqzr gravatar imageSqzr ( 2015-12-05 05:04:20 -0600 )edit

Can you post original image?

LBerger gravatar imageLBerger ( 2015-12-05 05:12:03 -0600 )edit

@LBerger just saw your comment now. Heres a link to the original image. Going to go do some more tutorials and research algorithms. Thanks for your help

Sqzr gravatar imageSqzr ( 2015-12-05 16:21:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-12-05 10:24:01 -0600

jmbapps gravatar image

updated 2015-12-05 10:40:12 -0600

Your parameters should be narrowed, imo. I have an app for Apple devices that uses Hough Circles. Use these parameters instead to narrow your results. It takes huge processing power and is slow, use the GPU to speed things up considerably. You should run the Canny Edge Detector as well.

cv::Canny(gray, edges, t1, t2, aS, l2);  //25, 35, 3, true
cv::HoughCircles(gray, circles, CV_HOUGH_GRADIENT, aIr, minCentDist, t2, dFilt, minDist, maxDist);  //2, 50, 35, 40, 30, 50

Understanding what each parameter is will help you considerably. The last two are the smallest circle and largest circle you want to find. Using 0,0 as parameters makes HoughCircles look for every size circle possible and slows things down quite a bit. Use actual numbers that represent the size of your circles (pepperoni) and you will get better results. The dFilt in my parameters is the detection filter, the higher the number the more accurate it is...the lower the number the more false circles you will detect. This is from my Xcode project which is Obj C++. Hope this helps. I did run across FCD which is Fast Circle Detection, it is impervious to background noise. From some professors in Iran long ago...and I could not find anything else on it. Having the picture at an angle, as you do, does help eliminate background noise false readings. If you look at my parameters aIr is Inverse Ratio, minCentDist is the Minimum Distance Between Circe Centers, t2 is Threshold 2 parameter from Canny Edge Detector, dFilt is the Detection Filter, minDist is the smallest circle and maxDist is the largest circle. Only adjust one parameter at a time when fine tuning, or you will chase ghosts forever. :o)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-04 20:48:45 -0600

Seen: 11,936 times

Last updated: Dec 05 '15