Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

According to the documentation:

convexityDefects – The output vector of convexity defects. In C++ and the new Python/Java interface each convexity defect is represented as 4-element integer vector (a.k.a. cv::Vec4i): (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices in the original contour of the convexity defect beginning, end and the farthest point, and fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the farthest contour point and the hull. That is, to get the floating-point value of the depth will be fixpt_depth/256.0.

So your code and what you are doing is more or less correct. However, your extracted indices from the convexHull() function call is not correct. You need to call it as follows:

convexHull( c, h, true );

then you will obtain the desired result ;-).

According to the documentation:

convexityDefects – The output vector of convexity defects. In C++ and the new Python/Java interface each convexity defect is represented as 4-element integer vector (a.k.a. cv::Vec4i): (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices in the original contour of the convexity defect beginning, end and the farthest point, and fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the farthest contour point and the hull. That is, to get the floating-point value of the depth will be fixpt_depth/256.0.

So your code and what you are doing is more or less correct. However, your extracted indices from the convexHull() function call is not correct. You need to call it as follows:

convexHull( c, h, true );

then you will obtain the desired result ;-).

;-). If you check the documentation for the convexHull() function the third parameter is related to the convex hull orientation. If it is true, the output convex hull is oriented clockwise. Otherwise (default), it is oriented counter-clockwise.

According to the documentation:

convexityDefects – The output vector of convexity defects. In C++ and the new Python/Java interface each convexity defect is represented as 4-element integer vector (a.k.a. cv::Vec4i): (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices in the original contour of the convexity defect beginning, end and the farthest point, and fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the farthest contour point and the hull. That is, to get the floating-point value of the depth will be fixpt_depth/256.0.

So your code and what you are doing is more or less correct. However, your extracted indices from the convexHull() function call is are not correct. in the correct order. You need to call it as follows:

convexHull( c, h, true );

then you will obtain the desired result ;-). If you check the documentation for the convexHull() function the third parameter is related to the convex hull orientation. If it is true, the output convex hull is oriented clockwise. Otherwise (default), it is oriented counter-clockwise.