def main(args): """Sets up object detection according to the provided args.""" # If no number of workers are specified, use all available GPUs input_q = Queue(maxsize=args.queue_size) output_q = Queue(maxsize=args.queue_size) draw_proc = Process(target=draw_worker, args=( input_q, output_q, args.detect_workers, args.track_gpu_id, args.rows, args.cols, args.detect_rate, )) draw_proc.start() if args.stream: print('Reading from hls stream.') video_capture = HLSVideoStream(src=args.stream).start() elif args.video_path: print('Reading from local video.') video_capture = LocalVideoStream(src=args.video_path, width=args.width, height=args.height).start() else: print('Reading from webcam.') video_capture = LocalVideoStream(src=args.video_source, width=args.width, height=args.height).start() video_out = None if args.video_out_fname is not None: video_out = cv2.VideoWriter( args.video_out_fname, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), OUTPUT_FRAME_RATE, (video_capture.WIDTH, video_capture.HEIGHT)) fps = FPS().start() while True: # fps._numFrames < 120 try: frame = video_capture.read() input_q.put(frame) start_time = time.time() output_rgb = cv2.cvtColor(output_q.get()[0], cv2.COLOR_RGB2BGR) if args.show_frame: cv2.imshow('Video', output_rgb) if video_out is not None: video_out.write(output_rgb) fps.update() print('[INFO] elapsed time: {:.2f}'.format(time.time() - start_time)) if cv2.waitKey(1) & 0xFF == ord('q'): break except (KeyboardInterrupt, SystemExit): if video_out is not None: video_out.release() break fps.stop() print('[INFO] elapsed time (total): {:.2f}'.format(fps.elapsed())) print('[INFO] approx. FPS: {:.2f}'.format(fps.fps())) if video_out is not None: video_out.release() draw_proc.join() video_capture.stop() cv2.destroyAllWindows()
receive_thread = threading.Thread(target=telloControllerThread) receive_thread.daemon = True receive_thread.start() logger = multiprocessing.log_to_stderr() logger.setLevel(multiprocessing.SUBDEBUG) input_q = Queue(maxsize=args.queue_size) output_q = Queue(maxsize=args.queue_size) pool = Pool(args.num_workers, worker, (input_q, output_q)) if (args.stream): print('Reading from hls stream.') video_capture = HLSVideoStream(src=args.stream).start() else: print('Reading from webcam.') video_capture = WebcamVideoStream(src=args.video_source, width=args.width, height=args.height).start() fps = FPS().start() while True: # fps._numFrames < 120 receiving = True frame = video_capture.read() input_q.put(frame) t = time.time()
parser.add_argument('-ht', '--height', dest='height', type=int, default=480, help='Height of the frames in the video stream.') parser.add_argument('-strout','--stream-output', dest="stream_out", help='The URL to send the livestreamed object detection to.') args = parser.parse_args() input_q = Queue(1) # fps is better if queue is higher but then more lags output_q = Queue() for i in range(1): t = Thread(target=worker, args=(input_q, output_q)) t.daemon = True t.start() if (args.stream_in): print('Reading from hls stream.') stream_name = args.stream_in.split('/live/')[1].split('/playlist.m3u8')[0] video_capture = HLSVideoStream(src=args.stream_in).start() else: print('Reading from webcam.') video_capture = WebcamVideoStream(src=args.video_source, width=args.width, height=args.height).start() fps = FPS().start() args.width = int(video_capture.WIDTH * FEED_IMAGE_HEIGHT / video_capture.HEIGHT) # int(video_capture.WIDTH * IMAGE_SCALE_FACTOR) args.height = FEED_IMAGE_HEIGHT # int(video_capture.HEIGHT * IMAGE_SCALE_FACTOR) print("args width" + str(args.width)) print("args height" + str(args.height)) last_bus_points = []