解决:cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\contours.cpp

  • Post author:
  • Post category:python

解决:cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\contours.cpp

报错如下

Traceback (most recent call last):
  File "C:\Users\Dihuge\Desktop\jier_qinxie\find_Contours_2.py", line 55, in <module>
    contours, hierarchy = cv2.findContours(p_gray,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\contours.cpp:197: error: (-210: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 function 'cvStartFindContours_Impl'

在这里插入图片描述

解决方法

p_gray = np.where(p_gray > 30, 255, 0) # (条件,成立返回值,不成立返回值)

改为

p_gray = np.where(p_gray > 30, p_gray*0+255, p_gray*0+0) # (条件,成立返回值,不成立返回值)

即可!


版权声明:本文为FriendshipTang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。