U
U
uSide2014-08-16 15:46:52
JavaScript
uSide, 2014-08-16 15:46:52

How to find circle coordinates on canvas?

There is this image:
52085ed7b59547d7be9b70f087ccff23.png
How can I find the coordinates of this circle?
(That is, in the task, the circle is in a different place each time. I need to process the image and find the circle)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
barkalov, 2014-08-16
@uSide

I believe this problem is easiest to solve "on the forehead" by enumeration:

var bestCircleness = 0;
var bestX, bestY, bestRadius;

for (var x = 0; x < width; x++) {
    for (var y = 0; y < height; y++) {
        for (var radius = minRadius; radius <= maxRadius; radius++) {
            var circleness = getCircleness(x, y, radius);
            if (circleness > bestCircleness) {
                bestCircleness = circleness;
                bestX = x;
                bestY = y;
                bestRadius = radius;
            }
        }
    }
}

Where the function getCircleness(x, y, radius) returns the number of black pixels inside a circle with an inner/outer radius of radius±1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question