This is my code:
import cv2
cam=cv2.VideoCapture(0,cv2.CAP_DSHOW)
cam.set(3,640)
cam.set(4,480)
detector=cv2.CascadeClassifier('C:\\Users\\Hp\\Downloads\\8f51e58ac0813cb695f3733926c77f52-
07eed8d5486b1abff88d7e34891f1326a9b6a6f5\\8f51e58ac0813cb695f3733926c77f52-
07eed8d5486b1abff88d7e34891f1326a9b6a6f5\\haarcascade_frontalface_default.xml')
face_id=input("Enter a numeric face id: ")
print("taking sample, look at camera......")
count=0
while True:
ret, img=cam.read('C:\\Users\\Hp\\Desktop\\leo software
company\\gamedata\\.vscode\\Maya.Ai')
converted_image=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces=detector.detectMultiScale(converted_image, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y),(x+w,y+h),(255,0,0),2)
count += 1
cv2.imwrite("samples/face."+str(face_id)+'.'+str(count)+".jpg",
converted_image[y:y+h,x:x+w])
cv2.imshow('image',img)
k=cv2.waitKey(100) & 0xff
if k == 27:
break
elif count>=10:
break
print("id made succesfully")
cam.release()
cv2.destroyAllWindows
I am getting this error:
Traceback (most recent call last):
File "c:\Users\Hp\Desktop\leo software company\game data\.vscode\Maya.Ai\id.py", line 10, in <module>
ret, img=cam.read('C:\\Users\\Hp\\Desktop\\leo software company\\game data\\.vscode\\Maya.Ai')
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'read'
> Overload resolution failed:
> - image is not a numpy array, neither a scalar
> - Expected Ptr<cv::UMat> for argument 'image'