我找不到一个可用的例子来使用OpenCV计算凸包的面积。我看到了一个使用cvApproxPoly和cvContourArea的例子,但是我无法让它工作。以下是我的代码。
IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
int i, count = rand()%100 + 1;
CvPoint pt0;
CvPoint* points = (CvPoint*)malloc( count * sizeof(points[0]));
int* hull = (int*)malloc( count * sizeof(hull[0]));
CvMat point_mat = cvMat( 1, count, CV_32SC2, points );
CvMat hull_mat = cvMat( 1, count, CV_32SC1, hull );
for( i = 0; i < count; i++ )
{
pt0.x = rand() % (img->width/2) + img->width/4;
pt0.y = rand() % (img->height/2) + img->height/4;
points[i] = pt0;
}
CvSeq* convex_hull=cvConvexHull2( &point_mat, &hull_mat, CV_CLOCKWISE, 0 );