Face Recognition Data science

I am facing an error in face recognition project there is my code and error
import cv2
import numpy as np

#Init Camera
cap = cv2.VideoCapture(0)

Face Detection

face_cascade = cv2.CascadeClassifier(“haarcascade_frontalface_alt.xml”)

skip = 0
face_data = []
dataset_path = ‘/data/’

while True:
ret,frame = cap.read()

if ret==False:
	continue

gray_frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)


faces = face_cascade.detectMultiScale(frame,1.3,5)

	
faces = sorted(faces,key=lambda f:f[2]*f[3])

face_section =[]
# Pick the last face (because it is the largest face acc to area(f[2]*f[3]))
for face in faces[-1:]:
	x,y,w,h = face
	cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,255),2)

	#Extract (Crop out the required face) : Region of Interest
	offset = 10
	face_section = frame[y-offset:y+h+offset,x-offset:x+w+offset]
	face_section = cv2.resize(face_section,(100,100))

	skip += 1
	if skip%10==0:
		face_data.append(face_section)
		print(len(face_data))


cv2.imshow("Frame",frame)
cv2.imshow("Face Section",face_section)

key_pressed = cv2.waitKey(1) & 0xFF
if key_pressed == ord('q'):
	break

cap.release()
cv2.destroyAllWindows()

Error -raceback (most recent call last):
File “C:\Users\nsnik\Desktop\data science\data science projects\facer.py”, line 59, in
cv2.imshow(“Face Section”,face_section)
TypeError: Expected Ptrcv::UMat for argument ‘mat’

please resolved it

Hey @Nikhil799

Request you to share the code through the Coding Blocks IDE. It would a lot easier for me to debug it then. The indentation is all messed when pasting code here directly.


here is my code it showing me the error that face section not defined and when i defined it it showing me this error
Error -raceback (most recent call last):
File “C:\Users\nsnik\Desktop\data science\data science projects\facer.py”, line 59, in
cv2.imshow(“Face Section”,face_section)
TypeError: Expected Ptrcv::UMat for argument ‘mat’

Hey @Nikhil799

Try to run this code for me once: https://ide.codingblocks.com/s/293396

I’ve made some changes to your code (indentation related mostly).

Let me know the results.

my webacam is responding very slow and its stop working sometimes and its open very late is there any problem or it is something else??

This could be a hardware issue. There is also the possibility that some other app is trying to access the webcam at the same time. The speed aside, is it able to mark the face section or not?

hey,how to stop cmd from capturing images