OpenCV Circle Detection

Discussion related to "under the hood" OpenMV topics.
lab
Posts: 18
Joined: Wed Mar 21, 2018 9:02 pm

OpenCV Circle Detection

Postby lab » Fri May 11, 2018 7:15 pm

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
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: OpenCV Circle Detection

Postby kwagyeman » Fri May 11, 2018 8:01 pm

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/m ... ugh.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.
Nyamekye,
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: OpenCV Circle Detection

Postby kwagyeman » Fri May 11, 2018 8:02 pm

I will add improving this to my list of things to do.
Nyamekye,
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: OpenCV Circle Detection

Postby kwagyeman » Fri May 11, 2018 8:02 pm

To help us, generating a high quality PR which adds this feature would be appreciated.
Nyamekye,
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: OpenCV Circle Detection

Postby kwagyeman » Sun May 13, 2018 7:34 pm

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.
Attachments
firmware.zip
(2.16 MiB) Downloaded 13 times
Nyamekye,
lab
Posts: 18
Joined: Wed Mar 21, 2018 9:02 pm

Re: OpenCV Circle Detection

Postby lab » Mon May 14, 2018 12:53 pm

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

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests