def run_camera(camera_chain, video_file_loc): # buffers for demo in batch buffer_inp = list() # Loop through frames elapsed = 0 start = timer() data_collector = DataCollector() print('Video file to open: ' + str(video_file_loc)) while True: frame_num = 0 while frame_num < FRAME_LIMIT: print('Press [ESC] to quit demo') camera = cv2.VideoCapture(video_file_loc) cam_num = UserParameters().get_cam_num() while camera.isOpened(): elapsed += 1 _, frame = camera.read() frame_num = frame_num + 1 if frame is None: print('\nEnd of Video') break buffer_inp.append(frame) # Only process and imshow when queue is full if elapsed % QUEUE == 0: for image in buffer_inp: collector_start_time = timer() process_image_response = process_img_request( image, cam_num, frame_num, camera_chain.get_processor()) cv2.imshow('', process_image_response.boxed_image) #cv2.imshow('', image) duration = str(timer() - collector_start_time) print('Processing Time: ' + duration) data_collector.write(DATA_TYPE_PROCESSING_TIME, duration) # Clear Buffers buffer_inp = list() if elapsed % 5 == 0: sys.stdout.write('\r') fps = elapsed / (timer() - start) sys.stdout.write('{0:3.3f} FPS\n'.format(fps)) data_collector.write(DATA_TYPE_FPS, str(fps)) sys.stdout.flush() choice = cv2.waitKey(1) if choice == 27: break sys.stdout.write('\n') camera.release() data_collector.close() cv2.destroyAllWindows() #run_camera()
def send_request(url, request): print('Size of request: ' + str(request.image.size)) start_time = time.time() # Send full image to edge device for further processing pickle.dump(request.image, open(PICKLED_TEMP_LOC, 'wb')) resp = requests.post(url, files={'file': open(PICKLED_TEMP_LOC, 'rb')}, verify=False) status_code = resp.status_code size_of_resp = len(resp.content) total_size = str(request.image.size + size_of_resp) resp = resp.json() print('Size of response: ' + str(size_of_resp)) print('Total transfer size: ' + total_size) duration = str(time.time() - start_time) prediction = 'Count: ' + str(len(resp['prediction'])) + ', ' + str( resp['prediction']) print('Data Transfer Time: ' + duration) print('Results: ' + prediction) data_collector = DataCollector() data_collector.write(DATA_TYPE_TRANSFER_SIZE, total_size) data_collector.write(DATA_TYPE_DATA_TRANSFER_TIME, duration) data_collector.write(DATA_TYPE_DETECTION, prediction) return NodeResponse(cc.get_status(status_code), cc.get_image(request.image, resp['prediction']), resp['prediction'])
def post_to_multi_view(request): data = { 'cam': request.cam_num, 'frame': request.frame_num, 'prediction': [create_box_resp_field(pred) for pred in request.predicted_box_loc] } size_of_request = asizeof.asizeof(data) print('Size of request: ' + str(size_of_request)) start_time = time.time() resp = requests.post(str(UserParameters().get_edge_ip()) + MULTI_VIEW_RELATIVE_URL, headers={'Content-Type': 'application/json'}, data=json.dumps(data), verify=False) status_code = resp.status_code size_of_resp = asizeof.asizeof(resp.content) total_size = str(size_of_request + size_of_resp) resp = resp.json() print('Size of response: ' + str(size_of_resp)) print('Total transfer size: ' + total_size) duration = str(time.time() - start_time) prediction = 'Count: ' + str(len(resp['prediction'])) + ', ' + str( resp['prediction']) print('Data Transfer Time: ' + duration) print('Results: ' + prediction) data_collector = DataCollector() data_collector.write(DATA_TYPE_TRANSFER_SIZE, total_size) data_collector.write(DATA_TYPE_DATA_TRANSFER_TIME, duration) data_collector.write(DATA_TYPE_DETECTION, prediction) return NodeResponse(cc.get_status(status_code), cc.get_image(request.image, resp['prediction']), resp['prediction'])