为什么Android中的凸性缺陷OpenCV会出错? [英] Why is my convexity defect OpenCV in Android getting error?

查看:66
本文介绍了为什么Android中的凸性缺陷OpenCV会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发中的初学者,也是OpenCV中的新手。我有关于Android手势识别的项目。我想对它做凸性缺陷。在我做凸性缺陷之前,我应该找到轮廓和凸包。我已经做过了。现在,我正在做凸度缺陷以获得手和手指的缺陷。但是有些不对劲。当我在我的Android中使用凸性缺陷构建我的代码时,很遗憾它停止了。我不知道我的凸性缺陷函数是错误的,还是我得到缺陷值(MatOfInt4)到Point的方式是错误的。有人,请帮帮我。谢谢。这是我的代码:



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;
             }
          }
      }

推荐答案

您最有可能尝试使用一个尚未在某处初始化的变量。在以下两行中,您在外壳列表中创建一个新条目,然后将其发送到 Imgproc.convexHull 。但是你可能没有任何数据。

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.
hull.add(new MatOfInt()); // add a new MatOfInt, but what does it contain?
Imgproc.convexHull(newContours.get(i), hull.get(i));


请问您以后如何解决?


这篇关于为什么Android中的凸性缺陷OpenCV会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