Пример #1
0
def person_recognition_example(db, proportion, feature_extraction_methods,
                               args, images_path):
    X_train, y_train, X_test, y_test = train_and_test_split(db, proportion)
    [img_width, img_height] = X_test[0].shape
    new_width, new_height = img_width * 3, img_height * 3
    resized_img = cv2.resize(X_test[0], (new_width, new_height))
    show_image(resized_img, "Original image")
    cv2.imwrite(os.path.join(images_path, "Original image.png"), X_test[0])

    for feat_extr_meth, par in zip(feature_extraction_methods, args):
        recognizer = FaceRecognizer(feat_extr_meth, par)
        recognizer.fit(X_train, y_train)
        prediction, pred_number = recognizer.predict(X_test[0])
        method_name = feat_extr_meth.__name__
        resized_img = cv2.resize(X_train[pred_number], (new_width, new_height))
        show_image(resized_img, method_name)
        cv2.imwrite(os.path.join(images_path, f"{method_name}.png"),
                    X_train[pred_number])
Пример #2
0
            ts = timestamp.strftime("%A %d %B %Y %I:%M:%S%p")
            cv2.putText(image, "Room Status : {}".format(text), (10, 35), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
            cv2.putText(image, ts, (10, image.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
           
            # Uncomment this line if the live feed is to be seen
            #cv2.imshow("Security Camera", image)

            if text == "Occupied":
                if (timestamp - lastUploaded).seconds >= conf["min_upload_seconds"]:
                    motionCounter += 1
                    if motionCounter >= conf["min_motion_frames"]:
                        if len(faces): # checking if number of faces found is > 0 
                            cv2.imwrite("Captured_Img.jpg", image)
                            image_path = "Captured_Img.jpg"
                            FaceRecognizer.train_data()
                            prediction, confidence = FaceRecognizer.predict(image_path)
                            print prediction, confidence
                            # now check if person belongs to known set of people or not by thresholding confidence level
                            if confidence < 50:
                                print " WELCOME :", known_people[prediction]
                                cv2.putText(image, "Verified User : {}".format(known_people[prediction]), (10, image.shape[0] - 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
                                cv2.imwrite("Captured_Img.jpg", image)
                            else:
                                print "ALERT! NOT VERIFIED! CALL THE POLICE!"
                                cv2.putText(image, "ALERT! NOT VERIFIED! CALL THE POLICE!", (10, image.shape[0] -30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
                                cv2.imwrite("Captured_Img.jpg", image)

                        if conf["use_dropbox"]:
                            # check if image file was already created due to presence of faces
                            # else create image file due to motion detection only
                            if not(os.path.isfile("Captured_Img.jpg")):