def CheckFace(valid_output, vid_image, graph, frame_name, match_count): # run a single inference on the image and overwrite the # boxes and labels test_output = run_inference(vid_image, graph) matched_face = face_match(valid_output, test_output) if (matched_face != False): print('PASS! File ' + matched_face + ' matches ') match_count += 1 if (match_count >= 5 and match_count <= 7): print('User Checked In!') found_match = 2 if (match_count == 7): match_count = 0 Requestor().start() excemptions = ['Michael', 'Chris L'] if matched_face not in excemptions: fileName = '/home/tme/Desktop/Log/' + matched_face + str( datetime.now()) + '.png' cv2.imwrite(fileName, vid_image) emailMessage = Emailer(fileName, matched_face) emailMessage.start() else: found_match = 1 else: found_match = 3 # print('FAIL! File ' + frame_name + ' does not match ') match_count = 0 # Uncomment next line to view the image sent to the graph # vid_image = preprocess_image(vid_image) overlay_on_image(vid_image, frame_name, found_match, matched_face) return match_count
def CreateSocket(q): # Read the IP address of the door with open(r'/home/tme/door.txt') as file: host = file.readline() port = 8686 q.put(False) doorOpenedTime = None sendEmail = True # Create a socket item mySocket = socket.socket() # Try to connect to the socket server running on the Pi try: mySocket.connect((host, port)) except socket.error as e: print(e) # Loop forever checking the socket for messages while True: if doorOpenedTime is not None: if (datetime.now() - doorOpenedTime).total_seconds() > 1800 and sendEmail: sendEmail = False emailMessage = Emailer() emailMessage.start() # Check the Queue to see if it has information, if it does check to see if it says exit. # If the Queue says exit then break the loop if not q.empty(): qData = q.get() if qData == "exit": break else: q.put(qData) # Set receive listen timeout to 1/10 of a second so it doesn't hang forever waiting for a message mySocket.settimeout(0.1) # Try to receive data from the socket, if it times out pass and run loop again try: data = mySocket.recv(1024).decode() # If data is None then the socket server isn't running and break the loop if not data: break print("from connected user: "******"opened": if q.empty(): q.put(True) else: qData = q.get() if qData == "exit": break q.put(True) doorOpenedTime = datetime.now() print("Door opened at " + str(doorOpenedTime)) elif data == "closed": if q.empty(): q.put(False) else: qData = q.get() if qData == "exit": print("quitting") break q.put(False) sendEmail = True doorOpenedTime = None print("Door closed") except KeyboardInterrupt: print("Keyboard interrupt detected. Closing Socket.") mySocket.close() except socket.timeout: pass mySocket.close() print("Socket Closed")
def run_camera(valid_output, graph): camera_device = cv2.VideoCapture(CAMERA_INDEX) camera_device.set(cv2.CAP_PROP_FRAME_WIDTH, REQUEST_CAMERA_WIDTH) camera_device.set(cv2.CAP_PROP_FRAME_HEIGHT, REQUEST_CAMERA_HEIGHT) camera_device.set(cv2.CAP_PROP_FPS, REQUEST_CAMERA_FPS) actual_camera_width = camera_device.get(cv2.CAP_PROP_FRAME_WIDTH) actual_camera_height = camera_device.get(cv2.CAP_PROP_FRAME_HEIGHT) print ('actual camera resolution: ' + str(actual_camera_width) + ' x ' + str(actual_camera_height)) if ((camera_device == None) or (not camera_device.isOpened())): print ('Could not open camera. Make sure it is plugged in.') print ('Also, if you installed python opencv via pip or pip3 you') print ('need to uninstall it and install from source with -D WITH_V4L=ON') print ('Use the provided script: install-opencv-from_source.sh') return frame_count = 0 match_count = 0 #entrant = 0 cv2.namedWindow(CV_WINDOW_NAME) found_match = 0 Faked = False while True : # Read image from camera, ret_val, vid_image = camera_device.read() if (not ret_val): print("No image from camera, exiting") break frame_count += 1 frame_name = 'camera frame ' + str(frame_count) if (not Faked): # run a single inference on the image and overwrite the # boxes and labels test_output = run_inference(vid_image, graph) matched_face = face_match(valid_output, test_output) if (matched_face != False): print('PASS! File ' + matched_face + ' matches ') match_count += 1 if (match_count >= 5 and match_count <= 7): print('User Checked In!') found_match = 2 if (match_count == 7): #return match_count = 0 Requestor().start() excemptions = ['Michael', 'Chris L'] if matched_face not in excemptions: fileName = '/home/tme/Desktop/Log/' + matched_face + str(datetime.datetime.now()) + '.png' cv2.imwrite(fileName, vid_image) emailMessage = Emailer(fileName, matched_face) emailMessage.start() else: found_match = 1 else: found_match = 3 print('FAIL! File ' + frame_name + ' does not match ') match_count = 0 #Uncomment next line to view the image sent to the graph #vid_image = preprocess_image(vid_image) overlay_on_image(vid_image, frame_name, found_match, matched_face) # check if the window is visible, this means the user hasn't closed # the window via the X button prop_val = cv2.getWindowProperty(CV_WINDOW_NAME, cv2.WND_PROP_ASPECT_RATIO) if (prop_val < 0.0): print('window closed') break # display the results and wait for user to hit a key cv2.imshow(CV_WINDOW_NAME, vid_image) raw_key = cv2.waitKey(1) if (raw_key != -1): if (handle_keys(raw_key) == False): print('user pressed Q') break if (handle_keys(raw_key) == 2): Faked = True print('PASS! File ' + frame_name + ' matches ') match_count += 1 if (match_count == 2): print('User Checked In!') found_match = 2 elif (match_count == 3): Faked = False match_count = 0 else: found_match = 1 if (found_match): cv2.imshow(CV_WINDOW_NAME, vid_image) cv2.waitKey(0)