else:
cv2.putText(frame, "Up Left", (1024, 440 - 15), font_type, 3, font_color,
line_type)
cv2.rectangle(overlay, (rect_margin, rect_margin),
# Set the opacity
alpha = 0.2
cv2.addWeighted(overlay, alpha, frame, 1 - alpha, 0, frame)
# Draw the red ball at the previous x-y position.
cv2.circle(frame, (self.circ_cent_x, self.circ_cent_y), 50, (0, 0, 255), -1)
# Update the balls x-y coordinates.
self.circ_cent_x += int(change_x)
self.circ_cent_y += int(change_y)
# Make sure the ball stays inside the image.
if self.circ_cent_x > self.x_max:
self.circ_cent_x = self.x_max
if self.circ_cent_x < 0:
self.circ_cent_x = 0
if self.circ_cent_y > self.y_max:
self.circ_cent_y = self.y_max
if self.circ_cent_y < 0:
self.circ_cent_y = 0
# Send the post processed frame to the FIFO file for display
self.result_thread.set_frame_data(frame)
def adjust_x_vel(self, velocity, pct_of_center):
""" Helper for computing
velocity - x direction velocity.
pct_of_center - The percantage around the center of the image that
we should consider a dead zone.
"""
x_vel = 0
if self.circ_cent_x < (1.0 - pct_of_center) * self.x_max/2:
x_vel = velocity
if self.circ_cent_x > (1.0 - pct_of_center) * self.x_max/2:
x_vel = -1 *velocity
return x_vel
def adjust_y_vel(self, velocity, pct_of_center):
""" Helper for computing
velocity - y direction velocity.
pct_of_center - The percantage around the center of the image that
we should consider a dead zone.
"""
y_vel = 0
if self.circ_cent_y < (1.0 - pct_of_center) * self.y_max/2:
y_vel = velocity
if self.circ_cent_y > (1.0 - pct_of_center) * self.y_max/2:
y_vel = -1 * velocity
return y_vel
def send_data(self, frame, parsed_results):
""" Method that handles all post processing and sending the results to a FIFO file.
frame - The frame that will be post processed.
parsed_results - A dictionary containing the inference results.
"""
label = parsed_results[0]["label"]
# Use the probability to determine the velocity, scale it by 100 so that the ball
# moves across the screen at reasonable rate.
velocity = parsed_results[0]["prob"] * 100
pct_of_center = 0.05
if label == 0:
self.update_coords(frame, velocity, velocity, label)
elif label == 1:
AWS DeepLens Guía para desarrolladores
Crear y ejecutar el proyecto de
detección de posición de cabeza
(0, 255, 0), -1)
(rect_width, rect_height), (0, 255, 0), -1)
the next x coordinate.
the next y coordinate.
107