简体   繁体   中英

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.

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. 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. I made another file calling those functions on the main file and by the multi threading function I called them simultaneously. It turned out to be successful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM