How Does the OK3588-C Arm Motherboard Implement Face Detection?

Nowadays, face recognition technology is becoming more and more mature and widely used. Face detection implementation is an important part of face recognition technology. This article will introduce how to add the OpenCV face detection model on the basis of video surveillance on the OK3588-C Arm Motherboard to quickly implement the face detection function.

OK3588-C development board

Implementation Method

1. Go to OpenCV and download the trained public model version: opencv/opencv at master (github.com)

After downloading and unzipping, copy the xml (under the \opencv-master\data\haarcascades file) to the static directory:

Face detection implementation

2. Modify the video surveillance code

# Create a cascade classifier and load a .xml classifier file. It can be either a Haar feature or a classifier with LBP features
# face_detect = cv2.CascadeClassifier(r'./static/haarcascade_frontalface_default.xml')
face_detect = cv2.CascadeClassifier(r'./static/haarcascade_frontalcatface.xml')
def get_image_dataurl():
	# (1). Read data from the camera. If the reading succeeds “ret” is TRUE , otherwise it is False. It is a three-dimensional array saved as image in the frame.
	ret, frame = cap.read()
	#Process gray-scale 
	gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
	# Detect face in multiple spaces and return results (Face area coordinate information)
	face_zone = face_detect.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=8)
	# Draw rectangles and circles to detect faces.
    	for x, y, w, h in face_zone:
        cv2.rectangle(frame, pt1=(x, y), pt2=(x + w, y + h), color=[0, 0, 255], thickness=2)
        # cv2.circle(frame, center=(x + w // 2, y + h // 2), radius=w // 2, color=[0, 255, 0], thickness=2) 
	# Display images.
	# (2). First encode the array type into jepg data, then convert it to byte array, and finally encode it in base64
    	r, buf = cv2.imencode(".jpeg", frame)
    	dat = Image.fromarray(np.uint8(buf)).tobytes()
    	img_date_url = JPEG_HEADER + str(base64.b64encode(dat))[2:-1]
    	return img_date_url

By visiting the web pages, as a human face appears in the image, it can be detected accurately after adding the face detection code and restarting the service. It is worth noting that the system has a very low CPU usage, which indicates its efficient computing power and excellent performance.

Thanks to the powerful performance of the RK3588 development board. Its high-performance GPU and NPU can quickly process face-detection tasks. At the same time, combined with the tornado framework and OpenCV library, the implementation of face detection becomes more efficient and simple. In addition, the RK3588 development board also supports various interfaces and protocols and can be seamlessly connected with different devices, providing more possibilities for the application of face recognition technology.