基于深度学习的人体关键点检测与姿态识别

文章目录

源码下载地址:
源码地址在视频简介中

深度学习人体关键点检测,姿态识别

界面效果:

界面代码:

python 复制代码
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from untitled import Ui_Form
import sys
import cv2 as cv
from PyQt5.QtCore import QCoreApplication
import numpy as np
from PyQt5 import QtCore,QtGui
from PIL import Image
from predicts import pp
import time
from PyQt5 import QtWidgets
import cv2
class My(QMainWindow,Ui_Form):
    def __init__(self):
        super(My,self).__init__()
        self.setupUi(self)
        self.setWindowTitle('人体姿态识别')
        self.use_palette()

        self.pushButton.clicked.connect(self.pic)

        self.pushButton_2.clicked.connect(self.pre)
        self.pushButton_3.clicked.connect(self.video)

        self._timer = QTimer(self)
        self._timer.timeout.connect(self.play)

    def video(self):
        self._timer.stop()
        v, videoType = QFileDialog.getOpenFileName(self,
                                                   "打开视频",
                                                   "",
                                                   " *.mp4;;*.avi;;All Files (*)")

        if v=='':
            return
        self.ved = cv2.VideoCapture(v)
        qq = self.ved.isOpened()
        if qq == False:
            msg_box = QMessageBox(QMessageBox.Warning, 'Warning', '请选择视频!')
            msg_box.exec_()
            return
        self._timer.stop()
        self._timer.start(1)
    def play(self):
        try:
            r, frame = self.ved.read()
            orial=self.cv_qt(frame)
            self.label.setPixmap(
                QPixmap.fromImage(orial).scaled(self.label.width(), self.label.height(), QtCore.Qt.KeepAspectRatio))


            self.out, zt = pp(frame)
            out = self.cv_qt(self.out)
            self.label_2.setPixmap(
                QPixmap.fromImage(out).scaled(self.label.width(), self.label.height(), QtCore.Qt.KeepAspectRatio))
            self.label_4.setText(zt)
        except:
            self._timer.stop()


    def pre(self):
        self._timer.stop()

        self.out,zt=pp(self.img[...,::-1])
        out=self.cv_qt(self.out)
        self.label_2.setPixmap(QPixmap.fromImage(out).scaled(self.label.width(),self.label.height(),QtCore.Qt.KeepAspectRatio))
        self.label_4.setText(zt)
    def pic(self):
        self._timer.stop()
        imgName, imgType = QFileDialog.getOpenFileName(self,
                                                       "打开图片",
                                                       "",
                                                       " *.png;;*.jpg;;*.jpeg;;*.bmp;;All Files (*)")
        if imgName=='':
            return
        #KeepAspectRatio
        png = QtGui.QPixmap(imgName).scaled(self.label.width(),self.label.height(),QtCore.Qt.KeepAspectRatio)  # 适应设计label时的大小
        self.label.setPixmap(png)

        self.img=Image.open(imgName)
        self.img=np.array(self.img)[...,:3]
    def cv_qt(self, src):
        #src必须为bgr格式图像
        #src必须为bgr格式图像
        #src必须为bgr格式图像
        if len(src.shape)==2:
            src=np.expand_dims(src,axis=-1)
            src=np.tile(src,(1,1,3))
            h, w, d = src.shape
        else:h, w, d = src.shape



        bytesperline = d * w
        # self.src=cv.cvtColor(self.src,cv.COLOR_BGR2RGB)
        qt_image = QImage(src.data, w, h, bytesperline, QImage.Format_RGB888).rgbSwapped()
        return qt_image
    #设置背景图片函数
    def use_palette(self):
        self.setWindowTitle("人体姿态识别")
        window_pale = QtGui.QPalette()
        window_pale.setBrush(self.backgroundRole(),
                             QtGui.QBrush(QtGui.QPixmap(r"./back.jpg")))
        self.setPalette(window_pale)


if __name__ == '__main__':
    QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app=QApplication(sys.argv)
    my=My()
    my.show()
    sys.exit(app.exec_())
相关推荐
千宇宙航3 小时前
闲庭信步使用SV搭建图像测试平台:第三十一课——基于神经网络的手写数字识别
图像处理·人工智能·深度学习·神经网络·计算机视觉·fpga开发
onceco3 小时前
领域LLM九讲——第5讲 为什么选择OpenManus而不是QwenAgent(附LLM免费api邀请码)
人工智能·python·深度学习·语言模型·自然语言处理·自动化
天水幼麟4 小时前
动手学深度学习-学习笔记(总)
笔记·深度学习·学习
jndingxin6 小时前
OpenCV CUDA模块设备层-----高效地计算两个 uint 类型值的带权重平均值
人工智能·opencv·计算机视觉
天水幼麟6 小时前
动手学深度学习-学习笔记【二】(基础知识)
笔记·深度学习·学习
Sweet锦6 小时前
零基础保姆级本地化部署文心大模型4.5开源系列
人工智能·语言模型·文心一言
hie988947 小时前
MATLAB锂离子电池伪二维(P2D)模型实现
人工智能·算法·matlab
晨同学03277 小时前
opencv的颜色通道问题 & rgb & bgr
人工智能·opencv·计算机视觉
蓝婷儿7 小时前
Python 机器学习核心入门与实战进阶 Day 3 - 决策树 & 随机森林模型实战
人工智能·python·机器学习
大千AI助手7 小时前
PageRank:互联网的马尔可夫链平衡态
人工智能·机器学习·贝叶斯·mc·pagerank·条件概率·马尔科夫链