mediapipe系列之一肢体行为标记

基于mediapipe进行的肢体行为标记

采用方法

主要使用google 的 mediapipe 工具包中的pose模块和opencv中的显示标识模块

使用事项

文中的1.flv 可以换成其他格式的视频,只要有肢体存在。

代码如下

"""
基础环境 python3
安装包   pip install opencv-python mediapipe
"""
import cv2
import mediapipe as mp
import time

class poseDetector():
    def __init__(self, mode=False, model=2, smooth=True, detection=0.5, tracking=0.5):
        self.mode = mode
        self.model = model
        self.smooth = smooth
        self.detection = detection
        self.tracking = tracking

        self.mpPose = mp.solutions.pose
        self.poses = self.mpPose.Pose(self.mode, self.model,self.smooth,self.detection, self.tracking)
        self.mpDraw = mp.solutions.drawing_utils

    def findPose(self, img, draw=True):
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        self.results = self.poses.process(imgRGB)
        print(self.results.pose_landmarks)
        if self.results.pose_landmarks:
            if draw:
                self.mpDraw.draw_landmarks(img, self.results.pose_landmarks, self.mpPose.POSE_CONNECTIONS)
        return img

    def findPosition(self, img,draw=True):
        lmList = []
        if self.results.pose_landmarks:
            myPose = self.results.pose_landmarks.landmark
            for id, lm in enumerate(myPose):
                h, w, c = img.shape
                cx, cy = int(lm.x * w), int(lm.y * h)
                lmList.append((id, cx, cy))
                if draw:
                    cv2.circle(img, (cx, cy), 10, (255, 0, 255), cv2.FILLED)
        return lmList

def main():
    pTime = 0
    cap = cv2.VideoCapture('1.flv')
    detector = poseDetector()
    while True:
        success, img = cap.read()
        img = detector.findPose(img)
        lmList = detector.findPosition(img)
        if len(lmList) != 0:
            # print(lmList)
            pass
        cTime = time.time()
        fps = 1 / (cTime - pTime)
        pTime = cTime
        cv2.putText(img, f"fps:{int(fps)}", (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)
        cv2.imshow('Image', img)
        cv2.waitKey(1)
if __name__ == '__main__':
    main()
【资源说明】 毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip毕业设计基于mediapipe实现的动作识别python源码.zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

武念

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

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

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

打赏作者

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

抵扣说明:

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

余额充值