首页 文章

opencv:在numpy数组上查找contoures

提问于
浏览
2

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

  • 1

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

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

相关问题