赞
踩
from ultralytics import YOLO # 加载模型 model = YOLO('yolov8n.pt') # 预测视频帧 result = model.predict(frame) for output in result: conf = output.boxes.conf xyxy = output.boxes.xyxy cls = output.boxes.cls #绘制结果 res_plotted = result[0].plot() cv2.imwrite("runs/out.jpg", res_plotted)
from ultralytics.yolo.utils.plotting import colors
# 0: person
c = 0
color = colors(c)
ultralytics/yolo/engine/results
ultralytics/yolo/utils/plotting.py
res = model.predict(input) keypoints = res[0].keypoints # keypoints[0]: # tensor([[252.1356, 53.5941, 0.9974], # [259.1374, 46.1328, 0.9820], # [244.4133, 46.8059, 0.9837], # [272.5132, 51.1340, 0.6986], # [234.5109, 54.0464, 0.7821], # [281.7415, 92.0788, 0.9962], # [217.0259, 99.8510, 0.9987], # [303.3503, 131.4309, 0.9885], # [179.2675, 159.3849, 0.9960], # [343.6052, 121.5844, 0.9864], # [229.3094, 191.5756, 0.9945], # [266.0266, 201.0648, 0.9996], # [217.8109, 209.0343, 0.9996], # [315.8262, 278.2117, 0.9988], # [224.8120, 302.9610, 0.9987], # [332.7999, 377.5961, 0.9824], # [174.8404, 340.4106, 0.9840]], device='cuda:0')
返回的关键点共17个,keypoints.shape = [17, 3],分别是 x ,y ,conf
关键点是有顺序的,如图标注
连接规则&颜色:
skeleton = [[16, 14], [14, 12], [17, 15], [15, 13], [12, 13], [6, 12], [7, 13], [6, 7], [6, 8], [7, 9],
[8, 10], [9, 11], [2, 3], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]]
pose_palette = np.array([[255, 128, 0], [255, 153, 51], [255, 178, 102], [230, 230, 0], [255, 153, 255],
[153, 204, 255], [255, 102, 255], [255, 51, 255], [102, 178, 255], [51, 153, 255],
[255, 153, 153], [255, 102, 102], [255, 51, 51], [153, 255, 153], [102, 255, 102],
[51, 255, 51], [0, 255, 0], [0, 0, 255], [255, 0, 0], [255, 255, 255]],
dtype=np.uint8)
kpt_color = pose_palette[[16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9]]
limb_color = pose_palette[[9, 9, 9, 9, 7, 7, 7, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16]]
各个身体部分在skeleton中的序号:
# 拼音
body_name_dict = {'zuoxiaotui': 0, 'zuodatui': 1,
'youxiaotui': 2, 'youdatui': 3,
'kua': 4, 'zuoce': 5, 'youce': 6, 'shuangjian': 7,
'zuodabi': 8, 'youdabi': 9, 'zuoxiaobi': 10, 'youxiaobi': 11, 'tou': '12:19'}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。