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;
}