openCV用法cvFindDominantPoints

时间:2010-04-27 04:50:54

标签: opencv

有谁知道如何使用openCV的cvFindDominantPoints API?我基本上有一个1通道的二进制图像,我可以从中获得一组轮廓。从图像来看,我似乎得到了正确的轮廓。现在,我选择其中一个轮廓来获得主导点。该轮廓具有大约60个顶点。然而,对cvFindDominantPoints的API调用给了我一系列点(大约15个)甚至不在轮廓上。它离它很远。有什么见解吗?

我的用法: CvSeq * dominantpoints = cvFindDominantPoints(targetSeq,tristorage,CV_DOMINANT_IPAN,7,9,9,150);

1 个答案:

答案 0 :(得分:3)

#include "cv.h"
#include "highgui.h"

CvSeq* contours = 0;
CvSeq* dps = 0;

int main( int argc, char** argv )
{
    int i, idx;
    CvPoint p;
    CvMemStorage* storage_ct = cvCreateMemStorage(0);
    CvMemStorage* storage_dp = cvCreateMemStorage(0);
    IplImage* img = cvLoadImage("contour.bmp", CV_LOAD_IMAGE_GRAYSCALE);

    cvNamedWindow( "image" );
    cvShowImage( "image", img );

    cvFindContours( img, storage_ct, &contours, sizeof(CvContour),
        CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE );

    dps = cvFindDominantPoints( contours, storage_dp, CV_DOMINANT_IPAN, 7, 20, 9, 150 );

    contours = cvApproxPoly( contours, sizeof(CvContour), storage_ct, CV_POLY_APPROX_DP, 3, 1 );

    printf("found %d DPs and %d Contours \n", dps->total, contours->total );

    for ( i = 0; i < dps->total; i++)
    {
        idx = *(int *) cvGetSeqElem(dps, i);
        p = *(CvPoint *) cvGetSeqElem(contours, idx);
        cvDrawCircle( img, p , 1, cvScalarAll(255) );
        printf("%d %d %d\n", idx, p.x, p.y);
    }

    cvDrawContours(img, contours, cvScalarAll(100), cvScalarAll(200), 100 );


    cvNamedWindow( "contours" );
    cvShowImage( "contours", img );

    cvWaitKey(0);
    cvReleaseMemStorage( &storage_ct );
    cvReleaseMemStorage( &storage_dp );
    cvReleaseImage( &img );

    return 0;
}