OpenCV Circle Detection

I am interested in implementing the OpenCV’s circle finding algorithm, i.e:

cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,dp,minDist,param1=,param2=,minRadius=,maxRadius=)

to do circle detection. In my application, there are multiple circle sizes, so it is important to set the minimum and maximum radii in order to restrict the range of sizes to be able to efficiently find circles. I played around with find_circles included in OpenMV, but it will find circles of different sizes.

Can you please help me import cv2’s HoughCircles source code into OpenMV? I followed your instructions to set up the OpenMV Firmware Development on my Linux virtual machine, but I’m not sure how to implement the source code in OpenMV. I searched on GitHub and this seems to be the source code that I want to use: opencv/modules/imgproc/src/hough.cpp

Hi, the circle detection code on OpenMV already is based on the OpenCV one. The OpenCV method will not fit on the OpenMV Cam due to memory constraints.

Anyway, it sound like you want to improve the speed for the find circles algorithm on the OpenMV Cam. This can be done by adding some more parameters to our current method to look for particular radiuses.

Please see this code here:

https://github.com/openmv/openmv/blob/master/src/omv/img/hough.c#L678

Just made the min and Max value of R a parameter and you’ll have it run much faster like the OpenCV one.

I will add improving this to my list of things to do.

To help us, generating a high quality PR which adds this feature would be appreciated.

Okay, your request is implemented. Please add “r_min”, “r_max”, and “r_step” as keyword arguments to find_circles to speed up the algorithm. I easily got a speed up to 17 FPS by reducing the radius.

Attached is the firmware. Use the tools->run bootloader option to update the firmware. Either the firmware.bin or the openmv.dfu file will work. Try the firmware.bin file first.
firmware.zip (2.16 MB)

Thanks! I tested it and the ability to distinguish between different circle sizes is much improved.