问题描述
我指的是这段视频,以创建训练模型。
[使用OpenCV用脸解锁应用程序] :https://www.youtube.com/watch?v=pXYJUrpQgzg
[Github链接]
https://github.com/krishnaik06/Unlock-Application/blob/master/Face%20Recognition%20%E2%80%93%20Unlock%20Your%20Computer%20With%20Your%20Face!%20-%20Copy.ipynb
但执行时出现错误。请帮忙
以下是代码:
a_times_3 = a + (a << 1)
a_times_15 = a_times_3 + (a_times_3 << 2)
a_times_13 = a_times_15 - (a << 1)
预期产量->收集样品完成
我的输出->
import cv2
import numpy as np
#Load HAAR face classifier
face_classifier = cv2.CascadeClassifier('Haarcascades/haarcascade_frontalface_default.xml')
#Load functions
def face_extractor(img):
#Function detects faces and returns the cropped face
#If no face detected,it returns the input image
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray,1.3,5)
if faces is ():
return None
#Crop all faces found
for (x,y,w,h) in faces:
cropped_face = img[y:y+h,x:x+w]
return cropped_face
#Initialize Webcam
cap = cv2.VideoCapture(0)
count = 0
#Collect 100 samples of your face from webcam input
while True:
ret,frame = cap.read()
if face_extractor(frame) is not None:
count += 1
face = cv2.resize(face_extractor(frame),(200,200))
face = cv2.cvtColor(face,cv2.COLOR_BGR2GRAY)
#save file in specified directory with unique name
file_name_path = './faces/user/' + str(count) + '.jpg'
cv2.imwrite(file_name_path,face)
#Put count on images and display live count
cv2.putText(face,str(count),(50,50),cv2.FONT_HERShey_COMPLEX,1,(0,255,0),2)
cv2.imshow('Face Cropper',face)
else:
print("Face not found")
pass
if cv2.waitKey(1) == 13 or count == 100: #13 is the Enter Key
break
cap.release()
cv2.destroyAllWindows()
print("Collecting Samples Complete")
'''
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)