2016-04-19 13 views
1

Ich versuche Konturen in ein binäres Bild zu finden, das eine numpy Array istopencv: Suche nach Konturen auf numpy Array

a = np.array(np.random.rand(1024,768),dtype='float32')  
_, t2 = cv2.threshold(a,127,255,0) 
im2, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 

Wenn ich versuche, diesen Code ich diesen Fehler zu laufen

OpenCV Error: Unsupported format or combination of formats 
([Start]FindContours supports only CV_8UC1 images when 
mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only) 
in cvStartFindContours 

Antwort

0

Wie die Fehlermeldung besagt - das einzige unterstützte Format, wenn der Modus nicht CV_RETR_FLOODFILL ist, ist CV_8UC1 => Einzelkanal 8 Bit, vorzeichenlose Integer-Matrix. Wenn der Modus CV_RETR_FLOODFILL ist, das einzige unterstützte Format ist CV_32SC1-32 Bit unterzeichnet ...

Da Sie Array von float32 sind vorbei, ist es CV_32FC1 - 32 Bit, schwebend, die nicht unterstützt wird. Sie müssen das Array von Integer verwenden.

+0

Dank j-Kaspar, das das Problem behebt. –