5

我正在尝试在二进制图像中找到轮廓,这是一个 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
4

1 回答 1

3

正如错误消息所述 - 唯一支持的格式,当模式不是时CV_RETR_FLOODFILL,是CV_8UC1=> 单通道 8 位无符号整数矩阵。当模式为CV_RETR_FLOODFILL时,唯一支持的格式是CV_32SC1- 32 位有符号...

由于您传递的是 float32 数组,因此它是CV_32FC1- 32 位浮动,不支持。您必须使用整数数组。

于 2016-04-19T15:27:27.637 回答