|
1 | 1 | import os |
2 | 2 | import cv2 |
| 3 | +import time |
3 | 4 | import argparse |
4 | 5 | import multiprocessing |
5 | 6 | import numpy as np |
|
21 | 22 |
|
22 | 23 | NUM_CLASSES = 90 |
23 | 24 |
|
24 | | -NUM_WORKERS = 2 # cv2.getNumberOfCPUs() - 1 |
25 | | -QUEUE_SIZE = 5 |
26 | | - |
27 | 25 | # Loading label map |
28 | 26 | label_map = label_map_util.load_labelmap(PATH_TO_LABELS) |
29 | 27 | categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, |
@@ -88,33 +86,47 @@ def worker(input_q, output_q): |
88 | 86 | parser = argparse.ArgumentParser() |
89 | 87 | parser.add_argument('-src', '--source', dest='video_source', type=int, |
90 | 88 | default=0, help='Device index of the camera.') |
| 89 | + parser.add_argument('-wd', '--width', dest='width', type=int, |
| 90 | + default=480, help='Width of the frames in the video stream.') |
| 91 | + parser.add_argument('-ht', '--height', dest='height', type=int, |
| 92 | + default=360, help='Height of the frames in the video stream.') |
| 93 | + parser.add_argument('-num-w', '--num-workers', dest='num_workers', type=int, |
| 94 | + default=2, help='Number of workers.') |
| 95 | + parser.add_argument('-q-size', '--queue-size', dest='queue_size', type=int, |
| 96 | + default=5, help='Size of the queue.') |
91 | 97 | args = parser.parse_args() |
92 | 98 |
|
93 | 99 | logger = multiprocessing.log_to_stderr() |
94 | 100 | logger.setLevel(multiprocessing.SUBDEBUG) |
95 | 101 |
|
96 | | - input_q = Queue(maxsize=QUEUE_SIZE) |
97 | | - output_q = Queue(maxsize=QUEUE_SIZE) |
| 102 | + input_q = Queue(maxsize=args.queue_size) |
| 103 | + output_q = Queue(maxsize=args.queue_size) |
98 | 104 |
|
99 | 105 | process = Process(target=worker, args=((input_q, output_q))) |
100 | 106 | process.daemon = True |
101 | | - pool = Pool(NUM_WORKERS, worker, (input_q, output_q)) |
| 107 | + pool = Pool(args.num_workers, worker, (input_q, output_q)) |
102 | 108 |
|
103 | | - video_capture = WebcamVideoStream(src=args.video_source).start() |
| 109 | + video_capture = WebcamVideoStream(src=args.video_source, |
| 110 | + width=args.width, |
| 111 | + height=args.height).start() |
104 | 112 | fps = FPS().start() |
105 | 113 |
|
106 | 114 | while True: # fps._numFrames < 120 |
107 | 115 | frame = video_capture.read() |
108 | 116 | input_q.put(frame) |
109 | 117 |
|
| 118 | + t = time.time() |
| 119 | + |
110 | 120 | cv2.imshow('Video', output_q.get()) |
111 | 121 | fps.update() |
112 | 122 |
|
| 123 | + print('[INFO] elapsed time: {:.2f}'.format(time.time() - t)) |
| 124 | + |
113 | 125 | if cv2.waitKey(1) & 0xFF == ord('q'): |
114 | 126 | break |
115 | 127 |
|
116 | 128 | fps.stop() |
117 | | - print('[INFO] elasped time: {:.2f}'.format(fps.elapsed())) |
| 129 | + print('[INFO] elapsed time (total): {:.2f}'.format(fps.elapsed())) |
118 | 130 | print('[INFO] approx. FPS: {:.2f}'.format(fps.fps())) |
119 | 131 |
|
120 | 132 | video_capture.stop() |
|
0 commit comments