def show_camera(self):
        start = time.time()
        ret, frame = self.cap.read()

        if ret:
            if self.__flag_mode == 1:
                self.infoBox.setText(u'当前为人体姿态估计模式')
                humans = estimator.inference(frame)  # 返回heatMat pafMat空间地址
                # get pose info
                # return frame, joints, bboxes, xcenter
                pose = TfPoseVisualizer.draw_pose_rgb(frame, humans)  # pose绘制在画面上了
                # recognize the action framewise
                show = framewise_recognize(pose, action_classifier)  # 返回绘制好的frame

            # elif self.__flag_mode == 2:
            #     self.infoBox.setText(u'当前为多人跟踪模式')
            #     humans = poseEstimator.inference(show)
            #     show, joints, bboxes, xcenter, sk = TfPoseEstimator.get_skeleton(show, humans, imgcopy=False)
            #     height = show.shape[0]
            #     width = show.shape[1]
            #     if bboxes:
            #         result = np.array(bboxes)
            #         det = result[:, 0:5]
            #         det[:, 0] = det[:, 0] * width
            #         det[:, 1] = det[:, 1] * height
            #         det[:, 2] = det[:, 2] * width
            #         det[:, 3] = det[:, 3] * height
            #         trackers = self.tracker.update(det)
            #
            #         for d in trackers:
            #             xmin = int(d[0])
            #             ymin = int(d[1])
            #             xmax = int(d[2])
            #             ymax = int(d[3])
            #             label = int(d[4])
            #             cv2.rectangle(show, (xmin, ymin), (xmax, ymax),
            #                           (int(settings.c[label % 32, 0]),
            #                            int(settings.c[label % 32, 1]),
            #                            int(settings.c[label % 32, 2])), 4)
            #
            # elif self.__flag_mode == 3:
            #     self.infoBox.setText(u'当前为人体行为识别模式')
            #     humans = poseEstimator.inference(show)
            #     ori = np.copy(show)
            #     show, joints, bboxes, xcenter, sk= TfPoseEstimator.get_skeleton(show, humans, imgcopy=False)
            #     height = show.shape[0]
            #     width = show.shape[1]
            #     if bboxes:
            #         result = np.array(bboxes)
            #         det = result[:, 0:5]
            #         det[:, 0] = det[:, 0] * width
            #         det[:, 1] = det[:, 1] * height
            #         det[:, 2] = det[:, 2] * width
            #         det[:, 3] = det[:, 3] * height
            #         trackers = self.tracker.update(det)
            #         self.current = [i[-1] for i in trackers]
            #
            #         if len(self.previous) > 0:
            #             for item in self.previous:
            #                 if item not in self.current and item in self.data:
            #                     del self.data[item]
            #                 if item not in self.current and item in self.memory:
            #                     del self.memory[item]
            #
            #         self.previous = self.current
            #         for d in trackers:
            #             xmin = int(d[0])
            #             ymin = int(d[1])
            #             xmax = int(d[2])
            #             ymax = int(d[3])
            #             label = int(d[4])
            #             try:
            #                 j = np.argmin(np.array([abs(i - (xmax + xmin) / 2.) for i in xcenter]))
            #             except:
            #                 j = 0
            #             if joint_filter(joints[j]):
            #                 joints[j] = joint_completion(joint_completion(joints[j]))
            #                 if label not in self.data:
            #                     self.data[label] = [joints[j]]
            #                     self.memory[label] = 0
            #                 else:
            #                     self.data[label].append(joints[j])
            #
            #                 if len(self.data[label]) == settings.L:
            #                     pred = actionPredictor().move_status(self.data[label])
            #                     if pred == 0:
            #                         pred = self.memory[label]
            #                     else:
            #                         self.memory[label] = pred
            #                     self.data[label].pop(0)
            #
            #                     location = self.data[label][-1][1]
            #                     if location[0] <= 30:
            #                         location = (51, location[1])
            #                     if location[1] <= 10:
            #                         location = (location[0], 31)
            #
            #                     cv2.putText(show, settings.move_status[pred], (location[0] - 30, location[1] - 10),
            #                                 cv2.FONT_HERSHEY_SIMPLEX, 0.8,
            #                                 (0, 255, 0), 2)
            #
            #             cv2.rectangle(show, (xmin, ymin), (xmax, ymax),
            #                           (int(settings.c[label % 32, 0]),
            #                            int(settings.c[label % 32, 1]),
            #                            int(settings.c[label % 32, 2])), 4)
            #
            show = cv.resize(frame, (settings.winWidth, settings.winHeight))
            show = cv.cvtColor(show, cv.COLOR_BGR2RGB)
            end = time.time()
            self.fps = 1. / (end - start)
            cv.putText(show, 'FPS: %.2f' % self.fps, (30, 30), cv.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
            showImage = QtGui.QImage(show.data, show.shape[1], show.shape[0], QtGui.QImage.Format_RGB888)
            self.label_show_camera.setPixmap(QtGui.QPixmap.fromImage(showImage))
        else:
            self.cap.release()
            self.timer_camera.stop()
if not args.type:
    print('请输入具体采集的动作类型:-<')
else:
    while cv.waitKey(1) < 0:
        has_frame, show = cap.read()
        if has_frame:
            fps_count += 1
            frame_count += 1

            # pose estimation
            humans = estimator.inference(show)
            # get pose info
            pose = TfPoseVisualizer.draw_pose_rgb(
                show, humans)  # return frame, joints, bboxes, xcenter
            # recognize the action framewise
            show = framewise_recognize(pose, action_classifier)

            height, width = show.shape[:2]
            # 显示实时FPS值
            if (time.time() - start_time) > fps_interval:
                # 计算这个interval过程中的帧数,若interval为1秒,则为FPS
                realtime_fps = fps_count / (time.time() - start_time)
                fps_count = 0  # 帧数清零
                start_time = time.time()
            fps_label = 'FPS:{0:.2f}'.format(realtime_fps)
            cv.putText(show, fps_label, (width - 160, 25),
                       cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)

            # 显示检测到的人数
            num_label = "Human: {0}".format(len(humans))
            cv.putText(show, num_label, (5, height - 45),
    #print("DEBUG:stage 3")
    if has_frame:
        fps_count += 1
        frame_count += 1

        # 灰度图像转为RGB图像
        show = cv.cvtColor(show, cv.COLOR_GRAY2RGB)
        # 姿势识别,human存储着标记好骨骼的数据(以图像的相对位置表示)
        humans = estimator.inference(show)
        # get pose info,pose中存储着绘制好关键节点的姿势数据,主要目的是计算出关节的实际坐标位置,绘制骨骼,并返回整理完后的数据
        pose = TfPoseVisualizer.draw_pose_rgb(
            show,
            humans,
        )  # return frame, joints, bboxes, xcenter
        # recognize the action framewise
        show = framewise_recognize(pose, action_classifier, cap_Receptor)

        height, width = show.shape[:2]
        # 显示实时FPS值
        if (time.time() - start_time) > fps_interval:
            # 计算这个interval过程中的帧数,若interval为1秒,则为FPS
            realtime_fps = fps_count / (time.time() - start_time)
            fps_count = 0  # 帧数清零
            start_time = time.time()
        fps_label = 'FPS:{0:.2f}'.format(realtime_fps)
        cv.putText(show, fps_label, (width - 160, 25), cv.FONT_HERSHEY_SIMPLEX,
                   1, (0, 0, 255), 3)

        # 显示检测到的人数
        num_label = "Human: {0}".format(len(humans))
        cv.putText(show, num_label, (5, height - 45), cv.FONT_HERSHEY_SIMPLEX,
Esempio n. 4
0
        # pose estimation
        humans = estimator.inference(show)
        # get pose info
        pose = TfPoseVisualizer.draw_pose_rgb(show, humans)  # return frame, joints, bboxes, xcenter.

        if(pose[-1] != []):
            seq_data.append(pose)
            if len(seq_data) == 10:
               input_seq_data = seq_data
        
        #     print("################################ Make input data ################################")
        # # print("################################ check ################################ ")

        # recognize the action framewise
        show = framewise_recognize(pose, action_classifier,input_seq_data)
        if len(seq_data) == 10:
            input_seq_data, seq_data = [], []

        height, width = show.shape[:2]
        # 실시간 FPS 값 표시
        if (time.time() - start_time) > fps_interval:
            # 이 interval 프로세스에서 프레임 수를 계산하고 interval이 1초이면 FPS
            realtime_fps = fps_count / (time.time() - start_time)
            fps_count = 0  # 프레임 수가 매우 적다.
            start_time = time.time()
        # fps_label = 'FPS:{0:.2f}'.format(realtime_fps)
        # cv.putText(show, fps_label, (width-160, 25), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)

        # 사람의 수를 표시
        num_label = "Human: {0}".format(len(humans))
Esempio n. 5
0
    frame = imutils.resize(frame, width=400)

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_detection.detectMultiScale(gray,
                                            scaleFactor=1.2,
                                            minNeighbors=5,
                                            minSize=(30, 30),
                                            flags=cv2.CASCADE_SCALE_IMAGE)

    canvas = np.zeros((250, 300, 3), dtype="uint8")
    frameClone = frame.copy()

    #pose
    humans = estimator.inference(frameClone)
    pose = TfPoseVisualizer.draw_pose_rgb(frameClone, humans)
    frameClone = framewise_recognize(pose, action_classifier)
    height, width = frameClone.shape[:2]

    if len(faces) > 0:
        faces = sorted(faces,
                       reverse=True,
                       key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
        (fX, fY, fW, fH) = faces
        # Extract the ROI of the face from the grayscale image, resize it to a fixed 48x48 pixels, and then prepare
        # the ROI for classification via the CNN
        roi = gray[fY:fY + fH, fX:fX + fW]
        roi = cv2.resize(roi, (48, 48))
        roi = roi.astype("float") / 255.0
        roi = img_to_array(roi)
        roi = np.expand_dims(roi, axis=0)