Welcome to RDK X5 Robot repository
7. Face Detection
Face Detection
7.1 Introduction
This course mainly uses the IMX219 camera to obtain the camera image, detect faces and frame faces.
7.2 Core Content Analysis
Load face Haar feature data.
xxxxxxxxxxface_haar = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
Pass the image into the face haar parser to extract the face position information.
xxxxxxxxxxdef face_detect(image):gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)faces = face_haar.detectMultiScale(gray_img, 1.1, 3)for face_x,face_y,face_w,face_h in faces:return "1", (face_x,face_y,face_w,face_h)return None, (0,0,0,0)
After turning on the start switch, determine whether there is a face in the returned image, and if so, frame the face.
xxxxxxxxxxstate, (face_x,face_y,face_w,face_h) = face_detect(frame)if state != None:cv2.rectangle(frame, (face_x, face_y), (face_x+face_w, face_y+face_h), (0,255,255), 1)
7.3 How to play
Open the jupyterLab client and find the code path:
xxxxxxxxxx/home/sunrise/sunriseRobot/Samples/2_AI/07_face_detect/face_detect.ipynb
Click to run all cells, then pull to the bottom to see the generated controls.

Click the Start button below to turn on the face detection function. When a face appears in the camera image, the face will be framed with a box.

Finally, click the Close_Camera button to close the camera.