theta_min, theta_max, _ = radar.GetArenaTheta() logger.info(f'radar theta min: {theta_min}, theta max: {theta_max} (deg)') # Threshold radar.SetThreshold(RADAR_THRESHOLD) # radar filtering filter_type = radar.FILTER_TYPE_MTI if MTI else radar.FILTER_TYPE_NONE radar.SetDynamicImageFilter(filter_type) # Start the system in preparation for scanning. radar.Start() # Calibrate scanning to ignore or reduce the signals if not in MTI mode. if not MTI: common.calibrate() frame_rate = radar.GetAdvancedParameter('FrameRate') logger.info(f'radar frame rate: {frame_rate}') logger.info(f'desired labels: {args.desired_labels}') samples, labels = plot_and_capture_data(args.num_samples, args.realtime_plot, args.save_plot, args.save_plot_path, args.desired_labels) # Append data file if it already exists, else create a new one. if samples and labels: logger.info(f'Captured {len(labels)} new samples with label(s) {set(labels)}.') try: with open(os.path.join(common.PRJ_DIR, common.RADAR_DATA), 'rb') as fp: data = pickle.load(fp)
def main(): radar.Init() # Configure Walabot database install location. radar.SetSettingsFolder() # Establish communication with walabot. try: radar.ConnectAny() except radar.WalabotError as err: print(f'Failed to connect to Walabot.\nerror code: {str(err.code)}') exit(1) # Set radar scan profile. radar.SetProfile(common.RADAR_PROFILE) # Set scan arena in polar coords radar.SetArenaR(common.R_MIN, common.R_MAX, common.R_RES) radar.SetArenaPhi(common.PHI_MIN, common.PHI_MAX, common.PHI_RES) radar.SetArenaTheta(common.THETA_MIN, common.THETA_MAX, common.THETA_RES) # Threshold radar.SetThreshold(RADAR_THRESHOLD) # radar filtering filter_type = radar.FILTER_TYPE_MTI if MTI else radar.FILTER_TYPE_NONE radar.SetDynamicImageFilter(filter_type) # Start the system in preparation for scanning. radar.Start() # Calibrate scanning to ignore or reduce the signals if not in MTI mode. if not MTI: common.calibrate() try: while True: # Scan according to profile and record targets. radar.Trigger() # Retrieve any targets from the last recording. targets = radar.GetSensorTargets() if not targets: continue # Retrieve the last completed triggered recording raw_image, size_x, size_y, size_z, _ = radar.GetRawImage() raw_image_np = np.array(raw_image, dtype=np.float32) for t, target in enumerate(targets): print( 'Target #{}:\nx: {}\ny: {}\nz: {}\namplitude: {}\n'.format( t + 1, target.xPosCm, target.yPosCm, target.zPosCm, target.amplitude)) i, j, k = common.calculate_matrix_indices( target.xPosCm, target.yPosCm, target.zPosCm, size_x, size_y, size_z) # projection_yz is the 2D projection of target in y-z plane. projection_yz = raw_image_np[i, :, :] # projection_xz is the 2D projection of target in x-z plane. projection_xz = raw_image_np[:, j, :] # projection_xy is 2D projection of target signal in x-y plane. projection_xy = raw_image_np[:, :, k] observation = common.process_samples( [(projection_xy, projection_yz, projection_xz)], proj_mask=PROJ_MASK) # Make a prediction. name, prob = classifier(observation) if name == 'person': color_name = colored(name, 'green') elif name == 'dog': color_name = colored(name, 'yellow') elif name == 'cat': color_name = colored(name, 'blue') else: color_name = colored(name, 'red') print(f'Detected {color_name} with probability {prob}\n') except KeyboardInterrupt: pass finally: # Stop and Disconnect. radar.Stop() radar.Disconnect() radar.Clean() print('Successful termination.')