简体   繁体   中英

image processing in python using open cv

import cv2 
fc=cv2.CascadeClassifier("haarcascade_fontalface_default.xml")

img=cv2.imread('dp.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

faces= fc.detectMultiScale(gray,1.1,4)

for (x,y,w,h) in faces:
    cv2.rectangle(img, (x,y), (x+w,y+h),(0,255,0),2)
    
cv2.imshow('img',img)
cv2.waitkey()
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-3-9ba3354eb85a> in <module>
      3 
      4 img=cv2.imread('dp.jpg')
----> 5 gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
      6 
      7 faces= fc.detectMultiScale(gray,1.1,4)

error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-rwld3ghi\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Below are the possible reasons for the error

  • Give full path for your haar cascade file

  • Give the full path for your image . Check whether cv2 as correctly read your image by using print(img) , if it returns None then the path specified by you is incorrect . Correct your path and try printing the image, if an array shows up then you are well to go as your image is now read successfully

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM