2012-11-02 2 views
16

Essayer de faire fonctionner findContours sur une image binaire »findContours 'de support seulement des images 8uC1' erreur

Mat conv(image.size(), CV_8U); 
image.convertTo(conv, CV_8U); 
vector<vector<cv::Point> > contours; 

findContours(conv, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); 

thorws erreur:

OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 images) in cvStartFindContours, 

Toutes les idées Merci

Répondre

19

De the documentation:

C++: void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Parameters:

rtype – desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.

Vous voyez que le nombre de canaux n'est pas changé par convertTo, cela signifie très probablement que vous obtenez 3 canaux (r, g et b). Cependant findContours nécessite une image monochrome.

Vous devez convertir l'image en noir et blanc:

cv::Mat bwImage; 
cv::cvtColor(image, bwImage, CV_RGB2GRAY); 
vector< vector<cv::Point> > contours; 
cv::findContours(bwImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); 
+1

Est-il possible que je peux réduire monochrome? J'ai déjà une image en noir et blanc qui a été filtrée avec canny d'un autre programme – 0xSina

+0

@ 0xSina: oui, juste ajouté :) – Vlad

+0

Cool, merci !!! – 0xSina

Questions connexes