Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
             }
          }
      }
Posted
Updated 7-Apr-17 22:56pm
v2

You are most likely trying to use a variable that has not been initialised somewhere. In the following two lines you create a new entry in the hull list, and then send it to Imgproc.convexHull. However you may not have any data in it.
Java
hull.add(new MatOfInt()); // add a new MatOfInt, but what does it contain?
Imgproc.convexHull(newContours.get(i), hull.get(i));
 
Share this answer
 
Comments
Annisa Kartikasari 5-Jul-15 1:24am    
@Richard MacCutchan that's not the problem. I need that line to add new type data MatOfInt to variable hull that will be used to store data hull from function Imgproc.convexHull. So, I got data from function Imgproc.convexHull. And I'm successfull on it, the result has showed up. The problem is when I try to do convexity defect with function Imgproc.convexityDefect, the apps is unfortunately stopped when I debugged it in my android device.
Richard MacCutchan 5-Jul-15 2:58am    
Where did it stop, and what messages showed in the debug log?
Annisa Kartikasari 8-Jul-15 4:54am    
I have solved this problem. Thank for your help
please How you solved it later ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900