[英]Is there a way to determine which camera has recognized a person in live stream when using multiple cameras for facial recognition in python
這是一個面部識別程序,用 python 和 opencv 編程,數據庫插入 model 到 MySQL。
我在程序中有一個查詢。 第一部分,當相機通過給定的圖片識別人時,在表格中實時插入數據,在數據庫中插入日期、時間、姓名和 ID 戳。 我還想插入已識別人的相機名稱,以了解特定位置。
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("trainner.yml")
labels = {"person_name": 1}
with open("labels.pickle", 'rb') as f:
og_labels = pickle.load(f)
labels = {v: k for k, v in og_labels.items()}
cap = cv2.VideoCapture(0)
#cap1 = cv2.VideoCapture('rtsp://admin:umerkhan261@192.168.226.201')
while True:
ret, frame = cap.read()
# ret, frame1 = cap1.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
now = datetime.now()
print("Today's date: ", str(now))
for (x, y, w, h) in faces:
roi_gray = gray[y:y + h, x:x + w]
# roi_gray1 = gray1[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
# roi_color1 = frame1[y:y + h, x:x + w]
# deep Learned Model for recognizing the person in live stream
id_, conf = recognizer.predict(roi_gray)
# id_, conf = recognizer.predict(roi_gray1)
if 45 <= conf <= 85:
print(id_)
print(labels[id_])
font = cv2.FONT_HERSHEY_SIMPLEX
name = labels[id_]
new = datetime.now()
tString = new.strftime('%H:%M:%S')
dtString = new.strftime('%D:%m')
我想出了解決問題的方法。 我用一個名為 cam1 的變量從我的網絡攝像頭讀取幀 function,然后我制作了另一個 python 文件,復制了整個程序並將該變量命名為 cam2。 我制作了另一個文件,在主文件上調用這些函數,並通過多線程 function 我同時調用了它們。 結果成功了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.