Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the largest circle in palm contour

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?