def PeopleCounterApp(): # PeopleCounter object people_counter = PeopleCounter() # walabotAPI.SetArenaR - input parameters rArenaMin, rArenaMax, rArenaRes = 5, 120, 5 # walabotAPI.SetArenaPhi - input parameters phiArenaMin, phiArenaMax, phiArenaRes = -60, 60, 3 # walabotAPI.SetArenaTheta - input parameters thetaArenaMin, thetaArenaMax, thetaArenaRes = -20, 20, 10 # Configure Walabot database install location (for windows) walabotAPI.SetSettingsFolder() # 1) Connect: Establish communication with walabot. walabotAPI.ConnectAny() # 2) Configure: Set scan profile and arena # Set Profile - to Tracker. walabotAPI.SetProfile(walabotAPI.PROF_TRACKER) # Set arena by Polar coordinates, with arena resolution walabotAPI.SetArenaR(rArenaMin, rArenaMax, rArenaRes) walabotAPI.SetArenaPhi(phiArenaMin, phiArenaMax, phiArenaRes) walabotAPI.SetArenaTheta(thetaArenaMin, thetaArenaMax, thetaArenaRes) # Walabot filtering MTI walabotAPI.SetDynamicImageFilter(walabotAPI.FILTER_TYPE_MTI) # 3) Start: Start the system in preparation for scanning. walabotAPI.Start() try: num_of_people = 0 while True: # 4) Trigger: Scan (sense) according to profile and record signals # to be available for processing and retrieval. walabotAPI.Trigger() # 5) Get action: retrieve the last completed triggered recording targets = walabotAPI.GetTrackerTargets() # 6) Sort targets by amplitude targets = sorted(targets, key=lambda x: x.zPosCm, reverse=True) # 7) Update state and get people count prev_num_of_people = num_of_people num_of_people = people_counter.update_state_get_count(targets) if prev_num_of_people != num_of_people: if (num_of_people > 0): return num_of_people # print y-axis of target found # PrintTrackerTargets(targets) except KeyboardInterrupt: pass finally: # 7) Stop and Disconnect. walabotAPI.Stop() walabotAPI.Disconnect() walabotAPI.Clean() return 0 print('Terminated successfully!')
if energy > energy_threshold: state = True else: state = False if debug: print('Energy: {:<10}Frame Rate: {}'.format( energy, 1 / (time.time() - t))) t = time.time() if __name__ == '__main__': print("Initialize API") WalabotAPI.Init() while True: WalabotAPI.Initialize() # Check if a Walabot is connected try: WalabotAPI.ConnectAny() run() except WalabotAPI.WalabotError as err: print('Failed to connect to Walabot. error code: {}'.format( str(err.code))) except Exception as err: print(err) finally: print("Cleaning API") WalabotAPI.Clean() time.sleep(2)
samples, labels = plot_and_capture_data(args.num_samples, args.realtime_plot, args.save_plot, args.save_plot_path) # Append data file if it already exists, else create a new one. if samples and labels: try: with open(os.path.join(common.PRJ_DIR, common.RADAR_DATA), 'rb') as fp: logger.info('Appending existing data file.') existing_data = pickle.load(fp) samples = np.vstack((existing_data['samples'], samples)) labels = existing_data['labels'] + labels except ValueError: logger.error(f'Error while trying to append data file, exiting.') exit(1) except FileNotFoundError: logger.info('Existing data file not found, creating.') finally: data = {'samples': samples, 'labels': labels} logger.debug(f'Data dump:\n{data}') with open(os.path.join(common.PRJ_DIR, common.RADAR_DATA), 'wb') as fp: logger.info(f'Saving data file with labels {set(labels)}.') fp.write(pickle.dumps(data)) else: logger.info(f'No data was captured.') # Stop and Disconnect radar. radar.Stop() radar.Disconnect() radar.Clean() logger.info('Successful radar shutdown.')
try: wala_data_slice, sizeX, sizeY, depth, power = wala.GetRawImageSlice() plt.imshow(wala_data_slice) plt.pause(0.05) except: print("closing matplotlib") """ #cv.imshow('frame', frame) #frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB) #im1.set_data(frame) #plt.pause(.05) if (keyboard.is_pressed('q')): # Close the jsonstreams objects, this adds the closing '}' to the file time_stamp_out.close() wala_out.close() # Take a quick break, walabot wala.Disconnect() wala.Clean() # Close out the cv objects, go home, go to sleep. Goodnight. cap.release() cv.destroyAllWindows() break #plt.ioff() #start = time.time()
def predict(min_proba): # Load classifier along with the label encoder. with open(os.path.join(common.PRJ_DIR, common.SVM_MODEL), 'rb') as fp: model = pickle.load(fp) with open(os.path.join(common.PRJ_DIR, common.LABELS), 'rb') as fp: le = pickle.load(fp) # Calculate size of radar image data array used for training. train_size_z = int((common.R_MAX - common.R_MIN) / common.R_RES) + 1 train_size_y = int((common.PHI_MAX - common.PHI_MIN) / common.PHI_RES) + 1 train_size_x = int( (common.THETA_MAX - common.THETA_MIN) / common.THETA_RES) + 1 logger.debug(f'train_size: {train_size_x}, {train_size_y}, {train_size_z}') 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): logger.info('**********') logger.info( '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] proj_zoom = calc_proj_zoom(train_size_x, train_size_y, train_size_z, size_x, size_y, size_z) observation = common.process_samples( [(projection_xz, projection_yz, projection_xy)], proj_mask=PROJ_MASK, proj_zoom=proj_zoom, scale=True) # Make a prediction. name, prob = classifier(observation, model, le, min_proba) logger.info(f'Detected {name} with probability {prob}') logger.info('**********') except KeyboardInterrupt: pass finally: # Stop and Disconnect. radar.Stop() radar.Disconnect() radar.Clean() logger.info('Successful radar shutdown.') return
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.')
def PeopleCounterApp(): # PeopleCounter object people_counter = PeopleCounter() # walabotAPI.SetArenaR - input parameters rArenaMin, rArenaMax, rArenaRes = 5, 120, 5 # walabotAPI.SetArenaPhi - input parameters phiArenaMin, phiArenaMax, phiArenaRes = -60, 60, 3 # walabotAPI.SetArenaTheta - input parameters thetaArenaMin, thetaArenaMax, thetaArenaRes = -20, 20, 10 # Configure Walabot database install location (for windows) walabotAPI.SetSettingsFolder() # 1) Connect: Establish communication with walabot. walabotAPI.ConnectAny() # 2) Configure: Set scan profile and arena # Set Profile - to Tracker. walabotAPI.SetProfile(walabotAPI.PROF_TRACKER) # Set arena by Polar coordinates, with arena resolution walabotAPI.SetArenaR(rArenaMin, rArenaMax, rArenaRes) walabotAPI.SetArenaPhi(phiArenaMin, phiArenaMax, phiArenaRes) walabotAPI.SetArenaTheta(thetaArenaMin, thetaArenaMax, thetaArenaRes) # Walabot filtering MTI walabotAPI.SetDynamicImageFilter(walabotAPI.FILTER_TYPE_MTI) # 3) Start: Start the system in preparation for scanning. walabotAPI.Start() try: client_socket = socket.socket() client_socket.connect((SERVER_ADDRESS, SERVER_PORT)) num_of_people = 0 while True: # 4) Trigger: Scan (sense) according to profile and record signals # to be available for processing and retrieval. walabotAPI.Trigger() # 5) Get action: retrieve the last completed triggered recording targets = walabotAPI.GetTrackerTargets() # 6) Sort targets by amplitude targets = sorted(targets, key=lambda x: x.zPosCm, reverse=True) # 7) Update state and get people count prev_num_of_people = num_of_people num_of_people = people_counter.update_state_get_count(targets) if prev_num_of_people != num_of_people: print('# {} #\n'.format(num_of_people)) # print y-axis of target found # PrintTrackerTargets(targets) # Run this line in python2.7 # client_socket.send(json.dumps({"room": ROOM_NAME, "number_of_people": numOfPeople})) # Run this line in python3 client_socket.send( json.dumps({ "name": ROOM_NAME, "number_of_people": num_of_people, "max_people": MAX_PEOPLE }).encode('UTF-8')) except socket.error: print("Server is currently unavailable.") except KeyboardInterrupt: pass finally: # 7) Stop and Disconnect. walabotAPI.Stop() walabotAPI.Disconnect() walabotAPI.Clean() print('Terminated successfully!')