Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Result issues with findContours

Hi all !

I'm kind of new to opencv, and on top of that, I'm french, so, sorry =) I'm using opencv 2.4.1 with visual studio 2008 and i'm having issues with my detection program. I've an image on which there are fishes that I want to detect. I do all the stuff to have an image on which I can work (threshold, dilate, erode...)and then I use Canny and findContours, this is when it gets weird : There are 5 fishes on the image, but the message tells me there are 12404 fishes oO 12404 corresponds to contours.size() Just before, I draw those "contours", and I can clearly see my 5 fishes with their contour drawn in red. So why do I have those 5 drawn contours, but 12404 fishes ?! I'v spent so many time searching and trying anything else but unsuccessfully. Here is the part of my code corresponding :

//**Edges detection
    Canny (imde,imcanny,75,150,3); 
    imshow("cont",imcanny);
    cvWaitKey();

//**Contours finding and drawing = way number 1
    static vector'<'vector'<'Point'>'> contours; //There ar no '' around < in my code, 
//it's just for you to see (html code hides what's in '<>')
    findContours(imcanny,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
    drawContours(immat,contours,-1,CV_RGB(255,0,0),2);

//**Récupération et affichage du nombre de poissons détectés
    char msg[20];
    sprintf(msg, "Found %d fishes",contours.size());
    printf(msg);
    //putText(imcanny,msg,cvPoint(2,12),FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,0,0));
    imshow("cont",immat);
    cvWaitKey();

I don't know what I'm doing wrong, I've used exactly what is used in the "coins counting" tutorial so... Thanks a lot for your help Tell me if you need to see another part of my code, or the images maybe, and I'll edit =) Thanks

Result issues with findContours

Hi all !

I'm kind of new to opencv, and on top of that, I'm french, so, sorry =) I'm using opencv 2.4.1 with visual studio 2008 and i'm having issues with my detection program. I've an image on which there are fishes that I want to detect. I do all the stuff to have an image on which I can work (threshold, dilate, erode...)and then I use Canny and findContours, this is when it gets weird : There are 5 fishes on the image, but the message tells me there are 12404 fishes oO 12404 corresponds to contours.size() Just before, I draw those "contours", and I can clearly see my 5 fishes with their contour drawn in red. So why do I have those 5 drawn contours, but 12404 fishes ?! I'v spent so many time searching and trying anything else but unsuccessfully. Here is the part of my code corresponding :

//**Edges detection
    Canny (imde,imcanny,75,150,3); 
    imshow("cont",imcanny);
    cvWaitKey();

//**Contours finding and drawing = way number 1
    static vector'<'vector'<'Point'>'> contours; //There ar no '' around < in my code, 
//it's just for you to see (html code hides what's in '<>')
    findContours(imcanny,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
    drawContours(immat,contours,-1,CV_RGB(255,0,0),2);

//**Récupération et affichage du nombre de poissons détectés
    char msg[20];
    sprintf(msg, "Found %d fishes",contours.size());
    printf(msg);
    //putText(imcanny,msg,cvPoint(2,12),FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,0,0));
    imshow("cont",immat);
    cvWaitKey();

I don't know what I'm doing wrong, I've used exactly what is used in the "coins counting" tutorial so... Thanks a lot for your help Tell me if you need to see another part of my code, or the images maybe, and I'll edit =) Thanks

EDIT1 :

Here is what I do to the image just before Canny :

//**Lissage de l'image
    medianBlur(immat,immat,5);
    imshow("binaire",immat);
    cvWaitKey();

//**Binarisation de l'image
    threshold(immat,imthresh,75,255,CV_THRESH_BINARY);
    imshow("binaire",imthresh);
    cvWaitKey();*

//**Dilatation de l'image
    int dilatation_size=1; //dilatation max=21
    Mat element=getStructuringElement(MORPH_RECT, Size(2*dilatation_size+1,2*dilatation_size+1), Point(dilatation_size,dilatation_size));
    dilate(imthresh,imde,element);
    imshow("dne",imde);
    cvWaitKey();

//**Erosion de l'image
    int erosion_size=1; //erosion max=21
    Mat elementt=getStructuringElement(MORPH_RECT, Size(2*erosion_size+1,2*erosion_size+1), Point(erosion_size,erosion_size));
    erode(imde,imde,elementt);
    imshow("dne",imde);
    cvWaitKey();

