Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV Java凸面缺陷(计算机视觉)_Java_Android_C++_Opencv_Convexity Defects - Fatal编程技术网

OpenCV Java凸面缺陷(计算机视觉)

OpenCV Java凸面缺陷(计算机视觉),java,android,c++,opencv,convexity-defects,Java,Android,C++,Opencv,Convexity Defects,我有一个问题,把我的凸面缺陷的框架。为了计算它们,我修改了C++源,这就是我所存档的: mConvexityDefectsMatOfInt4 = new MatOfInt4(); if(contours.size() > 0 && convexHullMatOfInt.rows() > 0) Imgproc.convexityDefects(contours.get(0), convexHullMatOfInt, mConvexi

我有一个问题,把我的凸面缺陷的框架。为了计算它们,我修改了C++源,这就是我所存档的:

    mConvexityDefectsMatOfInt4 = new MatOfInt4();

    if(contours.size() > 0 && convexHullMatOfInt.rows() > 0)
        Imgproc.convexityDefects(contours.get(0), convexHullMatOfInt,   mConvexityDefectsMatOfInt4);
但是,Imgproc.drawContours(…)方法要求作为参数传递给它的凸面效果将是ArrayList。我不知道怎样才能转换。我对凸面外壳也有类似的问题,但我发现了一个解决方案:

  convexHullMatOfInt = new MatOfInt();
  convexHullPointArrayList = new ArrayList<Point>();
  convexHullMatOfPoint = new MatOfPoint();
  convexHullMatOfPointArrayList = new ArrayList<MatOfPoint>();

  //Calculate convex hulls
  if(contours.size() > 0)
  {
    Imgproc.convexHull( contours.get(0), convexHullMatOfInt, false );
    for(int j=0; j < convexHullMatOfInt.toList().size(); j++)
      convexHullPointArrayList.add(contours.get(0).toList().get(convexHullMatOfInt.toList().get(j)));
    convexHullMatOfPoint.fromList(convexHullPointArrayList);
    convexHullMatOfPointArrayList.add(convexHullMatOfPoint);   
  }
convexHullMatOfInt=new MatOfInt();
convexHullPointArrayList=新ArrayList();
convexHullMatOfPoint=新的MatOfPoint();
convexHullMatOfPointArrayList=新ArrayList();
//计算凸包
如果(等高线.size()>0)
{
Imgproc.CONVERXHULL(轮廓.get(0),CONVERXHULMOTOFINT,false);
对于(int j=0;j
对于凸性缺陷的类似解决方案不起作用。有人知道我如何解决这个问题吗

如何从MatOfInt4()转换到ArrayList(),以便能够绘制凸面缺陷?

(我自己一直在为凸面缺陷挣扎,以至于我想杀死为OpenCV编写Java接口的人!)

现在答案是:

如中所述,
MatOfInt4
基本上是一个包含以下信息的4元素整数数组:

start_index
end_index
farthest_pt_index
fixpt_depth
您可以使用以下命令将
mconvexitydefectsmotfint4
转换为整数列表:

List<Integer> cdList = mConvexityDefectsMatOfInt4.toList();
因此,例如,如果只想绘制每个凹度的最远点,只需使用每4个元素的第三个索引即可。在这种情况下:26,33

希望它能有所帮助。

(我自己也在为凸性缺陷挣扎,我想杀死为OpenCV编写Java接口的人!)

现在答案是:

如中所述,
MatOfInt4
基本上是一个包含以下信息的4元素整数数组:

start_index
end_index
farthest_pt_index
fixpt_depth
您可以使用以下命令将
mconvexitydefectsmotfint4
转换为整数列表:

List<Integer> cdList = mConvexityDefectsMatOfInt4.toList();
因此,例如,如果只想绘制每个凹度的最远点,只需使用每4个元素的第三个索引即可。在这种情况下:26,33

希望有帮助。

以下是一个示例:

for (int i = 0; i < contours.size(); i++) {
    convDef.add(new MatOfInt4());
    Imgproc.convexityDefects(contours.get(i), hull.get(i),
        convDef.get(i));
    cdList = convDef.get(i).toList();
    Point data[] = contours.get(i).toArray();

    for (int j = 0; j < cdList.size(); j = j+4) {
        Point start = data[cdList.get(j)];
        Point end = data[cdList.get(j+1)];
        Point defect = data[cdList.get(j+2)];
        //Point depth = data[cdList.get(j+3)];

        Imgproc.circle(mat, start, 5, new Scalar(0, 255, 0), 2);
        Imgproc.circle(mat, end, 5, new Scalar(0, 255, 0), 2);
        Imgproc.circle(mat, defect, 5, new Scalar(0, 255, 0), 2);
    }
}
for(int i=0;i
以下是一个示例:

for (int i = 0; i < contours.size(); i++) {
    convDef.add(new MatOfInt4());
    Imgproc.convexityDefects(contours.get(i), hull.get(i),
        convDef.get(i));
    cdList = convDef.get(i).toList();
    Point data[] = contours.get(i).toArray();

    for (int j = 0; j < cdList.size(); j = j+4) {
        Point start = data[cdList.get(j)];
        Point end = data[cdList.get(j+1)];
        Point defect = data[cdList.get(j+2)];
        //Point depth = data[cdList.get(j+3)];

        Imgproc.circle(mat, start, 5, new Scalar(0, 255, 0), 2);
        Imgproc.circle(mat, end, 5, new Scalar(0, 255, 0), 2);
        Imgproc.circle(mat, defect, 5, new Scalar(0, 255, 0), 2);
    }
}
for(int i=0;i