Why is my convexity defect OpenCV in Android getting error?

341 views Asked by At

I'm beginner in Android development and newbie in OpenCV too. I have project about hand gesture recognition in Android. I want to do convexity defect on it. Before I do convexity defect, I should have done finding contour and convex hull. I have done them already. Now, I'm doing convexity defect to get defect of the hand and fingers. But there is something wrong. When I build my code with convexity defect in my Android, It's unfortunately stopped. I don't know whether my convexity defect function is wrong, or the way I get value of defect (MatOfInt4) to Point is wrong.

This is my code :

List<MatOfInt> hull = new ArrayList<MatOfInt>();
List<MatOfInt4> defect = new ArrayList<MatOfInt4>();
for(int i = 0; i < newContours.size(); i++)
    {
        hull.add(new MatOfInt());
        Imgproc.convexHull(newContours.get(i), hull.get(i));
        Imgproc.convexityDefects(newContours.get(i), hull.get(i), defect.get(i));
    }

    Point defectSP= new Point();
    Point defectEP= new Point();
    Point defectFP= new Point();
    for(int i = 0; i < defect.size(); i++)
    {
        Point[] startP = new Point[newContours.get(i).rows()];
        Point[] endP = new Point[newContours.get(i).rows()];
        Point[] farP = new Point[newContours.get(i).rows()];
        Point[] depthP = new Point[newContours.get(i).rows()];

        for(int j = 0; j < defect.get(i).rows(); j++)
        {
            int distP = (int) defect.get(i).get(j, 3)[3];
            if (distP > 20*256)
            {
                startId = (int) defect.get(i).get(j, 0)[0];
                endId = (int) defect.get(i).get(j, 1)[1];
                farId = (int) defect.get(i).get(j, 2)[2];

                defectSP.x = startId;
                defectSP.y = startId;
                defectEP.x = endId;
                defectEP.y = endId;
                defectFP.x = farId;
                defectFP.y = farId;
            }
         }
     }
0

There are 0 answers