程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

img_gray = cv2。cv2 cvtColor (img cv2.COLOR_BGR2GRAY)。錯誤:OpenCV (4.2.0) C: \ \ opencv-python項目

編輯:Python

@solve img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' error

Program error

Error Reason

It is not clear whether the input image is single-channel or multi-channel, and the grayscale of the image.

img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Workaround

One, know whether the input is a single-channel image or a multi-channel image

Second, if it is a single channel, directly cv2.imread(tmp_path, 0) read in single channel mode, do not read in multi channel mode such as 1, otherwise cv2.cvtColor it will report an error.

Third, choose a high-quality one. For face recognition, choose a photo with a fuller and clearer face.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved