Welcome to DOFBOT Pro repository
3. Face positioning
Face Positioning
Orin board users can directly open a web page and enter IP address:8888 to access jupyter-lab and run directly. Jetson-Nano board users need to first enter the docker container, then enter the following command in docker:
cdjupyter-lab --allow-rootThen open a web page and enter IP address:9999 to access jupyter-lab and run the following program.
The principle of the face positioning experiment is to determine the position information of the face relative to the camera by calculating the center point coordinates of the face in the camera image, thereby achieving face positioning. The experimental results show that it will continuously find the center point of the face, print the center point coordinates, and draw a box on the face.
Code path:
xxxxxxxxxx#Jetson-Nano users need to enter the docker container to view~/dofbot_pro/dofbot_face_follow/scripts/Face_position.ipynb1. Main Code
- Import header files
xxxxxxxxxximport cv2 as cvimport threadingfrom time import sleepimport ipywidgets as widgetsfrom IPython.display import displayfrom face_position import Face_Positionfrom dofbot_utils.robot_controller import Robot_Controllerfrom dofbot_utils.fps import FPSfrom dofbot_utils.dofbot_config import *- Create instances, initialize parameters
xxxxxxxxxxrobot = Robot_Controller()robot.move_init_pose()fps = FPS()face = Face_Position()model = 'General'- Main process
xxxxxxxxxxdef camera(): global model # 打开摄像头 Open camera capture = cv.VideoCapture(0, cv.CAP_V4L2) capture.set(3, 640) capture.set(4, 480) capture.set(5, 30) while capture.isOpened(): try: _, img = capture.read() fps.update_fps() img, pos = follow.follow_function(img) if model == 'Exit': cv.destroyAllWindows() capture.release() break fps.show_fps(img) imgbox.value = cv.imencode('.jpg', img)[1].tobytes() except KeyboardInterrupt:capture.release()- Startup
xxxxxxxxxxdisplay(controls_box,output)threading.Thread(target=camera, ).start()
2. Run the Program
Click the run entire program button on the jupyterlab toolbar, then scroll to the bottom.

After the program starts, place a face image in the camera view. You can see a green box framing the face. As you move the face image, the box will also follow the face movement.

Open Log information, select Log Level as Info, you can see the printed face position coordinates.

If you need to end the program, please click [Exit] to avoid affecting other programs from calling resources.