opencv:在numpy数组中查找轮廓
opencv: finding contoures on numpy array
我试图在二进制图像中找到轮廓,它是一个 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
如错误消息所述 - 唯一受支持的格式,当模式不是 CV_RETR_FLOODFILL
时,是 CV_8UC1
=> 单通道 8 位无符号整数矩阵。当模式为 CV_RETR_FLOODFILL
时,唯一支持的格式是 CV_32SC1
- 32 位有符号...
由于您传递的是 float32 数组,它是 CV_32FC1
- 32 位,浮动,不受支持。你必须使用整数数组。
我试图在二进制图像中找到轮廓,它是一个 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
如错误消息所述 - 唯一受支持的格式,当模式不是 CV_RETR_FLOODFILL
时,是 CV_8UC1
=> 单通道 8 位无符号整数矩阵。当模式为 CV_RETR_FLOODFILL
时,唯一支持的格式是 CV_32SC1
- 32 位有符号...
由于您传递的是 float32 数组,它是 CV_32FC1
- 32 位,浮动,不受支持。你必须使用整数数组。