OpenCV中的Java凸缺陷(计算机视觉) [英] OpenCV Java convexity defects (Computer Vision)

查看:715
本文介绍了OpenCV中的Java凸缺陷(计算机视觉)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有把我凸缺陷在框架上的问题。为了计算这些,我修改C ++源代码,这就是我存档:

I have a problem with putting my convexity defects on the frame. To calculate them, I modified c++ source and this is what i archived:

    mConvexityDefectsMatOfInt4 = new MatOfInt4();

    if(contours.size() > 0 && convexHullMatOfInt.rows() > 0)
        Imgproc.convexityDefects(contours.get(0), convexHullMatOfInt,   mConvexityDefectsMatOfInt4);

不过,Imgproc.drawContours(...)方法要求传递给它作为一个参数convexityDefects将ArrayList的。我不知道我怎么能进行转换。我曾与凸包也是类似的问题,但我发现了一个外观图释:

However, the Imgproc.drawContours(...) method requires that convexityDefects passed to it as a parameters will be ArrayList. I don't know how can I make the conversion. I had also similar problem with convex hulls, but I found out a walkaround:

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

有关凸缺陷类似的解决方案是行不通的。有没有人对我怎么能解决这个问题的想法?

Similar solution for convexity defects is not working. Does anyone have an idea on how can I solve the problem?

如何从MatOfInt4()来的ArrayList()转换为能够得出凸性缺陷?

推荐答案

(我自己也挣扎了这么多与 convexityDefect ,我想杀谁就写的​​Java接口对于OpenCV的!)

(I myself was struggling so much with convexityDefect that I wanted to kill whoever has written the Java interface for OpenCV!)

现在的答案是:

作为<一说href=\"http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#convexitydefects\"相对=nofollow>文档, MatOfInt4 基本上就是一个包含以下信息的4元素整型数组:

As stated in docs, MatOfInt4 is basically a 4-element integer array containing the following information:

start_index
end_index
farthest_pt_index
fixpt_depth

您可以使用下面的方法 mConvexityDefectsMatOfInt4 转换为整数的列表:

You can use the following to convert mConvexityDefectsMatOfInt4 to a list of integers:

List<Integer> cdList = mConvexityDefectsMatOfInt4.toList();

现在,在 cdList 4的每个连续元素持有上述的信息:

Now, each 4 consecutive elements in cdList holds the info stated above:

cdList 0 : 23    
cdList 1 : 30      
cdList 2 : 26    
cdList 3 : 18101
-----------------
cdList 4 : 30
cdList 5 : 44
cdList 6 : 33
cdList 7 : 43738

因此​​,举例来说,如果你只想绘制每个凹的最远点,你可以简单地使用每4个元素的第三个指标。在这种情况下:26,33,...

So, for example if you want to draw only the farthest point of each concavity, you can simply use the third index of each 4 elements. In this case: 26, 33, ...

希望它帮助。

这篇关于OpenCV中的Java凸缺陷(计算机视觉)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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