【发布时间】:2020-08-03 14:28:41
【问题描述】:
所以我试图获取图像的轮廓,但它似乎是错误的数据类型,我收到了这个错误:
cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/contours.cpp:197: 错误:(-210:不支持的格式或格式组合) [开始]FindContours 在 mode != 时仅支持 CV_8UC1 图像 CV_RETR_FLOODFILL 否则仅在函数中支持 CV_32SC1 图像 'cvStartFindContours_Impl'
我读到这可能是图像不是二进制的问题,但是在我的情况下,我已经通过阈值转换了图像:
im = cv2.imread("picture.jpg")
cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
(thresh, im_t) = cv2.threshold(im, 160, 255, cv2.THRESH_BINARY)
im_tb = cv2.convertScaleAbs(im_t) #this does not seem to help either
(contours, hierarchy) = cv2.findContours(im_tb,cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
感谢您的帮助
【问题讨论】:
-
“我的目录”中有什么?那是图像还是目录。 cv2.imread() 只读取一个图像,而不是一个目录。
-
你为什么使用
convertScaleAbs? -
你可以试试:
im_tb.shape和im_tb.dtype在cv2.findContours之前 -
@fmw42 我试图用通用的东西替换目录,因为postist正在使用.jpg。