Ask Your Question

ls998's profile - activity

2016-01-08 02:09:55 -0600 received badge  Student (source)
2016-01-05 16:50:51 -0600 answered a question Convexity defect not working as expected

This issue was being caused by a bug in OpenCV 3.1.0 - https://github.com/Itseez/opencv/issu....

By reverting my OpenCV version back to 2.4.9, the program works properly again.

2016-01-03 15:14:09 -0600 commented question Convexity defect not working as expected

yes. Right now im on Windows, and I have some system limitations, so I'll just have to revert back to 2.4.9 for now

2016-01-03 14:03:41 -0600 commented question Convexity defect not working as expected

Thank you. About when will a version with this fixed be released?

2016-01-03 10:49:44 -0600 asked a question Convexity defect not working as expected

First off, I am using the OpenCV 3.1.0 Java wrapper (NOT JavaCV).

I am trying to find the convexity defects on a hand, but it is not giving the expected results. For examples, here is a binary image of a hand:

image description

(The white lines show the convex hull, and the blue lines show the contour that I am working with).

Here is the same image showing the attempted convexity defect detection:

image description

(blue dots show defects, and pink lines show the resulting shape)

As you can see, the defect between the index and thumb is not being detected.

Here is my code:

    ...
    hull = new MatOfInt();

    Imgproc.convexHull(approxContour, hull, false);

    MatOfInt4 defects = new MatOfInt4();
    Imgproc.convexityDefects(approxContour, hull, defects);

    numPoints = defects.total();
    if (numPoints > max_points) {
        System.out.println("Processing " + max_points + " defect pts");
        numPoints = max_points;
    }

    for (int i = 0; i < numPoints; i++) {
        double[] dat = defects.get(i, 0);

        double[] startdat = approxContour.get((int) dat[0], 0);

        Point startPt = new Point(startdat[0], startdat[1]);

        tipPts[i] = startPt;

        double[] enddat = approxContour.get((int) dat[1], 0);
        endPts[i] = new Point(enddat[0], enddat[1]);

        double[] depthdat = approxContour.get((int) dat[2], 0);
        Point depthPt = new Point(depthdat[0], depthdat[1]);
        foldPts[i] = depthPt;

        depths[i] = dat[3];
    }
    ...
    for (int i = 0; i < numPoints; i++) {
        Imgproc.circle(im, tipPts[i], 2, new Scalar(0, 0, 255));
        Imgproc.circle(im, foldPts[i], 2, new Scalar(255, 0, 0));
        Imgproc.circle(im, endPts[i], 2, new Scalar(0, 255, 0));
        Imgproc.line(im, tipPts[i], foldPts[i], new Scalar(255, 0, 255));
        Imgproc.line(im, tipPts[i], endPts[i], new Scalar(255, 255, 255));
        Imgproc.line(im, endPts[i], foldPts[i], new Scalar(255, 0, 255));
    }