简体   繁体   中英

Solve error: Expected Ptr<cv::UMat> for argument '%s'

FcascPath='/content/drive/MyDrive/COTM july/Copy of haarcascade_frontalface_default.xml'

#Create the haar cascade
faceCascade = cv2.CascadeClassifier(FcascPath)

def imgdetect(gray,image):
  faces=faceCascade.detectMultiScale(gray,1.3,5)
  for (x,y,w,h) in faces:
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)
    roi_gray=gray[y:y+h,x:x+w]
  return image

i10="/content/drive/MyDrive/COTM july/Faces /10.jpg"
gr = cv2.cvtColor(i10, cv2.COLOR_BGR2GRAY)

canvas=imgdetect(gr,i10)
cv2.imshow("resultvideo", canavs)

And it is showing this:

TypeError Traceback (most recent call last) in () 13 14 i10="/content/drive/MyDrive/COTM july/Faces /10.jpg" ---> 15 gr = cv2.cvtColor(i10, cv2.COLOR_BGR2GRAY) 16 17 canvas=imgdetect(gr,i10)

TypeError: Expected Ptr<cv::UMat> for argument '%s

You have not read the image file before converting it to gray scale. Just do the following:-

FcascPath='/content/drive/MyDrive/COTM july/Copy of haarcascade_frontalface_default.xml'

#Create the haar cascade
faceCascade = cv2.CascadeClassifier(FcascPath)

def imgdetect(gray,image):
  faces=faceCascade.detectMultiScale(gray,1.3,5)
  for (x,y,w,h) in faces:
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)
    roi_gray=gray[y:y+h,x:x+w]
  return image

i10="/content/drive/MyDrive/COTM july/Faces /10.jpg"
image = cv2.imread(i10)
gr = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

canvas=imgdetect(gr,i10)
cv2.imshow("resultvideo", canavs)

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