def save_ir_image(intrinsic_config_json, image_path, dev_handle): logger.info("Saving IR Image") intrinsic_config_dict = {} if (intrinsic_config_dict is not None): with open(intrinsic_config_json) as f: intrinsic_config_dict = json.load(f) firmware_path = intrinsic_config_dict['firmware_path'] print(firmware_path) print(intrinsic_config_json) device.program_firmware(dev_handle, firmware_path) os.makedirs(image_path, exist_ok=True) focus = True dummy_count = 5 while focus: for count in np.arange(dummy_count): dev_handle.getImage() ir_image = frame.get_ir_image(dev_handle) plt.figure('ir_image') plt.clf() plt.imshow(ir_image, cmap='gray') plt.draw() plt.pause(0.1) plt.savefig(os.path.join(image_path, 'ir_image.png')) publish.push_to_host(image_path) print("Press Enter to send new image \n") print("Enter -- done -- if focusing complete \n") choice = input() if choice == 'done': break
def warmup(sweep_config_dict, dev_handle, seconds): sweep_config_dict = {} if (sweep_config_json is not None): with open(sweep_config_json) as f: sweep_config_dict = json.load(f) firmware_path = sweep_config_dict['firmware_path'] device.program_firmware(dev_handle, firmware_path) logger.info("Starting Warmup") start = time.time() end = time.time() while (end - start < seconds): end = time.time() if int(end) % 10 == 0: logger.info("Time Left: %d seconds", seconds - (end - start)) time.sleep(1) logger.info("Warmup Ended")
def run_ld_test(ld_config_json, sweep_config_json, dev_handle): sweep_config_dict = {} if (sweep_config_json is not None): with open(sweep_config_json) as f: sweep_config_dict = json.load(f) logger.info("Running LD Test") firmware_path = sweep_config_dict['firmware_path'] device.program_firmware(dev_handle, firmware_path) ret = ld.test_all_ld(dev_handle, ld_config_json) if ret[0] == 1: logger.info("LD TEST VALUES: %d, %d, %d, %d, %d - PASSED", ret[1], ret[2], ret[3], ret[4], ret[5]) else: logger.info("LD TEST VALUES: %d, %d, %d, %d, %d - FAILED", ret[1], ret[2], ret[3], ret[4], ret[5])
def verify_depth(dev_handle, cfg, cfg_prev, target_dist, firmware_path, num_frames): device.program_firmware(dev_handle, firmware_path) # Get Parameters window = {} window['X'] = cfg['window_x'] window['Y'] = cfg['window_y'] raw_frame_dict = {} raw_frame_dict['height'] = cfg['raw_frame_height'] raw_frame_dict['width'] = cfg['raw_frame_width'] frame_dict = {} frame_dict['height'] = cfg['frame_height'] frame_dict['width'] = cfg['frame_width'] gain = cfg_prev['sw_gain'] offset = cfg_prev['sw_offset'] # Empty ndarray depthCrop = np.empty([1, num_frames, window['X'], window['Y']]) frame.dummy_read(dev_handle) # Get image for i in range(num_frames): depthImage = frame.get_depth_image_df(dev_handle, raw_frame_dict['width'], raw_frame_dict['height']) depthCrop[0][i] = frame.crop_center(depthImage, frame_dict['width'], frame_dict['height'], window['X'], window['Y']) meas_depth = (np.median(depthCrop[0]) * gain) + offset logger.info( "Measured Depth for previous station calibrated firmware: %.2f" % meas_depth) #print(target_dist) depth_error = meas_depth - target_dist depth_error_perc = (depth_error / target_dist) * 100 logger.info("Depth error percent is:" + str(depth_error_perc)) if depth_error_perc >= cfg['depth_perc_err_threshold']: logger.error("Depth Error GREATER than threshold - FAILED") else: logger.info("Depth error LESS than threshold - PASSED")
def run_all_calibration(sweep_config_json, dev_handle, unique_id, **kwargs): sweep_config_dict = {} if (sweep_config_json is not None): with open(sweep_config_json) as f: sweep_config_dict = json.load(f) for key, value in kwargs.items(): if value is not None: sweep_config_dict[key] = kwargs[key] if key in sweep_config_dict: if sweep_config_dict[key] is None: print( 'Need to specify %s either as a command line option or in the sweep config json file' ) raise SystemExit sweep_config_dict['unique_id'] = unique_id sweep_config_dict['unique_id_list'] = split_unique_id( sweep_config_dict['unique_id'], 4) firmware_path = sweep_config_dict['firmware_path'] verify_firmware_path = os.path.join(sweep_config_dict['results_path'], sweep_config_dict['unique_id'], sweep_config_dict['verify_mode'], 'latest/lf_files') device.program_firmware(dev_handle, firmware_path) logger.info("Running Sweep Calibration") latest, archive = save.make_results_dir(sweep_config_dict['results_path'], sweep_config_dict['unique_id'], sweep_config_dict['mode']) if sweep_config_dict['calibrate']: linear_offset_df, depth_stats_df = calib.run_sweep_calibration( dev_handle=dev_handle, cfg=sweep_config_dict, firmware_path=firmware_path) save.save_lf_files(latest, archive, firmware_path) write_lf.write_linear_offset_to_lf2(firmware_path, os.path.join(latest, 'lf_files'), sweep_config_dict, linear_offset_df) depth_stats_calibrated_df = pd.DataFrame() #if sweep_config_dict['verify_sweep']: # logger.info("Verifying Sweep") # _, depth_stats_calibrated_df = calib.verify_sweep(dev_handle, sweep_config_dict, os.path.join(latest, 'lf_files')) #logger.info("Calculating Metrics") metrics_df = pd.DataFrame() #if sweep_config_dict['verify_sweep'] and sweep_config_dict['calculate_metrics']: # metrics_df = metcalc.calculate_metrics(depth_stats_df, depth_stats_calibrated_df) #test_depth_error(metrics_df, sweep_config_dict) logger.info("Verify depth error for previous station calibrated firmware") sweep_config_json_prev = glob.glob( os.path.join(verify_firmware_path, 'sweep*.json'))[0] sweep_config_dict_prev = {} if (sweep_config_json_prev is not None): with open(sweep_config_json_prev) as f: sweep_config_dict_prev = json.load(f) for key, value in kwargs.items(): if value is not None: sweep_config_dict_prev[key] = kwargs[key] if key in sweep_config_dict_prev: if sweep_config_dict_prev[key] is None: print( 'Need to specify %s either as a command line option or in the sweep config json file' ) raise SystemExit verify_depth(dev_handle, sweep_config_dict, sweep_config_dict_prev, sweep_config_dict['target_distance'], verify_firmware_path, 50) logger.info("writing to calibration json files") cal_json = os.path.join(firmware_path, 'linear_cal.json') output_cal_dict = write_to_cal_json(cal_json, sweep_config_dict) logger.info("All tests passed. Saving results...") save.save_results(latest, archive, depth_stats_df, depth_stats_calibrated_df, linear_offset_df, sweep_config_dict, firmware_path, metrics_df, output_cal_dict) return linear_offset_df, dev_handle, sweep_config_dict