且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-23 12:01:52

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

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

现在的答案是:

作为文档, 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, ...

希望它帮助。