コード例 #1
0
            # draw the text and timestamp on the frame
            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