Imgproc.convexityDefects(); In eclipse + java + opencv

Imgproc.convexityDefects(); In eclipse + java + opencv

本文关键字:eclipse java opencv In convexityDefects Imgproc      更新时间:2023-10-16

我需要有关Java语言中convexitydefect()函数的信息。

这就是功能:

 Imgproc.convexityDefects(MatOfPoint contour, MatOfInt convexhull, MatOfInt4 convexityDefects)

结果是凸面缺陷变量:

MatOfInt4 convexityDefects;

现在在c++中,凸缺陷的结构是:

CvPoint* start; // point of the contour where the defect begins
CvPoint* end; // point of the contour where the defect ends
CvPoint* depth_point; // the farthest from the convex hull point within the defect
float depth; 

但是Java为行返回了4 int!如何在java中获取有关开始、结束、depth_point和深度的信息?

您提到的convexityDefects结构仅用于C API。对于C++和Java,很难比文档中已有的答案更好:

在C++和新的Python/Java接口中,每个凸性缺陷都表示为4元整向量(也称为cv::Vec4i):(start_indexend_indexfarthest_pt_indexfixpt_depth),其中索引是凸性缺陷开始、结束和最远点的原始轮廓中基于0的索引,并且CCD_ 8是最远轮廓点和船体之间的距离的定点近似(具有8个小数比特)。也就是说,要得到的浮点值的深度将是fixpt_depth/256.0

因此,startend是4个int的前两个元素,并且包含到contour的索引。depth_point是第三个元素,并且是contour中最深点的索引。将最后一个元素除以256,得到深度的浮点值。