问题描述
我是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;
}
}
}
推荐答案
hull.add(new MatOfInt()); // add a new MatOfInt, but what does it contain?
Imgproc.convexHull(newContours.get(i), hull.get(i));
这篇关于为什么Android中的凸性缺陷OpenCV会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!