import cv2
import numpy as np
import time
import PoseModule as pm
from PyQt5 import QtWidgets
from csdn import Ui_Form
from PyQt5.QtWidgets import QFileDialog
import cv2
import time
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QGraphicsPixmapItem
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
detector = pm.poseDetector()
class mywindow(QtWidgets.QWidget, Ui_Form):
def __init__(self):
super(mywindow, self).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.read_file)
self.pushButton_2.clicked.connect(self.read_voc)
self.pushButton_3.clicked.connect(self.stop_voc)
self.cap = []
self.timer_camera = QtCore.QTimer()
self.count= 0
self.dir = 0
self.pTime = 0
def read_file(self): # 选取文件
filename, filetype = QFileDialog.getOpenFileName(self, "选取文件", "./", "Images (*.png *.jpeg *.jpg)")
image = cv2.imread(filename)
image = image[:, :, ::-1].copy()
image = detector.findPose(image, False)
lmList = detector.findPosition(image, False)
if len(lmList) != 0:
# Right Arm
angle = detector.findAngle(image, 12, 14, 16)
height = image.shape[0]
width = image.shape[1]
frame = QImage(image, width, height, width * 3, QImage.Format_RGB888)
pix = QPixmap.fromImage(frame)
self.item = QGraphicsPixmapItem(pix)
self.scene = QGraphicsScene() # 创建场景
self.scene.addItem(self.item)
self.graphicsView.setScene(self.scene)
def read_voc(self): # 选取文件
videoName, _ = QFileDialog.getOpenFileName(self, "Open", "", "*.mp4;;*.avi;;All Files(*)")
self.cap = cv2.VideoCapture(videoName)
self.timer_camera.start(100)
self.timer_camera.timeout.connect(self.voc)
def voc(self):
if (self.cap.isOpened()):
ret, self.frame = self.cap.read()
if ret:
frame = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)
frame = cv2.resize(frame, (960, 576))
# frame = cv2.imread("AiTrainer/test.jpg")
frame = detector.findPose(frame, False)
lmList = detector.findPosition(frame, False)
# print(lmList)
if len(lmList) != 0:
# Right Arm
angle = detector.findAngle(frame, 12, 14, 16)
# # Left Arm
# angle = detector.findAngle(frame, 11, 13, 15)
# per = np.interp(angle, (210, 310), (0, 100))
per = np.interp(angle, (0, 180), (0, 100))
bar = np.interp(angle, (0, 180), (100, 550))
# bar = np.interp(angle, (210, 310), (650, 100))
# Check for the dumbbell curls
color = (255, 0, 255)
if per >= 80:
color = (0, 255, 0)
if self.dir == 0:
self.count += 0.5
self.dir = 1
if per <= 40:
color = (0, 255, 0)
if self.dir == 1:
self.count += 0.5
self.dir = 0
print(per, self.count)
# Draw Bar
cv2.rectangle(frame, (800, 100), (875, 550), color, 3)
cv2.rectangle(frame, (800, int(bar)), (875, 550), color, cv2.FILLED)
cv2.putText(frame, f'{int(100 - per)} %', (800, 75), cv2.FONT_HERSHEY_PLAIN, 4,
color, 4)
# Draw Curl Count
cv2.rectangle(frame, (0, 376), (250, 576), (0, 255, 0), cv2.FILLED)
cv2.putText(frame, str(int(self.count)), (45, 550), cv2.FONT_HERSHEY_PLAIN, 15,
(255, 0, 0), 25)
cTime = time.time()
fps = 1 / (cTime - self.pTime)
self.pTime = cTime
cv2.rectangle(frame, (0, 0), (200, 150), (0, 255, 0), cv2.FILLED)
cv2.putText(frame, str(int(fps)), (30, 100), cv2.FONT_HERSHEY_PLAIN, 8,
(255, 0, 0), 15)
height, width, bytesPerComponent = frame.shape
bytesPerLine = bytesPerComponent * width
q_image = QImage(frame.data, width, height, bytesPerLine, QImage.Format_RGB888)
pix = QPixmap.fromImage(q_image)
self.item = QGraphicsPixmapItem(pix)
self.scene = QGraphicsScene() # 创建场景
self.scene.addItem(self.item)
self.graphicsView.setScene(self.scene)
else:
self.cap.release()
self.timer_camera.stop() # 停止计时器
def stop_voc(self):
if self.cap != []:
self.cap.release()
self.count= 0
self.dir = 0
self.pTime = 0
self.timer_camera.stop() # 停止计时器
#################################################################
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ui = mywindow()
ui.show()
sys.exit(app.exec_())
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
pyqt5+AI健身+mediapipe 可视化界面opencv实现人体关键点检测,AI健身计数等功能。详细:https://blog.csdn.net/qq_34717531/article/details/124670291?spm=1001.2014.3001.5502。使用OpenCV+mediapipe的BlazePose以及前端界面的Qt Designer+Pyqt5实现的一个基于人体姿态识别的AI健身系统,可以实现选择打开图片文件或者是视频文件,具有视频的关闭播放和更换视频播放等功能。视频可以在CPU下实时检测。 注: 1.中间数字为角度。采用的是12,14,16,可自由更改。 2.左上角为fps,左下角为次数统计。 3.关闭视频后再打开视频,检测速度有明显提升,已发现原因。 将self.timer_camera.start()里的100去掉即可全部流畅运行。
资源推荐
资源详情
资源评论






















收起资源包目录









共 7 条
- 1

学术菜鸟小晨
- 粉丝: 2w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 高中数学《算法案例》-北师大版必修3.ppt
- 钱江电子商务园脚手架方案样本.doc
- 2023年江苏中小学教师心理健康网络知识竞赛.doc
- 信息安全等级测评师培训之应用系统安全测评.pptx
- 中北大学软件学院毕业设计中期报告.doc
- 绿宝企业门户网站概要设计报告.doc
- 计算机网络技术考试题C卷.docx
- 2023年3月计算机等级考试二级C语言笔试试题及答案.doc
- 小网站的网站广告投放策略..pdf
- 潍坊市公路局公路养护工程项目管理中的人力资源优化配置.docx
- 搜索引擎模式案例分析资料PPT课件.ppt
- 互联网-+-教育-.docx
- 综合布线工程全套竣工资料表格.doc
- 硬件系统安全和环境安全.ppt
- 顺序逻辑控制的PLC程序设计ppt课件.ppt
- 基于单片机的数字万用表的设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
- 4
前往页