def test_plot_random(): array_shape = (24, 32) min_value = 30 max_value = 40 plot = init_heatmap("Heatmap", array_shape, min_value, max_value) while True: frame = np.around(np.random.random(array_shape) * 10 + 30, decimals=2) update_heatmap(frame, plot)
def test_get_centroid_area_history(files): area_counter, area_movement_counter, centroid_area_numbers, annotated_images = get_centroid_area_history(files) assert len(centroid_area_numbers) == len(annotated_images) print(area_counter) print(area_movement_counter) contours_plot = init_heatmap("Detected Contours", (24,32), show=True) track_plot = init_heatmap("Tracked Centroid", (2, 4), min_value=0, max_value=1, show=True) area_number_frames = [] for i in range(len(centroid_area_numbers)): area_number = centroid_area_numbers[i] frame = np.zeros(8) frame[area_number] = 1 frame = frame.reshape((2,4)) update_heatmap(frame, track_plot) update_heatmap(annotated_images[i], contours_plot)
def test_plot(files): array_shape = (24, 32) min_value = 30 max_value = 40 plot = init_heatmap("Heatmap", array_shape, min_value, max_value, debug=True) for f in files: frame = get_frame(f) update_heatmap(frame, plot)
def test_plot_without_labels(files): array_shape = (24, 32) min_value = 25 max_value = 40 plot = init_heatmap("Heatmap", array_shape, min_value, max_value, debug=False) for i in range(len(files)): frame = get_frame(files[i]) update_heatmap(frame, plot) create_folder_if_absent("testpics") plt.savefig("testpics/{}.png".format(i))
def save_serial_output(forever, num_samples=3000, mode=DEBUG_MODE): """ Save I2C output """ counter = 0 to_read = forever or counter < num_samples plot = None if mode == DEBUG_MODE: min_temp = 28 max_temp = 40 plot = init_heatmap("MLX90640 Heatmap", ARRAY_SHAPE, min_temp, max_temp) elif mode == WRITE_MODE: create_folder_if_absent(DATA_PATH) while to_read: try: frame = np.zeros( (24 * 32)) # initialise array for storing temp values mlx.getFrame( frame ) # get the mlx values and put them into the array we just created array = np.array(frame) print(array) if array.shape[0] == ARRAY_SHAPE[0] * ARRAY_SHAPE[1]: df = np.reshape(array.astype(float), ARRAY_SHAPE) df = interpolate_values(df) max_temp = np.amax(df) min_temp = np.amin(df) if mode == DEBUG_MODE: print("Updating Heatmap...", "[{}]".format(counter)) update_heatmap(df, plot) elif mode == WRITE_MODE: print("Saving npy object...", "[{}]".format(counter)) save_npy(df, DATA_PATH, directory_sort=DATA_DIR_SORT) elif mode == PUBLISH_MODE: pass counter += 1 except KeyboardInterrupt: raise except Exception as e: print(e) break
def save_serial_output(forever, num_samples=3000, mode=DEBUG_MODE): """ Save serial output from arduino """ ser = serial.Serial(SERIAL_PORT, BAUD_RATE) ser.reset_output_buffer() counter = 0 to_read = forever or counter < num_samples plot = None if mode == DEBUG_MODE: min_temp = 28 max_temp = 40 plot = init_heatmap("MLX90640 Heatmap", ARRAY_SHAPE, min_temp, max_temp) elif mode == WRITE_MODE: create_folder_if_absent(DATA_PATH) while to_read: try: ser_bytes = ser.readline() decoded_string = ser_bytes.decode("utf-8", errors='ignore').strip("\r\n") values = decoded_string.split(",")[:-1] array = np.array(values) if array.shape[0] == ARRAY_SHAPE[0] * ARRAY_SHAPE[1]: df = np.reshape(array.astype(float), ARRAY_SHAPE) df = interpolate_values(df) max_temp = np.amax(df) min_temp = np.amin(df) if mode == DEBUG_MODE: print("Updating Heatmap...", "[{}]".format(counter)) update_heatmap(df, plot) elif mode == WRITE_MODE: print("Saving npy object...", "[{}]".format(counter)) save_npy(df, DATA_PATH, directory_sort=DATA_DIR_SORT) elif mode == PUBLISH_MODE: pass counter += 1 except KeyboardInterrupt: raise except Exception as e: print(e) break
def get_init_likelihood_plot(): array_shape = (2, 4) min_value = 0 max_value = 1 return init_heatmap("Likelihood Plot", array_shape, min_value, max_value)
def get_init_heatmap_plot(): array_shape = (24, 32) min_value = 25 max_value = 40 return init_heatmap("MLX90640 Heatmap", array_shape, min_value, max_value)