This chapter will introduce how to use Horned Sungem to deploy SSD-Mobilenet face detector
Get Python Development Kit and Model Resources according to Getting Started page.
Graph File | graph_face_SSD |
Example | examples/apps/FaceDetector/FaceDetector.py |
# 1. Import libs
import numpy as np, cv2, sys
from hsapi import FaceDetector
# 2. Create a face detection network
net = FaceDetector(zoom=True, thresh=0.55)
"""
zoom: If True, the image output from the camera built into the Horned Sungem is 640x360, otherwise 1920x1080.
thresh: Face detection threshold, range 0-1, increasing the threshold will reduce false detection but increase missed detection, and vice versa.
device: Used to specify the device that creates the network.
graphPath: Used to customize the path of the graph file, defaulted to the examples/graphs directory.
...
Other options can refer to the specific implementation in the API.
"""
# If using an external camera, create a cv2.VideoCapture class to call the camera
WEBCAM = False
if WEBCAM: video_capture = cv2.VideoCapture(0)
# 3. Read image data and detection results, frame and display
try:
while True:
# If you use an external camera, load the camera image into the Hornd Sungem
if WEBCAM: _, img = video_capture.read()
else: img = None
result = net.run(img)
"""
When the function parameter is None, use the built-in camera of the Horned Sungem as input.
Return value 'result' is a tuple
result[0]: Image for the device (if an external camera is used, the loaded image)
result[1]: A list of multiple detection results
You can get the number of detection results by len(result[1])
result[1][0]: Detection result, a list of classification information, confidence, and location information.
result[1][0][0]: Tag
result[1][0][1]: Confidence [0-1]
result[1][0][2]: x1
result[1][0][3]: y1
result[1][0][4]: x2
result[1][0][5]: y2
"""
img = net.plot(result) # Visualize the results
cv2.imshow("Face Detector", img) # show image
cv2.waitKey(1)
finally:
net.quit() # reset device
After connecting the Horned Sungem:
cd SungemSDK-Python/examples/apps/FaceDetector
python3 FaceDetector.py