Python 3.x 在两台摄像机上执行人脸识别
我有一个面部识别项目,使用相机没有任何问题 我现在想用两台摄像机同时拍摄 这是我一个摄像头的代码,我不知道如何使用两个摄像头Python 3.x 在两台摄像机上执行人脸识别,python-3.x,opencv,face-recognition,Python 3.x,Opencv,Face Recognition,我有一个面部识别项目,使用相机没有任何问题 我现在想用两台摄像机同时拍摄 这是我一个摄像头的代码,我不知道如何使用两个摄像头 import face_recognition import cv2 import numpy as np video_capture = cv2.VideoCapture('rtsp://admin:11111@192.168.1.13:554/mode=real&idc=1&ids=2') farid_image = face_recognitio
import face_recognition
import cv2
import numpy as np
video_capture = cv2.VideoCapture('rtsp://admin:11111@192.168.1.13:554/mode=real&idc=1&ids=2')
farid_image = face_recognition.load_image_file("farid.jpg")
farid_face_encoding = face_recognition.face_encodings(farid_image)[0]
# Load a second sample picture and learn how to recognize it.
roice_image = face_recognition.load_image_file("roice.jpg")
roice_face_encoding = face_recognition.face_encodings(roice_image)[0]
known_face_encodings = [
farid_face_encoding,
roice_face_encoding
]
known_face_names = [
"farid",
"roice"
]
while True:
ret, frame = video_capture.read()
rgb_frame = frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame)
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
# Loop through each face in this frame of video
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
# Calculate face distance
face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
# If a match was found in known_face_encodings, just use the first one.
if True in matches:
# first_match_index = matches.index(True)
# Sort nearest distance
name = known_face_names[np.argsort(face_distance)[0]]
# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
# Display the resulting image
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()
我可以使用
cv2.VideoCapture()
模块简单地添加更多摄像头,但是如何更改人脸识别
以使用两个摄像头?您可以尝试将此多线程化。每个摄像头都有一个线程,可以对看到的图像进行自己的面部识别
它们将独立地作用于各自的流,但是您可以从两个线程获得结果,以组合信息以改进检测和/或识别