def start(): while True: start_app = input(""" 1 Start 2 Registration in Credo 3 Send old detection files -- Press h to get help -- -- Press e to exit --""" + '\n') if start_app == "1": break elif start_app == "h": os.system("reset") help_file = open(local_path + "/help.text", 'r') context = help_file.read() print(context) continue elif start_app == "2": os.system("reset") registration() elif start_app == "3": os.system("reset") old_detection_file() print("Done") continue elif start_app == "e": exit() else: continue
def start_detection(): global last_ping global last_detection_time last_ping = linux_time() last_detection_time = 0 cam_read = cv2.VideoCapture(int(cam_number)) sample_number = sample_save = 0 print("Start sampling...") time.sleep(2) os.system("reset") while True: try: time_dat = datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f")[:-3] detection_time = linux_time() sample_number += 1 ret, frame = cam_read.read() data = np.array(frame) print('\r', "Sample:", sample_number, "|", "Saved", sample_save, "|", "Press Ctrl + c to exit", end='') time.sleep(0.000001) counter = 0 xy_coordinates = [] if np.max(data) >= int(threshold): all_coordinate_x = list(np.where(data >= int(threshold))[1]) all_coordinate_y = list(np.where(data >= int(threshold))[0]) all_ziped = list(zip(all_coordinate_x, all_coordinate_y)) all_ziped.sort() while counter < len(all_ziped): if len(all_ziped) == 1: xy_coordinates.append(all_ziped[0]) break elif counter == 0: xy_coordinates.append(all_ziped[counter]) counter += 1 elif all_ziped[counter][0] - 10 < all_ziped[counter - 1][0]: counter += 1 else: xy_coordinates.append(all_ziped[counter]) counter += 1 multi_detection = 0 for x, y in xy_coordinates: if x >= 11 and y >= 11: img_crop = data[y - 10:y + 10, x - 10:x + 10] r = 50.0 / img_crop.shape[1] dim = (50, int(img_crop.shape[0] * r)) sample_save = sample_save + 1 if img_crop is None: pass else: print(time_dat, sample_number, x, y, round(np.average(data), 4), np.max(data), sep=',', file=open(str(path) + "/Report.txt", "a")) img_zoom = cv2.resize(img_crop, dim, interpolation=cv2.INTER_AREA) gray_img_zoom = cv2.cvtColor( img_zoom, cv2.COLOR_BGR2GRAY) cv2.imwrite( str(path) + "/" + str(time_dat) + " Sample no. %i:%i.png" % (sample_number, multi_detection), gray_img_zoom) picture = open( str(path) + "/" + str(time_dat) + " Sample no. %i:%i.png" % (sample_number, multi_detection), 'rb') picture_read = picture.read() base64_picture = str( base64.b64encode(picture_read))[2:] credo_detection(base64_picture, int(x), int(y), detection_time) last_detection_time = linux_time() old_detection_file() multi_detection += 1 else: pass if linux_time() - last_ping >= 600000: credo_ping(last_ping, last_detection_time) last_ping = linux_time() except KeyboardInterrupt: cam_read.release() exit()
def start_detection(): global last_ping global last_detection_time last_ping = linux_time() last_detection_time = 0 cam_read = cv2.VideoCapture(int(cam_number)) sample_number = sample_save = 0 print("Start sampling...") time.sleep(2) os.system("reset") while True: try: time_dat = datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f")[:-3] sample_number += 1 ret, frame = cam_read.read() data = np.array(frame) print('\r', "Sample:", sample_number, "|", "Saved", sample_save, "|", "Press Ctrl + c to exit", end='') time.sleep(0.000001) if np.max(data) >= int(threshold): all_coordinate_x = (np.where(data == np.max(data))[1]) all_coordinate_y = (np.where(data == np.max(data))[0]) chosen_coordinate_x = all_coordinate_x[0] - 10 chosen_coordinate_y = all_coordinate_y[0] - 10 if chosen_coordinate_x >= 11 and chosen_coordinate_y >= 11: img_crop = data[chosen_coordinate_y:chosen_coordinate_y + 20, chosen_coordinate_x:chosen_coordinate_x + 20] r = 50.0 / img_crop.shape[1] dim = (50, int(img_crop.shape[0] * r)) sample_save = sample_save + 1 if img_crop is None: pass else: print(time_dat, sample_number, chosen_coordinate_x, chosen_coordinate_y, round(np.average(data), 4), np.max(data), sep=',', file=open(str(path) + "/Report.txt", "a")) img_zoom = cv2.resize(img_crop, dim, interpolation=cv2.INTER_AREA) gray_img_zoom = cv2.cvtColor(img_zoom, cv2.COLOR_BGR2GRAY) cv2.imwrite( str(path) + "/" + str(time_dat) + " Sample no. %i.png" % sample_number, gray_img_zoom) picture = open( str(path) + "/" + str(time_dat) + " Sample no. %i.png" % sample_number, 'rb') picture_read = picture.read() base64_picture = str( base64.b64encode(picture_read))[2:] credo_detection(base64_picture, int(chosen_coordinate_x), int(chosen_coordinate_y)) last_detection_time = linux_time() old_detection_file() else: pass if linux_time() - last_ping >= 600000: credo_ping(last_ping, last_detection_time) last_ping = linux_time() except KeyboardInterrupt: cam_read.release() exit()