I am trying to detect the center&radius of an arc like shown below for my thesis by using open cv. I tried many things and searched a lot, but cant figure out. Could please somebody help me? I would be really glad.
-
It is a really small part of my thesis (I hope your thesis was not about just to detect a circle) and I am about to loose my mind because of searching. I dont know what makes you think that you can comment on the level of need I have, but still i tried to answer neatly. I hope it cleared your concerns. – ginny Jul 08 '20 at 22:23
-
2Hey, welcome to Stack Overflow! It would be good if you could provide some more details about the question. What is your data? What did you try already? Did you find solutions to similar problems? – Simon Zyx Jul 08 '20 at 22:28
-
Hello, yeah I understand. Sorry this is my first post. I tried Ransac Circle Detection, find contours and minEnclosingCircle and also template matching with image moments. But I keep failing to detect a robust center location, and since I do not have so much experience in the field, I also cannot overcome the problem that center is out the borders of the picture. I was hoping that somebody has a better idea. – ginny Jul 08 '20 at 22:32
-
2The main challenge here is that your circles/ellipses are incomplete. You could try 2 approaches: 1) Hough circle transform to see if you can describe a circle that passes exactly through your arc points or 2) ellipse fitting. – stateMachine Jul 08 '20 at 22:34
-
Having a quick look around I found this, could this help? https://riptutorial.com/opencv/example/22518/circular-blob-detection – Steak Overflow Jul 08 '20 at 22:36
-
I will also try all of them, thanks – ginny Jul 08 '20 at 22:40
2 Answers
I would not do the center finding itself with OpenCV but with simple 2D geometry instead see first bullet in Circular approximation of polygon (or its part) so:
filter out blobs not on curve
segmentate and remove too small (unconnected) blobs
find 3 points on your curve
They should be far enough from each and should form 2 lines (black). You can apply thinning algorithms to enhance precision. than simply find 2 most distant points from the curve and one that is in half way between them.
cast normal axises from their mid points (brown)
simply rotate the line slope by 90 deg by swapping
x,y
of direction vector and negating one of them so(-y,x)
or(y,-x)
.find the intersection its the center you are looking for
find radius
its the average of distance between center and the 3 points ...
Here a small example I just did in paint (its hand drawn so not pixel perfect):

- 49,595
- 11
- 110
- 380
-
I perfectly get your point and I believe it would work. Thanks a lot for this approach, I was so focused on CV2 I couldn't think of using simple geometry. – ginny Jul 09 '20 at 08:40
-
@ginny I am using this to compute curvature radius in vector trajectory data all the time for motion controlling purposes (it affects max safe speed possible so machines does not disassembly itself or persons and stuff nearby... :) ) – Spektre Jul 09 '20 at 10:16
Here is my simple approach algorithm:
- Look at the angle contour by wide-view, like:
- Check each pixel of this wide-view image one by one and find the norms(lengths) for each point of the contours. (To be clear: for each pixel, find lengths to those contour points)
- If all lengths are equal for a pixel then that pixel is the center of the circle.
Note: This is simple approach and absolutely works. Just not sure about does it take long time to calculate for cpu.

- 4,085
- 4
- 18
- 39
-
1that is `O(m*n^2)` and `n` is not known ahead (but at least multiple of `m`) so it must be guessed ... maybe better would be convert it to fitting the position from just few points along the curve and finding local optimum for lengths like [CCD](https://stackoverflow.com/a/24135139/2521214) ...but still casting 2 lines and computing intersection is much more faster/easier (but this could be used to focus search near found center) – Spektre Jul 09 '20 at 06:51
-
-
2`CCD` Is used mostly in robotics and stands for `Cyclic Coordinate Descent` do not confuse with `charge coupled device` (that are CCD cameras and stuff). The idea is to guess any start position , look at all directions from that by single step and chose the best ... and repeat again until solution found or stuck in local min/max – Spektre Jul 09 '20 at 07:22
-
Thanks for these ideas. Then I am assuming if by chance I could convert my problem to a case where I know the radius, this process would be quite easy, right? – ginny Jul 09 '20 at 08:37
-
@ginny I think you dont need to know the radius because if all lengths are equal for a pixel then that pixel is the center. There can not exist any other pixel equal to all contour points – Yunus Temurlenk Jul 09 '20 at 08:40
-
@ginny just do not forget to minimize abs difference between all radiuses (with this approach) as the arc might have pixelation errors or not be perfectly circular and also the curve is thick ... (loop through all possible combinations of x,y, compute min and max distance to each pixel of curve and remember position where the max-min is minimal – Spektre Jul 09 '20 at 10:17
-
@ginny to speed up the x,y for loops you can use CCD or any [approximation search](https://stackoverflow.com/a/36163847/2521214) for non monotonous data... as heuristics converting to roughly `O(m*n)` or `O(m*log^2(n))` – Spektre Jul 09 '20 at 10:22