OpenCV:在numpy数组上查找轮廓

10

我正在尝试在一个numpy数组的二进制图像中查找轮廓。

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)

当我尝试运行那段代码时,我会得到这个错误

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
1个回答

4
正如错误消息所述 - 当模式不为CV_RETR_FLOODFILL时,唯一支持的格式是CV_8UC1 => 单通道8位无符号整数矩阵。当模式为CV_RETR_FLOODFILL时,唯一支持的格式是CV_32SC1 - 32位有符号整数...。
由于您传递的是float32数组,它是CV_32FC1 - 32位浮点数,这是不被支持的。您需要使用整数数组。

1
谢谢j-kaspar,问题已经解决了。 - Ehab AlBadawy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接