YOLOV8 识别人体关键点

from ultralytics import YOLO

import torch

import cv2
import os
import matplotlib.pyplot as plt


# 有 GPU 就用 GPU,没有就用 CPU
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

# Load a model
# model = YOLO('yolov8n-pose.pt')  # load a pretrained model (recommended for training)

model = YOLO('yolov8n-pose.pt')

# 切换计算设备
model.to(device)

# Train the model
# model.train(data='coco8-pose.yaml', epochs=100, imgsz=640)


##预测  传入图像、视频、摄像头ID(对应命令行的 source 参数)
img_path = 'img/rj-5.jpg'
results = model(img_path)

##结果

# print(len(results),results[0])



# 框(rectangle)可视化配置
bbox_color = (150, 0, 0)             # 框的 BGR 颜色
bbox_thickness = 6                   # 框的线宽

# 框类别文字
bbox_labelstr = {
    'font_size':6,         # 字体大小
    'font_thickness':14,   # 字体粗细
    'offset_x':0,          # X 方向,文字偏移距离,向右为正
    'offset_y':-80,        # Y 方向,文字偏移距离,向下为正
}

# 关键点 BGR 配色
kpt_color_map = {
    0:{'name':'Nose', 'color':[0, 0, 255], 'radius':10},                # 鼻尖
    1:{'name':'Right Eye', 'color':[255, 0, 0], 'radius':10},           # 右边眼睛
    2:{'name':'Left Eye', 'color':[255, 0, 0], 'radius':10},            # 左边眼睛
    3:{'name':'Right Ear', 'color':[0, 255, 0], 'radius':10},           # 右边耳朵
    4:{'name':'Left Ear', 'color':[0, 255, 0], 'radius':10},            # 左边耳朵
    5:{'name':'Right Shoulder', 'color':[193, 182, 255], 'radius':10},  # 右边肩膀
    6:{'name':'Left Shoulder', 'color':[193, 182, 255], 'radius':10},   # 左边肩膀
    7:{'name':'Right Elbow', 'color':[16, 144, 247], 'radius':10},      # 右侧胳膊肘
    8:{'name':'Left Elbow', 'color':[16, 144, 247], 'radius':10},       # 左侧胳膊肘
    9:{'name':'Right Wrist', 'color':[1, 240, 255], 'radius':10},       # 右侧手腕
    10:{'name':'Left Wrist', 'color':[1, 240, 255], 'radius':10},       # 左侧手腕
    11:{'name':'Right Hip', 'color':[140, 47, 240], 'radius':10},       # 右侧
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码叔2004

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值