views:

86

answers:

2

Hi,

I am trying to use the findContours function in OpenCV, but VS 2008 gives an error saying:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupport ed array type) in unknown function, file ........\ocv\opencv\src\cxcore\cxarr ay.cpp, line 2476

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Press any key to continue . . .

Here's the code:

Mat_> originalimage;

Mat_> resultingimage;

vector> v;

originalimage = cv::imread("Original.ppm");

cv::findContours(originalimage,v,CV_RETR_LIST,CV_CHAIN_APPROX_NONE);

Thanks in advance

A: 

FindContours only accepts binary image. That is , any image which is output of cvThreshold cvAdapiveThreshold cvCanny

try adding this statement before cv::findContours

cvThreshold(originalImage,resultingImage,100,100,CV_THRESH_BINARY) 

then call findcontours with resultingImage.

if it works then you should input the correct parameters to cvThreshold ( 100 is just an example).Check the reference for that matter.

EDIT: resultingImage should be a single channel image!!

dnul
A: 

I have had the same problem (or at least a similar one) with that function. I was not able to fix it, so I used the old C style cvFindContours function instead. I have included an example function in wich I used the cvFindContours function to clean up a blob image. This might not be the fastest solution, but at leas it works.

void filtBproject(Mat& Bproject){

    Scalar          color       = CV_RGB(255,255,255); // text color
    IplImage*       BprojectIpl =  &IplImage(Bproject);
    CvMemStorage*   storage     = cvCreateMemStorage(0);
    CvSeq*          contours    = 0;
    int             numCont     = 0;
    int             contAthresh = 45;

    numCont= cvFindContours( BprojectIpl, storage, &contours, sizeof(CvContour),
                    CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );

    cvSet(BprojectIpl, cvScalar(0,0,0));
    for( ; contours != 0; contours = contours->h_next )
        {

            if ( (cvContourArea(contours, CV_WHOLE_SEQ) > contAthresh) ){
                cvDrawContours( BprojectIpl, contours, color, color, -1, CV_FILLED, 8 );
            }
        }
}
NotNamedDwayne