Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed no args performance #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions object_detection_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 10 additions & 13 deletions object_detection_multithreading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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!')
Expand Down
8 changes: 5 additions & 3 deletions utils/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down