rsinha
rsinha

Reputation: 2227

openCV usage cvFindDominantPoints

Does anyone know how to use the cvFindDominantPoints API of openCV? I basically have a 1 channel, binary image from which I get a set of contours. Judging from the image, I seem to be getting the correct contours. Now, I am selecting one of these contours to get dominant points of. This contour has about 60 vertices. However, the API call to cvFindDominantPoints is giving me a sequence of points (about 15) that does not even lie on the contour. It is quite far from it. Any insight?

my usage: CvSeq *dominantpoints = cvFindDominantPoints(targetSeq, tristorage, CV_DOMINANT_IPAN, 7, 9, 9, 150);

Upvotes: 1

Views: 3304

Answers (1)

yadda
yadda

Reputation: 31

#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;
}

Upvotes: 3

Related Questions