Approximates Freeman chain(s) with polygonal curve
CvSeq* cvApproxChains( CvSeq* srcSeq, CvMemStorage* storage,
CvChainApproxMethod method=CV_CHAIN_APPROX_SIMPLE,
double parameter=0, int minimalPerimeter=0, int recursive=0 );
This is a stand-alone approximation routine. The function cvApproxChains works exactly in the same way as cvFindContours with the corresponding approximation flag. The function returns pointer to the first resultant contour. Other approximated contours, if any, can be accessed via v_next or h_next fields of the returned structure.
Initializes chain reader
void cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
The function cvStartReadChainPoints initializes a special reader (see Dynamic Data Structures for more information on sets and sequences).
Gets next chain point
CvPoint cvReadChainPoint( CvChainPtReader* reader );
The function cvReadChainPoint returns the current chain point and updates the reader position.
Approximates polygonal curve(s) with desired precision
CvSeq* cvApproxPoly( const void* srcSeq, int headerSize, CvMemStorage* storage,
int method, double parameter,
int parameter2=0 );
The function cvApproxPoly approximates one or more curves and returns the approximation result[s]. In case of multiple curves approximation the resultant tree will have the same structure as the input one (1:1 correspondence).
Calculates up-right bounding rectangle of point set
CvRect cvBoundingRect( CvArr* contour, int update );
The function cvBoundingRect returns the up-right bounding rectangle for 2d point set.
Calculates area of the whole contour or contour section
double cvContourArea( const CvArr* contour, CvSlice slice=CV_WHOLE_SEQ );
The function cvContourArea calculates area of the whole contour or contour section. In the latter case the total area bounded by the contour arc and the chord connecting the 2 selected points is calculated as shown on the picture below:
NOTE: Orientation of the contour affects the area sign, thus the function may return negative result. Use fabs() function from C runtime to get the absolute value of area.
Calculates contour perimeter or curve length
double cvArcLength( const void* curve, CvSlice slice=CV_WHOLE_SEQ, int isClosed=-1 );
The function cvArcLength calculates length or curve as sum of lengths of segments between subsequent points
Compares two shapes
double cvMatchShapes( const void* A, const void* B,
int method, double parameter=0 );
The function cvMatchShapes compares two shapes. The 3 implemented methods all use Hu moments (see cvGetHuMoments):
method=CV_CONTOUR_MATCH_I1: I1(A,B)=sumi=1..7abs(1/mAi - 1/mBi) method=CV_CONTOUR_MATCH_I2: I2(A,B)=sumi=1..7abs(mAi - mBi) method=CV_CONTOUR_MATCH_I3: I3(A,B)=sumi=1..7abs(mAi - mBi)/abs(mAi) where mAi=sign(hAi)•log(hAi), mBi=sign(hBi)•log(hBi), hAi, hBi - Hu moments of A and B, respectively.
Creates hierarchical representation of contour
CvContourTree* cvCreateContourTree( cont CvSeq* contour, CvMemStorage* storage, double threshold );
The function cvCreateContourTree creates binary tree representation for the input contour and returns the pointer to its root. If the parameter threshold is less than or equal to 0, the function creates full binary tree representation. If the threshold is greater than 0, the function creates representation with the precision threshold: if the vertices with the interceptive area of its base line are less than threshold, the tree should not be built any further. The function returns the created tree.
Restores contour from tree
CvSeq* cvContourFromContourTree( const CvContourTree* tree, CvMemStorage* storage,
CvTermCriteria criteria );
The function cvContourFromContourTree restores the contour from its binary tree representation. The parameter criteria determines the accuracy and/or the number of tree levels used for reconstruction, so it is possible to build approximated contour. The function returns reconstructed contour.
Compares two contours using their tree representations
double cvMatchContourTrees( const CvContourTree* tree1, const CvContourTree* tree2,
CvTreeMatchMethod method, double threshold );
The function cvMatchContourTrees calculates the value of the matching measure for two contour trees. The similarity measure is calculated level by level from the binary tree roots. If at the certain level difference between contours becomes less than threshold, the reconstruction process is interrupted and the current difference is returned.
Finds bounding rectangle for two given rectangles
CvRect cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
The function cvMaxRect finds minimum area rectangle that contains both input rectangles inside:
Rotated 2D box
typedef struct CvBox2D
{
CvPoint2D32f center; /* center of the box */
CvSize2D32f size; /* box width and length */
float angle; /* angle between the horizontal axis
and the first side (i.e. length) in radians */
}
CvBox2D;
Finds box vertices
void cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
The function cvBoxPoints calculates vertices of the input 2d box. Here is the function code:
void cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] )
{
float a = (float)cos(box.angle)*0.5f;
float b = (float)sin(box.angle)*0.5f;
pt[0].x = box.center.x - a*box.size.height - b*box.size.width;
pt[0].y = box.center.y + b*box.size.height - a*box.size.width;
pt[1].x = box.center.x + a*box.size.height - b*box.size.width;
pt[1].y = box.center.y - b*box.size.height - a*box.size.width;
pt[2].x = 2*box.center.x - pt[0].x;
pt[2].y = 2*box.center.y - pt[0].y;
pt[3].x = 2*box.center.x - pt[1].x;
pt[3].y = 2*box.center.y - pt[1].y;
}
Fits ellipse to set of 2D points
CvBox2D cvFitEllipse2( const CvArr* points );
The function cvFitEllipse calculates ellipse that fits best (in least-squares sense) to a set of 2D points. The meaning of the returned structure fields is similar to those in cvEllipse except that size stores the full lengths of the ellipse axises, not half-lengths
Fits line to 2D or 3D point set
void cvFitLine( const CvArr* points, CvDisType disType, double C,
double reps, double aeps, float* line );
The function cvFitLine fits line to 2D or 3D point set by minimizing sumiρ(ri), where ri is distance between i-th point and the line and ρ(r) is a distance function, one of:
disType=CV_DIST_L2 (L2):
ρ(r)=r2/2 (the simplest and the fastest least-squares method)
disType=CV_DIST_L1 (L1):
ρ(r)=r
disType=CV_DIST_L12 (L1-L2):
ρ(r)=2•[sqrt(1+r2/2) - 1]
disType=CV_DIST_FAIR (Fair):
ρ(r)=C2•[r/C - log(1 + r/C)], C=1.3998
disType=CV_DIST_WELSCH (Welsch):
ρ(r)=C2/2•[1 - exp(-(r/C)2)], C=2.9846
disType=CV_DIST_HUBER (Huber):
ρ(r)= r2/2, if r < C
C•(r-C/2), otherwise; C=1.345
Finds convex hull of points set
CvSeq* cvConvexHull2( const void* points, void* hullStorage=0,
int orientation=CV_CLOCKWISE, int returnPoints=0 );
The function cvConvexHull2 finds convex hull of 2D point set using Sklansky's algorithm. If hullStorage is memory storage, the function creates a sequence containing the hull points or pointers