Welcome to DOGZILLA-Lite repository
20. Motion Detection
Motion Detection
Motion Detection1. Experimental Purpose2. Experimental Steps3. Experimental Results4. Experimental Source Code Analysis
This tutorial is specific to the CM5 version and will not work directly with the CM4 version
1. Experimental Purpose
Learn to use the robot dog's camera and screen to create a health assistant that counts motion. The counting here primarily involves counting detected human motions.
2. Experimental Steps
Log in to the robot dog's system, exit the robot dog program, and enter "ip (the robot dog's IP address):8888" in your browser. Once logged in, enter the password "yahboom"

Then log in. Go to the directory cd ~/DOGZILLA_Lite_class/5.AI Visual Recognition Course/20. Motion Detection and run mian.ipynb.
Finally, run the program.
3. Experimental Results
- After running the program, select the exercise to be monitored using the button in the upper right corner of the screen. The following exercises can be monitored:
- Squats
- Push-ups
- Sit-ups
- Biceps Curls
- Lateral Raises
- Overhead Presses
- Leg Raises
- Knee Raises
- Left Knee Presses
- Right Knee Presses


- After selecting the corresponding mode, press the button in the upper left corner of the screen to start monitoring the exercise.


- If you want to change the detected motion, restart the program and reselect the mode.
4. Experimental Source Code Analysis
xxxxxxxxxxwhile True: frame = picam2.capture_array() processed_frame, current_angle, keypoints = pose_processor.process_frame(frame, exercise_type) # 将OpenCV图像转为PIL图像 # Convert OpenCV images to PIL images pil_img = Image.fromarray(cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)) draw = ImageDraw.Draw(pil_img) current_count = exercise_counter.counter # 计算文本位置 Calculate text position text_width = draw.textlength(display_text, font=pil_font) count_width = draw.textlength(str(current_count), font=pil_font) right_margin = 5 text_x = processed_frame.shape[1] - text_width - right_margin count_x = processed_frame.shape[1] - count_width - right_margin # 绘制文本 Drawing Text draw.text((text_x, 30), display_text, font=pil_font, fill=(0, 255, 0)) draw.text((count_x, 60), str(current_count), font=pil_font, fill=(0, 255, 0)) # 转换回OpenCV格式 Convert back to OpenCV format processed_frame = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR) image_widget.value = bgr8_to_jpeg(myimg) if button.press_b(): breakThis while loop is the main business logic for detecting motion, and the detection is exited by detecting the button in the lower left corner of the screen.