posted by 심재형 2017. 11. 15. 13:14

convexityDefects

Finds the convexity defects of a contour.

C++: void convexityDefects(InputArray contour, InputArray convexhull, OutputArray convexityDefects)
Python: cv2.convexityDefects(contour, convexhull[, convexityDefects]) → convexityDefects
C: CvSeq* cvConvexityDefects(const CvArr* contour, const CvArr* convexhull, CvMemStorage* storage=NULL )
Python: cv.ConvexityDefects(contour, convexhull, storage) → convexityDefects
Parameters:
  • contour – Input contour.
  • convexhull – Convex hull obtained using convexHull() that should contain indices of the contour points that make the hull.
  • 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. In C interface convexity defect is represented by CvConvexityDefectstructure - see below.
  • storage – Container for the output sequence of convexity defects. If it is NULL, the contour or hull (in that order) storage is used.

The function finds all convexity defects of the input contour and returns a sequence of the CvConvexityDefect structures, where CvConvexityDetect is defined as:

struct CvConvexityDefect
{
   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; // distance between the farthest point and the convex hull
};

The figure below displays convexity defects of a hand contour:

../../../_images/defects.png

'OpenCV' 카테고리의 다른 글

적당한 선으로 채우기 fitLine  (0) 2017.11.15
구멍 채우기 - fitEllipse  (0) 2017.11.15
형태 넓이 구하기 - contourArea  (0) 2017.11.15
윤곽선 그리기 - DrawContours  (0) 2017.11.15
윤곽선 정보 찾기 - findContours  (0) 2017.11.15