single-mouse-webrtc-pose / create_test_image.py
Hakureirm's picture
Initial commit: Single mouse WebRTC pose estimation project
4673545
#!/usr/bin/env python3
"""
创建测试用的小鼠图像
"""
import cv2
import numpy as np
import os
def create_test_mouse_image():
"""创建一个简单的测试小鼠图像"""
# 创建640x640的背景图像
img = np.ones((640, 640, 3), dtype=np.uint8) * 50 # 深灰色背景
# 小鼠的大致位置和大小
center_x, center_y = 320, 320
# 绘制小鼠身体(椭圆)
body_width, body_height = 120, 60
cv2.ellipse(img, (center_x, center_y), (body_width//2, body_height//2), 0, 0, 360, (150, 150, 150), -1)
# 绘制小鼠头部(圆形)
head_x, head_y = center_x - 80, center_y
head_radius = 35
cv2.circle(img, (head_x, head_y), head_radius, (160, 160, 160), -1)
# 绘制耳朵
left_ear = (head_x - 20, head_y - 25)
right_ear = (head_x + 20, head_y - 25)
cv2.circle(img, left_ear, 10, (140, 140, 140), -1)
cv2.circle(img, right_ear, 10, (140, 140, 140), -1)
# 绘制鼻子
nose_pos = (head_x - 30, head_y)
cv2.circle(img, nose_pos, 3, (100, 100, 100), -1)
# 绘制腿部
left_leg = (center_x - 30, center_y + 40)
right_leg = (center_x + 30, center_y + 40)
cv2.circle(img, left_leg, 8, (130, 130, 130), -1)
cv2.circle(img, right_leg, 8, (130, 130, 130), -1)
# 绘制尾巴
tail_base = (center_x + 60, center_y)
tail_tip = (center_x + 120, center_y - 20)
cv2.line(img, tail_base, tail_tip, (140, 140, 140), 8)
cv2.circle(img, tail_base, 5, (135, 135, 135), -1)
cv2.circle(img, tail_tip, 3, (135, 135, 135), -1)
# 添加一些噪声使图像更真实
noise = np.random.randint(-20, 20, img.shape, dtype=np.int16)
img = np.clip(img.astype(np.int16) + noise, 0, 255).astype(np.uint8)
# 添加一些纹理
for _ in range(50):
x = np.random.randint(0, 640)
y = np.random.randint(0, 640)
cv2.circle(img, (x, y), 1, (np.random.randint(30, 70),) * 3, -1)
return img
def main():
"""主函数"""
print("正在创建测试小鼠图像...")
# 创建测试图像
test_image = create_test_mouse_image()
# 保存图像
cv2.imwrite("test_mouse.jpg", test_image)
print("✅ 测试图像已保存为 test_mouse.jpg")
# 显示图像信息
print(f"图像尺寸: {test_image.shape}")
print("您现在可以使用这个图像来测试小鼠姿态检测系统")
if __name__ == "__main__":
main()