the largest circle in palm contour

asked 2015-12-24 07:39:12 -0500

Momo gravatar image

Hi.

I implemented the algorithm and the result is very good . for example

image description

code:

    public Point centerHand(final List<Point> points,final MatOfPoint contour) {

    ExecutorService executor = Executors.newFixedThreadPool(10);

    final double[] distance = new double[points.size()];

    for(int j=0; j<distance.length;j++) {

        final int i = j;

        executor.execute(new Runnable() {

            @Override
            public void run() {
                distance[i] = findMinDistance(contour.toList(), points.get(i));         
            }
        });

    }

    executor.shutdown();
    executor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

    int maxIndex = -1;
    double maxDistance = 0;
    for (int index = 0; index < distance.length; index++)
    {
        if (distance[index] > maxDistance)
        {
            maxDistance = distance[index];
            maxIndex = index;
        }
    }

    Core.circle(image, points.get(maxIndex), (int)maxDistance, new Scalar(0,0,255));

    return points.get(maxIndex);

}

private double findMinDistance(List<Point> contourPoints, Point candidate)
{
    double result = Double.MAX_VALUE;
    for(Point p : contourPoints)
    {
        result = Math.min(lenght(p, candidate), result);
    }
    return result;
}

Unfortunately this algorithm is brutal and it works very slowly. How can I do the same thing but faster?

edit retag flag offensive close merge delete

Comments

1

Have you try distanceTransform?

LBerger gravatar imageLBerger ( 2015-12-24 08:45:58 -0500 )edit

pointPolygonTest if you are checking for points inside, or incrementing r as you check for intersection: https://docs.opencv.org/3.4.0/d3/dc0/...

sirius gravatar imagesirius ( 2018-02-09 19:38:08 -0500 )edit