0
votes
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

1

1 Answers

0
votes

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)