便捷网站建设价格重庆网站推广联系方式
本博客为人脸识别系统的姿态检测代码解释
人脸识别系统博客汇总:人脸识别系统-博客索引
项目GitHub地址:Su-Face-Recognition: A face recognition for user logining
注意:阅读本博客前请先参考以下博客
工具安装、环境配置:人脸识别系统-简介
UI界面设计:人脸识别系统-UI界面设计
UI事件处理:人脸识别系统-UI事件处理
摄像头展示画面:人脸识别系统-摄像头画面展示
阅读完本博客后可以继续阅读:
摄像头画面展示:人脸识别系统-摄像头画面展示
用户端逻辑:
- 人脸识别:Python | 人脸识别系统 — 人脸识别
- 活体检测:Python | 人脸识别系统 — 活体检测
- 背景模糊:Python | 人脸识别系统 — 背景模糊
- 姿态检测:Python | 人脸识别系统 — 姿态检测
- 人脸比对:Python | 人脸识别系统 — 人脸比对
- 用户操作: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 = Noneself.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 = Trueself.attitude_detection_button.setText("关闭姿态检测")self.attitude_detection()self.attitude_detection_button.setText("姿态检测")self.isAttitudeDetection_flag = Falseelif self.isAttitudeDetection_flag:self.isAttitudeDetection_flag = Falseself.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_utilswhile 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))
阅读完本博客后可以继续阅读:
摄像头画面展示:人脸识别系统-摄像头画面展示
用户端逻辑:
- 人脸识别:Python | 人脸识别系统 — 人脸识别
- 活体检测:Python | 人脸识别系统 — 活体检测
- 背景模糊:Python | 人脸识别系统 — 背景模糊
- 姿态检测:Python | 人脸识别系统 — 姿态检测
- 人脸比对:Python | 人脸识别系统 — 人脸比对
- 用户操作:Python | 人脸识别系统 — 用户操作
管理员端逻辑:
- 管理员操作:
- 用户操作:
注:以上代码仅为参考,若需要运行,请参考项目GitHub完整源代码:Su-Face-Recognition: A face recognition for user logining