1

i writed real time face recognition fro webcam and i want to pull it to raspberry pi3 version,but when i do it then speed is very low. i want to use parallel programming for speed up for it but i haven't experience to parallel processing and stuff like that..i used face_recognition module and dlib and when i open videostream from webcam then its very slow to captures frames and face recognize this is my code :

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()

please help me,thank you in advance

rkoofoo
  • 25
  • 4

0 Answers0