Identify Pepperoni Slice: Houghs Circles is Slow
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:
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;
}
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 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.
About Region Of Interest there is this post to start. What do you want to measure on pizza?
@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?
Can you post original image?
@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