我写了网络摄像头的实时面部识别,我想把它拉到覆盆子pi3版本,但是当我这样做时,速度非常低。 我想使用并行编程加速它,但我没有经验并行处理和类似的东西..我使用face_recognition模块和dlib,当我从网络摄像头打开videostream然后它很慢捕获帧和脸认识 这是我的代码:
while True:
# Grab a single frame of video
frame = video_capture.read()
frame = imutils.resize(frame,width=500)
# Resize frame of video to 1/4 size for faster face recognition processing
small_frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
# small_frame = cv2.resize(frame,(930,int(930*0.4234375)))
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1]
# Only process every other frame of video to save time
if process_this_frame%5==0:
# Find all the faces and face encodings in the current frame of video
# face_locations = face_recognition.face_locations(rgb_small_frame,number_of_times_to_upsample=2)
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
face_names = []
Length=len(known_face_encoding)
for face_encoding in face_encodings:
match = face_recognition.compare_faces(known_face_encoding, face_encoding,0.5)
Matches=np.where(match)[0] #Checking which image is matched
if len(Matches)>0:
name = str(known_person[Matches[0]])
face_names.append(name)
else:
face_names.append("Unknown")
# process_this_frame = not process_this_frame
process_this_frame = process_this_frame+1
# Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 2
right *= 2
bottom *= 2
left *= 2
# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 1)
# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), -1)
# draw.rectangle(((left, top), (right, bottom)), outline=(0, 0, 255))
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, .5, (255, 255, 255), 1)
cv2.imshow('Video', frame)
# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
请帮帮我,谢谢你