What should I do to do convexity defect OpenCV in Android ?

asked 2015-07-03 11:44:46 -0600

ichaka gravatar image

updated 2020-04-08 06:39:20 -0600

Hello. 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. Somebody, please help me. Thank you. 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;
                }
             }
         }
edit retag flag offensive close merge delete