Welcome to DOFBOT-JetsonNANO repository
4.Face positioning
Face Positioning Experiment
The main purpose of face positioning is to achieve advanced functionality for face tracking. The principle is to determine the distance and position information of the face relative to the camera by calculating the center point coordinates of the face in the camera's field of view, thereby achieving face positioning. The experimental results show that it continuously finds and follows the center point of the face and prints the center point. (Face recognition can be found in previous tutorials)
- Start Docker
After entering the main board desktop, open the terminal and run the following command to start the corresponding Dofbot container:
./Docker_Ros.sh
Then, in the Docker terminal, input the following command to start jupyter-lab,
xxxxxxxxxxcdjupyter-lab --allow-root
Then, in the browser, input the main board's IP address plus :9999
xxxxxxxxxxIP:9999 // Example: 192.168.1.11:9999
Code path: /root/Dofbot_2D/src/dofbot_face_follow/Face positioning.ipynb
1. Main Code
- Import header files
xxxxxxxxxximport cv2 as cvimport threadingfrom time import sleepimport ipywidgets as widgetsfrom IPython.display import displayfrom face_pose import face_follow- Create instance, initialize parameters
xxxxxxxxxx# Create instancefollow = face_follow()# Initialize modemodel = 'General'- Main implementation function, prints center coordinates.
xdef follow_function(self, img): img = cv.resize(img, (640, 480)) # Copy the original image to avoid interference during processing # 复制原始图像,避免处理过程中干扰 img = img.copy() # Convert image to grayscale # 将图像转为灰度图 gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) # Face detection # 检测人脸 faces = self.faceDetect.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5) if len(faces) != 0: face = self.face_filter(faces) # Face filtering # 人脸过滤 (x, y, w, h) = face # Draw a rectangle on the original color map # 在原彩图上绘制矩形 cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 4) cv.putText(img, 'Person', (280, 30), cv.FONT_HERSHEY_SIMPLEX, 0.8, (105, 105, 105), 2) point_x = x + w / 2 point_y = y + h / 2 print("x= ",point_x) print("y= ",point_y) return img- Main process
xxxxxxxxxx