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

contourArea

Calculates a contour area.

C++: double contourArea(InputArray contour, bool oriented=false )
Python: cv2.contourArea(contour[, oriented]) → retval
C: double cvContourArea(const CvArr* contour, CvSlice slice=CV_WHOLE_SEQ, int oriented=0 )
Python: cv.ContourArea(contour, slice=CV_WHOLE_SEQ) → float
Parameters:
  • contour – Input vector of 2D points (contour vertices), stored in std::vector or Mat.
  • oriented – Oriented area flag. If it is true, the function returns a signed area value, depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can determine orientation of a contour by taking the sign of an area. By default, the parameter is false, which means that the absolute value is returned.

The function computes a contour area. Similarly to moments() , the area is computed using the Green formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using drawContours() or fillPoly() , can be different. Also, the function will most certainly give a wrong results for contours with self-intersections.

Example:

vector<Point> contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));

double area0 = contourArea(contour);
vector<Point> approx;
approxPolyDP(contour, approx, 5, true);
double area1 = contourArea(approx);

cout << "area0 =" << area0 << endl <<
        "area1 =" << area1 << endl <<
        "approx poly vertices" << approx.size() << endl;

convexHull

Finds the convex hull of a point set.

C++: void convexHull(InputArray points, OutputArray hull, bool clockwise=false, bool returnPoints=true )
Python: cv2.convexHull(points[, hull[, clockwise[, returnPoints]]]) → hull
C: CvSeq* cvConvexHull2(const CvArr* input, void* hull_storage=NULL, int orientation=CV_CLOCKWISE, int return_points=0 )
Python: cv.ConvexHull2(points, storage, orientation=CV_CLOCKWISE, return_points=0) → convexHull
Parameters:
  • points – Input 2D point set, stored in std::vector or Mat.
  • hull – Output convex hull. It is either an integer vector of indices or vector of points. In the first case, the hull elements are 0-based indices of the convex hull points in the original array (since the set of convex hull points is a subset of the original point set). In the second case, hull elements are the convex hull points themselves.
  • hull_storage – Output memory storage in the old API (cvConvexHull2 returns a sequence containing the convex hull points or their indices).
  • clockwise – Orientation flag. If it is true, the output convex hull is oriented clockwise. Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing to the right, and its Y axis pointing upwards.
  • orientation – Convex hull orientation parameter in the old API, CV_CLOCKWISE or CV_COUNTERCLOCKWISE.
  • returnPoints – Operation flag. In case of a matrix, when the flag is true, the function returns convex hull points. Otherwise, it returns indices of the convex hull points. When the output array is std::vector, the flag is ignored, and the output depends on the type of the vector: std::vector<int> implies returnPoints=truestd::vector<Point> implies returnPoints=false.

The functions find the convex hull of a 2D point set using the Sklansky’s algorithm [Sklansky82] that has O(N logN) complexity in the current implementation. See the OpenCV sample convexhull.cpp that demonstrates the usage of different function variants.

Note

  • An example using the convexHull functionality can be found at opencv_source_code/samples/cpp/convexhull.cpp


'OpenCV' 카테고리의 다른 글

구멍 채우기 - fitEllipse  (0) 2017.11.15
형태 볼록함 결점찾기, 구멍찾기 - convexityDefects  (0) 2017.11.15
윤곽선 그리기 - DrawContours  (0) 2017.11.15
윤곽선 정보 찾기 - findContours  (0) 2017.11.15
ROI설정  (0) 2017.11.11