If I don't use Canny, but directly findcontours on the image imde (result of the erosion), i've got an error (that's why I use Canny, because I don't have any error with it xD)

//Exception non gérée ... Exception à l'emplacement mémoire ...

Opencv error: unsupported format or combination of formats '<'[Start]findcontours support only 8uc1 
and 32sC1 images'>' in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 196

I suppose it means that the image imde has the wrong format but it's the result of erosion so what can I do ?!

Thanks =)

Result issues with findContours

Hi all !

I'm kind of new to opencv, and on top of that, I'm french, so, sorry =) I'm using opencv 2.4.1 with visual studio 2008 and i'm having issues with my detection program. I've an image on which there are fishes that I want to detect. I do all the stuff to have an image on which I can work (threshold, dilate, erode...)and then I use Canny and findContours, this is when it gets weird : There are 5 fishes on the image, but the message tells me there are 12404 fishes oO 12404 corresponds to contours.size() Just before, I draw those "contours", and I can clearly see my 5 fishes with their contour drawn in red. So why do I have those 5 drawn contours, but 12404 fishes ?! I'v spent so many time searching and trying anything else but unsuccessfully. Here is the part of my code corresponding :

//**Edges detection
    Canny (imde,imcanny,75,150,3); 
    imshow("cont",imcanny);
    cvWaitKey();

//**Contours finding and drawing = way number 1
    static vector'<'vector'<'Point'>'> contours; //There ar no '' around < in my code, 
//it's just for you to see (html code hides what's in '<>')
    findContours(imcanny,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
    drawContours(immat,contours,-1,CV_RGB(255,0,0),2);

//**Récupération et affichage du nombre de poissons détectés
    char msg[20];
    sprintf(msg, "Found %d fishes",contours.size());
    printf(msg);
    //putText(imcanny,msg,cvPoint(2,12),FONT_HERSHEY_SIMPLEX, 0.4, CV_RGB(255,0,0));
    imshow("cont",immat);
    cvWaitKey();

I don't know what I'm doing wrong, I've used exactly what is used in the "coins counting" tutorial so... Thanks a lot for your help Tell me if you need to see another part of my code, or the images maybe, and I'll edit =) Thanks

EDIT1 EDIT 1 :

Here is what I do to the image just before Canny :

//**Lissage de l'image
    medianBlur(immat,immat,5);
    imshow("binaire",immat);
    cvWaitKey();

//**Binarisation de l'image
    threshold(immat,imthresh,75,255,CV_THRESH_BINARY);
    imshow("binaire",imthresh);
    cvWaitKey();*

//**Dilatation de l'image
    int dilatation_size=1; //dilatation max=21
    Mat element=getStructuringElement(MORPH_RECT, Size(2*dilatation_size+1,2*dilatation_size+1), Point(dilatation_size,dilatation_size));
    dilate(imthresh,imde,element);
    imshow("dne",imde);
    cvWaitKey();

//**Erosion de l'image
    int erosion_size=1; //erosion max=21
    Mat elementt=getStructuringElement(MORPH_RECT, Size(2*erosion_size+1,2*erosion_size+1), Point(erosion_size,erosion_size));
    erode(imde,imde,elementt);
    imshow("dne",imde);
    cvWaitKey();

If I don't EDIT 2

Here are some images :

The very first one, taken from a video :

image description

The one after "cvtcolor" & "medianblur" :

image description

The one after "threshold", "dilate" & "erode" :

image description

The one after "findcontours" and "drawcontours" (bold black) with CV_RETR_LIST :

image description

And the one after "findcontours" and "drawcontours" (bold black) if I use Canny, but directly findcontours on the image imde (result CV_RETR_EXTERNAL instead of the erosion), i've CV_RETR_LIST :

image description

In both case I've got an error (that's why I use Canny, because I don't have any error with it xD)

//Exception non gérée ... Exception à l'emplacement mémoire ...

Opencv error: unsupported format or combination of formats '<'[Start]findcontours support only 8uc1 
and 32sC1 images'>' in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 196

I suppose it means that the image imde has the wrong format but it's the result of erosion so what can I do ?!my lovely message "found 12404 fishes", this value doesn't change whatever I do...

Thanks for your help =)