sir i am trying to compile my code but i am getting following errors:-
FileNotFoundError Traceback (most recent call last)
in
13
14 names[class_id]=fx[:-4]
—> 15 data_item=np.load(path+fx)
16 face_data.append(data_item)
17
~\anaconda3\lib\site-packages\numpy\lib\npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
426 own_fid = False
427 else:
–> 428 fid = open(os_fspath(file), “rb”)
429 own_fid = True
430
FileNotFoundError: [Errno 2] No such file or directory: ‘C:/Users/YASH/Desktop/CV_FACE_RECOGNITIONCV_FACE_RECOGNITIONYASH_RASTOGI.npy’
CODE WHICH I AM USING ALONG WITH KNN ALGO(ITS WORKING)
import os
cap =cv2.VideoCapture(0)
face_recog=cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’)
path=‘C:/Users/YASH/Desktop/CV_FACE_RECOGNITION’
face_data=[]
labels=[]
names={}
class_id=0
data preparation
for fx in os.listdir(path):
if(fx.endswith(’.npy’)):
names[class_id]=fx[:-4]
data_item=np.load(path+fx)
face_data.append(data_item)
target=class_id*np.ones((data_item.shape[0],))
class_id+=1
labels.append(target)
print(face_data)
#print(face_data.shape)
face_data=np.concatenate(face_data ,axis=0)
face_labels = np.concatenate(labels,axis=0).reshape((-1,1))
trainset = np.concatenate((face_dataset,face_labels),axis=1)
while True:
ret,frame=cap.read()
if ret == False:
continue
faces=face_recog.detectMultiScale(frame,1.3,5)
if(len(faces) == 0):
continue
faces= sorted(faces,key = lambda f:f[2]*f[3])
for face in faces:
x,y,w,h=face
frame=cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)
offset =10
face_section=frame[y-offset:y+offset+h,x-offset:x+offset+w]
face_section=cv2.resize(face_section,(100,100))
out = knn(trainset,face_section.flatten())
pred_name=names[int(out)]
cv2.putText(frame,pred_name,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2,cv2.LINE_AA)
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,255,255),2)
cv2.imshow(name,frame)
key=cv2.waitKey(1) & 0xFF
if(key == ord('q')):
break;
cv2.destroyAllWindows()
cap.release()