# resolution is constant during the lifetime of the Lambda.
ret, sample_frame = awscam.getLastFrame()
if not ret:
raise Exception("Failed to get frame from the stream")
# Construct the custom helper object. This object just lets us handle
postprocessing
# in a managable way.
head_pose_detection = HeadDetection(sample_frame.shape[1]/2,
sample_frame.shape[0]/2)
# Dictionary that will allow us to convert the inference labels
# into a human a readable format.
output_map = ({0:'Bottom Right', 1:'Middle Right', 2:'Top Right', 3:'Bottom
Middle',
# This model is a ResNet classifier, so our output will be classification.
model_type = "classification"
# Define a rectangular region where we expect the persons head to be.
crop_upper_left_y = 440
crop_height = 640
crop_upper_left_x = 1024
crop_width = 640
while True:
# Grab the latest frame off the mjpeg stream.
ret, frame = awscam.getLastFrame()
if not ret:
raise Exception("Failed to get frame from the stream")
# Mirror Image
frame = cv2.flip(frame, 1)
# Draw the rectangle around the area that we expect the persons head to be.
cv2.rectangle(frame, (crop_upper_left_x, crop_upper_left_y),
crop_height),
# Crop the the frame so that we can do inference on the area of the frame where
# expect the persons head to be.
frame_crop = frame[crop_upper_left_y:crop_upper_left_y + crop_height,
# Down sample the image.
frame_resize = cv2.resize(frame_crop, (input_width, input_height))
# Renormalize the image so that the color magnitudes are between 0 and 1
frame_resize = frame_resize.astype(np.float32)/255.0
# Run the down sampled image through the inference engine.
infer_output = model.doInference(frame_resize)
# Parse the results so that we get back a more manageble data structure.
parsed_results = model.parseResult(model_type, infer_output)[model_type]
# Post process the image and send it to the FIFO file
head_pose_detection.send_data(frame, parsed_results)
# Send the results to MQTT in JSON format.
client.publish(topic=iot_topic,
output_map))
except Exception as ex:
msg = "Lambda has failure, error msg {}: ".format(ex)
client.publish(topic=iot_topic, payload=msg)
# Entry point of the lambda function.
head_detection()
LaLocalDisplayLa clase que se define en la función Lambda que aparece a continuación serializa
las imágenes procesadas, en un subproceso dedicado, en un archivo FIFO especificado que sirve como
fuente para reproducir los resultados de la inferencia como transmisión del proyecto.
La clase HeadDetection controla el posprocesamiento de los datos analizados, incluidas las llamadas a
una posición y postura de la cabeza detectadas en la visualización local de la transmisión del proyecto.
AWS DeepLens Guía para desarrolladores
Crear y ejecutar el proyecto de
detección de posición de cabeza
4:'Middle Middle', 5:'Top Middle', 6:'Bottom Left', 7:'Middle Left',
8:'Top Left'})
(crop_upper_left_x + crop_width, crop_upper_left_y +
(255, 40, 0), 4)
crop_upper_left_x:crop_upper_left_x + crop_width]
payload=head_pose_detection.get_results(parsed_results,
109