Is it a reasonably correct function?

10 views
Skip to first unread message

Massimo Vecchio

unread,
Oct 10, 2013, 7:08:40 AM10/10/13
to cvb...@googlegroups.com
Hi all,

I would like to ask if this function (written by myself, after collecting some info by googling around, consider that I am not a good developer at all!) is correct:



int BlobifyForeground(const Mat &in, Mat &out, int minArea){

    CvTracks tracks;

    IplImage img = in;

    IplImage *labelImg = cvCreateImage( cvGetSize(&img), IPL_DEPTH_LABEL, 1 );

    CvBlobs blobs;
    unsigned int result = cvLabel( &img, labelImg, blobs );

    IplImage *imgOut = cvCreateImage(cvGetSize(&img), IPL_DEPTH_8U, 3);

    if (minArea>0){
        cvFilterByArea(blobs,minArea,100000000);
    }

    int label=0;
    for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it){
            label=it->second->label;

    }

    cvRenderBlobs( labelImg, blobs, &img, imgOut );
    cvUpdateTracks(blobs, tracks, 200., 5);
    cvRenderTracks(tracks, imgOut, imgOut);


    out=Mat(imgOut,true); //true makes a deep copy


    cvReleaseImage( &labelImg );
    cvReleaseImage( &imgOut );

    cvReleaseBlobs(blobs);

    return label;
}


I'm indeed not very convinced...could anyone confirm/correct it?

Tnx and best.

Massimo
Reply all
Reply to author
Forward
0 new messages