diff --git a/object_detection_app.py b/object_detection_app.py index 999ca28..4899720 100644 --- a/object_detection_app.py +++ b/object_detection_app.py @@ -89,9 +89,9 @@ def worker(input_q, output_q): parser.add_argument('-src', '--source', dest='video_source', type=int, default=0, help='Device index of the camera.') parser.add_argument('-wd', '--width', dest='width', type=int, - default=480, help='Width of the frames in the video stream.') + default=None, help='Width of the frames in the video stream.') parser.add_argument('-ht', '--height', dest='height', type=int, - default=360, help='Height of the frames in the video stream.') + default=None, help='Height of the frames in the video stream.') parser.add_argument('-num-w', '--num-workers', dest='num_workers', type=int, default=2, help='Number of workers.') parser.add_argument('-q-size', '--queue-size', dest='queue_size', type=int, diff --git a/object_detection_multithreading.py b/object_detection_multithreading.py index e65f12e..97e6e4a 100644 --- a/object_detection_multithreading.py +++ b/object_detection_multithreading.py @@ -89,9 +89,9 @@ def worker(input_q, output_q): parser.add_argument('-src', '--source', dest='video_source', type=int, default=0, help='Device index of the camera.') parser.add_argument('-wd', '--width', dest='width', type=int, - default=640, help='Width of the frames in the video stream.') + default=None, help='Width of the frames in the video stream.') parser.add_argument('-ht', '--height', dest='height', type=int, - default=480, help='Height of the frames in the video stream.') + default=None, 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() @@ -112,6 +112,7 @@ def worker(input_q, output_q): height=args.height).start() fps = FPS().start() + font = cv2.FONT_HERSHEY_SIMPLEX while True: frame = video_capture.read() input_q.put(frame) @@ -121,18 +122,14 @@ def worker(input_q, output_q): if output_q.empty(): pass # fill up queue else: - font = cv2.FONT_HERSHEY_SIMPLEX data = output_q.get() - rec_points = data['rect_points'] - class_names = data['class_names'] - class_colors = data['class_colors'] - for point, name, color in zip(rec_points, class_names, class_colors): - cv2.rectangle(frame, (int(point['xmin'] * args.width), int(point['ymin'] * args.height)), - (int(point['xmax'] * args.width), int(point['ymax'] * args.height)), color, 3) - cv2.rectangle(frame, (int(point['xmin'] * args.width), int(point['ymin'] * args.height)), - (int(point['xmin'] * args.width) + len(name[0]) * 6, - int(point['ymin'] * args.height) - 10), color, -1, cv2.LINE_AA) - cv2.putText(frame, name[0], (int(point['xmin'] * args.width), int(point['ymin'] * args.height)), font, + for point, name, color in zip(data['rect_points'], data['class_names'], data['class_colors']): + cv2.rectangle(frame, (int(point['xmin'] * frame.shape[1]), int(point['ymin'] * frame.shape[0])), + (int(point['xmax'] * frame.shape[1]), int(point['ymax'] * frame.shape[0])), color, 3) + cv2.rectangle(frame, (int(point['xmin'] * frame.shape[1]), int(point['ymin'] * frame.shape[0])), + (int(point['xmin'] * frame.shape[1]) + len(name[0]) * 6, + int(point['ymin'] * frame.shape[0]) - 10), color, -1, cv2.LINE_AA) + cv2.putText(frame, name[0], (int(point['xmin'] * frame.shape[1]), int(point['ymin'] * frame.shape[0])), font, 0.3, (0, 0, 0), 1) if args.stream_out: print('Streaming elsewhere!') diff --git a/utils/app_utils.py b/utils/app_utils.py index 8bfeb96..61b48de 100644 --- a/utils/app_utils.py +++ b/utils/app_utils.py @@ -121,12 +121,14 @@ def stop(self): class WebcamVideoStream: - def __init__(self, src, width, height): + def __init__(self, src, width=None, height=None): # initialize the video camera stream and read the first frame # from the stream self.stream = cv2.VideoCapture(src) - self.stream.set(cv2.CAP_PROP_FRAME_WIDTH, width) - self.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, height) + if width: + self.stream.set(cv2.CAP_PROP_FRAME_WIDTH, width) + if height: + self.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, height) (self.grabbed, self.frame) = self.stream.read() # initialize the variable used to indicate if the thread should