[英]Is there a way to determine which camera has recognized a person in live stream when using multiple cameras for facial recognition in python
This is a facial recognition program and is programmed with python and opencv with database insertion model through MySQL.这是一个面部识别程序,用 python 和 opencv 编程,数据库插入 model 到 MySQL。
I have one query in the program.我在程序中有一个查询。 In the first part, there is real-time data insertion in a table when the camera recognizes a person through the pictures given in which a date, time, name and ID stamp is inserted in the database.第一部分,当相机通过给定的图片识别人时,在表格中实时插入数据,在数据库中插入日期、时间、姓名和 ID 戳。 I also want to insert the camera name which has recognized the person to know the particular location also.我还想插入已识别人的相机名称,以了解特定位置。
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')
I figured out a way to solve the problem.我想出了解决问题的方法。 I made the frame reading from my webcam a function with a variable named cam1, then I made another python file copied the whole program and named that variable to cam2.我用一个名为 cam1 的变量从我的网络摄像头读取帧 function,然后我制作了另一个 python 文件,复制了整个程序并将该变量命名为 cam2。 I made another file calling those functions on the main file and by the multi threading function I called them simultaneously.我制作了另一个文件,在主文件上调用这些函数,并通过多线程 function 我同时调用了它们。 It turned out to be successful结果成功了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.