Python | 人脸识别系统 — 姿态检测

博客汇总:Python | 人脸识别系统 — 博客索引

GitHub地址:Su-Face-Recognition

注:阅读本博客前请先参考

工具安装、环境配置:Python | 人脸识别系统 — 简介

UI界面设计:Python | 人脸识别系统 — UI界面设计

UI事件处理:Python | 人脸识别系统 — UI事件处理

摄像头画面展示:Python | 人脸识别系统 — 摄像头画面展示

一、判断器

        首先判断是否打开摄像头,打开则判断 self.isAttitudeDetection_flag 是否打开姿态检测。若否,则调用attitude_detection方法,进行背景模糊。

# 主界面
class UserMainWindow(QMainWindow, UserMainUi):

    def __init__(self, parent=None):
        super(UserMainWindow, self).__init__(parent)
        self.setupUi(self)

        self.show_image = None

        self.cap = cv2.VideoCapture()  # 相机
        self.source = CAPTURE_SOURCE  # 相机标号
        self.WIN_WIDTH = 800  # 相机展示画面宽度
        self.WIN_HEIGHT = 500  # 相机展示画面高度
        self.isAttitudeDetection_flag = False  # 是否打开姿态检测标志

    ... ...

    # 姿态检测判别器
    def criticalPoint_detection_judge(self):
        if not self.cap.isOpened():
            QMessageBox.information(self, "提示", self.tr("请先打开摄像头"))
        else:
            if not self.isAttitudeDetection_flag:
                self.isAttitudeDetection_flag = True
                self.attitude_detection_button.setText("关闭姿态检测")
                self.attitude_detection()
                self.attitude_detection_button.setText("姿态检测")
                self.isAttitudeDetection_flag = False

            elif self.isAttitudeDetection_flag:
                self.isAttitudeDetection_flag = False
                self.attitude_detection_button.setText("姿态检测")
                self.show_camera()

二、姿态检测

    # 姿态检测
    def attitude_detection(self):
        mp_pose = mp.solutions.pose  # 姿态识别方法
        pose = mp_pose.Pose(static_image_mode=False, smooth_landmarks=True,
                            min_detection_confidence=0.5, min_tracking_confidence=0.5)
        mp_draw = mp.solutions.drawing_utils
        while self.cap.isOpened():
            ret, frame = self.cap.read()
            QApplication.processEvents()
            imgRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            results = pose.process(imgRGB)
            if results.pose_landmarks:  # 如果检测到体态
                mp_draw.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)  # 绘制姿态坐标点

            show_video = cv2.cvtColor(cv2.resize(frame, (self.WIN_WIDTH, self.WIN_HEIGHT)), cv2.COLOR_BGR2RGB)
            self.show_image = QImage(show_video.data, show_video.shape[1], show_video.shape[0],
                                     QImage.Format_RGB888)
            self.camera_label.setPixmap(QPixmap.fromImage(self.show_image))

继续阅读:

摄像头画面展示:人脸识别系统-摄像头画面展示

用户端逻辑:

管理员端逻辑:

注:以上代码仅供参考,如需运行,参考GitHub源代码: Su-Face-Recognition

猜你喜欢

转载自blog.csdn.net/sun80760/article/details/130495193