我正在尝试估计基于简单numpy数组的图像的边界框
ret,thresh = cv.threshold(img1[:,:,244],10,255,0)
输出如下:
接下来我做这个
im2,contours,hierarchy = cv.findContours(thresh, 1, 2)
我得到一个错误
FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function cvStartFindContours_Impl
所以我转换为
im2,contours,hierarchy = cv.findContours(thresh.astype(np.int8), 1, 2)
现在我得到了错误
error: (-210) in function threshold
我该如何解决错误?他们的替代品是我该如何获得示例的倾斜边界框?
转换为np.uint8之前的数组:
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]])
转换后的数组:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=int8)
最佳答案
转换:
thresh = np.array([255, 0])
thresh.astype(np.int8) #array([-1, 0], dtype=int8)
由于溢出而给您一个错误的答案。
您应该改用:
thresh.astype(np.uint8) #array([255, 0], dtype=uint8)
这样结果才是正确的。
关于python - Opencv:错误:(-210)在函数阈值中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54651859/