for fxmin, fymin, fxmax, fymax in faces:
        cv2.rectangle(img, (fxmin, fymin), (fxmax, fymax), (255, 255, 0), 2)

        # Crop face area from frame
        fcrop = frame[fymin:fymax, fxmin:fxmax]

        # Search and draw facial landmarks
        dots = myCV.get_landmarks(LANDMARK_NET, fcrop, (fxmin, fymin))
        for x, y in dots:
            cv2.circle(img, (x, y), 3, (255, 0, 255), -1)

        # Transfrom the face to improve recognition
        fcrop = myCV.face_transform(fcrop)

        # Getting facial descriptor
        face_features = myCV.get_descriptor(FACE_REID_NET, fcrop)

        # Searching the face in face_database
        ID, distance = myCV.object_in_database(face_features, face_database,
                                               0.5)

        # If our database dont contain the face add it
        if not ID:
            ID = len(face_database) + 1
            face_database[ID] = face_features

        cv2.putText(img, f"[id{ID}][{(1 - distance):.2f}]",
                    (fxmin, fymin - 10), cv2.FONT_HERSHEY_SIMPLEX,
                    ((fxmax - fxmin) / 150), (255, 0, 255), 2)

    # Runtime and Afps specs
Esempio n. 2
0
    for fxmin, fymin, fxmax, fymax in face:
        fxmin += bxmin
        fymin += bymin
        fxmax += bxmin
        fymax += bymin

        cv2.rectangle(img, (fxmin, fymin), (fxmax, fymax), (0, 255, 0), 2)

        fchip = frame[fymin:fymax, fxmin:fxmax]

        cv2.imshow('Face{}'.format(n), fchip)
        cv2.waitKey(0)

        dots = myCV.get_landmarks(landmark_net, fchip, (fxmin, fymin))
        for x, y in dots:
            cv2.circle(img, (x, y), 4, (255, 0, 255), -1)

        face_info = myCV.get_descriptor(face_reid_net, fchip)

        ID = myCV.object_in_data(face_info, faces_data, 0.5)
        if not ID:
            ID = len(faces_data) + 1
        # Rewriting data!!!
        faces_data[ID] = face_info

        cv2.putText(img, 'id{}'.format(ID), (bxmin, bymin - 10),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 255), 2)

cv2.imshow('Output', img)
cv2.waitKey(0)
Esempio n. 3
0
        raise Exception('Frame not found')

    # Copy the input image for continuing processing
    img = frame.copy()

    # Detect bodies from the input image
    # 15 = person id in mobilessd list
    bodies = myCV.detect(BODY_NET, frame, 0.7, 15)
    for bxmin, bymin, bxmax, bymax in bodies:
        cv2.rectangle(img, (bxmin, bymin), (bxmax, bymax), (255, 255, 0), 2)

        # Crop body area from frame
        bcrop = frame[bymin:bymax, bxmin:bxmax]

        # Getting body descriptor
        body_features = myCV.get_descriptor(BODY_REID_NET, bcrop)

        # Searching the body in body_database
        ID, distance = myCV.object_in_database(body_features, bodies_database,
                                               0.5)

        # If our database dont contain the body add it
        if not ID:
            ID = len(bodies_database) + 1
            bodies_database[ID] = body_features

        # Display ID confidence of person
        cv2.putText(img, f"[id{ID}][{(1 - distance):.2f}]",
                    (bxmin, bymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 1,
                    (255, 0, 255), 2)