Esempio n. 1
0
 def __init__(self, show_img=True):
     self.pose_estimator = PoseEstimator()
     self.object_detector = ObjectDetectionYolo()
     self.img = []
     self.img_black = []
     self.show_img = show_img
     self.BBV = BBoxVisualizer()
Esempio n. 2
0
 def __init__(self, show_img=True):
     self.pose_estimator = PoseEstimator()
     self.object_detector = ObjectDetectionYolo()
     self.object_tracker = ObjectTracker()
     self.BBV = BBoxVisualizer()
     self.KPV = KeyPointVisualizer()
     self.IDV = IDVisualizer(with_bbox=False)
     self.img = []
     self.img_black = []
     self.show_img = show_img
 def __init__(self, show_img=True):
     self.object_detector = ObjectDetectionYolo(cfg=opt.yolo_cfg, weight=opt.yolo_weight)
     self.object_tracker = ObjectTracker()
     self.BBV = BBoxVisualizer()
     self.IDV = IDVisualizer(with_bbox=False)
     self.boxes = tensor([])
     self.boxes_scores = tensor([])
     self.img_black = np.array([])
     self.frame = np.array([])
     self.id2bbox = {}
     self.show_img = show_img
     self.CNN_model = CNNInference()
Esempio n. 4
0
 def __init__(self, show_img=True):
     self.object_detector = ObjectDetectionYolo(cfg=yolo_cfg, weight=yolo_weight)
     self.object_tracker = ObjectTracker()
     self.pose_estimator = PoseEstimator(pose_cfg=pose_cfg, pose_weight=pose_weight)
     self.BBV = BBoxVisualizer()
     self.KPV = KeyPointVisualizer()
     self.IDV = IDVisualizer(with_bbox=False)
     self.boxes = tensor([])
     self.boxes_scores = tensor([])
     self.img_black = np.array([])
     self.frame = np.array([])
     self.id2bbox = {}
     self.kps = {}
     self.kps_score = {}
     self.show_img = show_img
 def __init__(self, resize_size, show_img=True):
     self.object_detector = ObjectDetectionYolo(cfg=config.yolo_cfg, weight=config.yolo_weight)
     self.object_tracker = ObjectTracker()
     self.pose_estimator = PoseEstimator(pose_cfg=config.pose_cfg, pose_weight=config.pose_weight)
     self.BBV = BBoxVisualizer()
     self.KPV = KeyPointVisualizer()
     self.IDV = IDVisualizer()
     self.boxes = tensor([])
     self.boxes_scores = tensor([])
     self.frame = np.array([])
     self.id2bbox = {}
     self.CNN_model = CNNInference()
     self.kps = {}
     self.kps_score = {}
     self.show_img = show_img
     self.resize_size = resize_size
Esempio n. 6
0
 def __init__(self, path=config.video_path, show_img=True):
     self.pose_estimator = PoseEstimator()
     self.object_detector = ObjectDetectionYolo()
     self.BBV = BBoxVisualizer()
     self.IDV = IDVisualizer()
     self.object_tracker = ObjectTracker()
     self.video_path = path
     self.cap = cv2.VideoCapture(self.video_path)
     self.img = []
     self.img_black = []
     self.show_img = show_img
     self.locator = Locator([1, 2])
Esempio n. 7
0
class ImgProcessorForbbox:
    def __init__(self):
        self.object_detector = ObjectDetectionYolo()
        self.img = []
        self.img_black = []
        self.BBV = BBoxVisualizer()

    def process_img(self, frame, enhanced=None):
        with torch.no_grad():
            inps, orig_img, boxes, scores, pt1, pt2 = self.object_detector.process(
                frame)
            try:
                img = self.BBV.visualize(boxes, frame)
                return img
            except:
                return frame
Esempio n. 8
0
class ImgProcessor:
    def __init__(self, show_img=True):
        self.pose_estimator = PoseEstimator()
        self.object_detector = ObjectDetectionYolo()
        self.img = []
        self.img_black = []
        self.show_img = show_img
        self.BBV = BBoxVisualizer()

    def process_img(self, frame):
        with torch.no_grad():
            inps, orig_img, boxes, scores, pt1, pt2 = self.object_detector.process(
                frame)
            if boxes is not None:
                key_points, img, img_black = self.pose_estimator.process_img(
                    inps, orig_img, boxes, scores, pt1, pt2)

                img = self.BBV.visualize(boxes, img)
                return key_points, img, img_black
            else:
                return [], frame, cv2.imread("video/black.jpg")
Esempio n. 9
0
class ImgProcessor:
    def __init__(self, show_img=True):
        self.pose_estimator = PoseEstimator()
        self.object_detector = ObjectDetectionYolo()
        self.object_tracker = ObjectTracker()
        self.BBV = BBoxVisualizer()
        self.KPV = KeyPointVisualizer()
        self.IDV = IDVisualizer(with_bbox=False)
        self.img = []
        self.img_black = []
        self.show_img = show_img

    def init_sort(self):
        self.object_tracker.init_tracker()

    def __process_kp(self, kps, idx):
        new_kp = []
        for bdp in range(len(kps)):
            for coord in range(2):
                new_kp.append(kps[bdp][coord])
        return {idx: new_kp}

    def process_img(self, frame):
        # frame = cv2.resize(frame, config.frame_size)
        img = copy.deepcopy(frame)
        img_black = cv2.imread('video/black.jpg')
        with torch.no_grad():
            inps, orig_img, boxes, scores, pt1, pt2 = self.object_detector.process(
                frame)

            if boxes is not None:
                key_points, img, black_img = self.pose_estimator.process_img(
                    inps, orig_img, boxes, scores, pt1, pt2)
                if config.plot_bbox:
                    img = self.BBV.visualize(boxes, frame)

                if key_points is not []:
                    id2ske, id2bbox = self.object_tracker.track(
                        boxes, key_points)
                    if config.plot_id:
                        img = self.IDV.plot_bbox_id(id2bbox,
                                                    copy.deepcopy(img))
                        # img = self.IDV.plot_skeleton_id(id2ske, copy.deepcopy(img))

                    if config.track_idx != "all":
                        try:
                            kps = self.__process_kp(id2ske[config.track_idx],
                                                    config.track_idx)
                        except KeyError:
                            kps = {}
                    else:
                        kps = id2ske
                    #
                    # if config.plot_kps:
                    #     vis_kps = self.KPV.dict2ls(kps)
                    #     img = self.KPV.vis_ske(orig_img, vis_kps, kp_score)
                    #     img_black = self.KPV.vis_ske_black(orig_img, vis_kps, kp_score)

                    return kps, img, img_black
                else:
                    return {}, img, img_black
            else:
                return {}, frame, frame
Esempio n. 10
0
 def __init__(self):
     self.object_detector = ObjectDetectionYolo()
     self.img = []
     self.img_black = []
     self.BBV = BBoxVisualizer()
class HumanDetection:
    def __init__(self, show_img=True):
        self.object_detector = ObjectDetectionYolo(cfg=opt.yolo_cfg, weight=opt.yolo_weight)
        self.object_tracker = ObjectTracker()
        self.BBV = BBoxVisualizer()
        self.IDV = IDVisualizer(with_bbox=False)
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.img_black = np.array([])
        self.frame = np.array([])
        self.id2bbox = {}
        self.show_img = show_img
        self.CNN_model = CNNInference()

    def init_sort(self):
        self.object_tracker.init_tracker()

    def clear_res(self):
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.img_black = np.array([])
        self.frame = np.array([])
        self.id2bbox = {}

    def visualize(self):
        self.img_black = cv2.imread('video/black.jpg')
        if config.plot_bbox and self.boxes is not None:
            self.frame = self.BBV.visualize(self.boxes, self.frame, self.boxes_scores)
            # cv2.imshow("cropped", (torch_to_im(inps[0]) * 255))
        if config.plot_id and self.id2bbox is not None:
            self.frame = self.IDV.plot_bbox_id(self.id2bbox, self.frame)
            # frame = self.IDV.plot_skeleton_id(id2ske, copy.deepcopy(img))
        return self.frame, self.img_black

    def process_img(self, frame, gray=False):
        self.clear_res()
        self.frame = frame

        with torch.no_grad():
            if gray:
                gray_img = gray3D(copy.deepcopy(frame))
                box_res = self.object_detector.process(gray_img)
            else:
                box_res = self.object_detector.process(frame)
            self.boxes, self.boxes_scores = self.object_detector.cut_box_score(box_res)

            if box_res is not None:
                self.id2bbox = self.object_tracker.track(box_res)

        return self.id2bbox

    def classify_whole(self):
        out = self.CNN_model.predict(self.img_black)
        idx = out[0].tolist().index(max(out[0].tolist()))
        pred = opt.CNN_class[idx]
        print("The prediction is {}".format(pred))

    def classify(self, frame):
        for box in self.id2bbox.values():
            x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
            x1 = 0 if x1 < 0 else x1
            y1 = 0 if y1 < 0 else y1
            x2 = frame.shape[1] if x2 > frame.shape[1] else x2
            y2 = frame.shape[0] if y2 > frame.shape[0] else y2
            img = np.asarray(frame[y1:y2, x1:x2])
            # cv2.imshow("cut", img)
            # cv2.imwrite("img/tmp/0.jpg", img)
            out = self.CNN_model.predict(img)
            idx = out[0].tolist().index(max(out[0].tolist()))
            pred = opt.CNN_class[idx]
            print(pred)
            text_location = (int((box[0]+box[2])/2)), int((box[1])+50)
            cv2.putText(frame, pred, text_location, cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 255), 2)
Esempio n. 12
0
class HumanDetection:
    def __init__(self, resize_size, show_img=True):
        self.object_detector = ObjectDetectionYolo(cfg=config.yolo_cfg, weight=config.yolo_weight)
        self.object_tracker = ObjectTracker()
        self.pose_estimator = PoseEstimator(pose_cfg=config.pose_cfg, pose_weight=config.pose_weight)
        self.BBV = BBoxVisualizer()
        self.KPV = KeyPointVisualizer()
        self.IDV = IDVisualizer()
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.frame = np.array([])
        self.id2bbox = {}
        self.CNN_model = CNNInference()
        self.kps = {}
        self.kps_score = {}
        self.show_img = show_img
        self.resize_size = resize_size

    def init(self):
        self.object_tracker.init_tracker()

    def clear_res(self):
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.frame = np.array([])
        self.id2bbox = {}
        self.kps = {}
        self.kps_score = {}

    def visualize(self):
        img_black = np.full((self.resize_size[1], self.resize_size[0], 3), 0).astype(np.uint8)
        if config.plot_bbox and self.boxes is not None:
            self.BBV.visualize(self.boxes, self.frame)
        if config.plot_kps and self.kps is not []:
            self.KPV.vis_ske(self.frame, self.kps, self.kps_score)
            self.KPV.vis_ske_black(img_black, self.kps, self.kps_score)
        if config.plot_id and self.id2bbox is not None:
            self.IDV.plot_bbox_id(self.id2bbox, self.frame)
            self.IDV.plot_skeleton_id(self.kps, self.frame)
        return self.frame, img_black

    def process_img(self, frame, gray=False):
        self.clear_res()
        self.frame = frame

        with torch.no_grad():
            if gray:
                gray_img = gray3D(copy.deepcopy(frame))
                box_res = self.object_detector.process(gray_img)
            else:
                box_res = self.object_detector.process(frame)
            self.boxes, self.boxes_scores = self.object_detector.cut_box_score(box_res)

            if box_res is not None:
                self.id2bbox = self.object_tracker.track(box_res)
                self.id2bbox = eliminate_nan(self.id2bbox)
                boxes = self.object_tracker.id_and_box(self.id2bbox)

                inps, pt1, pt2 = crop_bbox(frame, boxes)
                if inps is not None:
                    kps, kps_score, kps_id = self.pose_estimator.process_img(inps, boxes, pt1, pt2)
                    self.kps, self.kps_score = self.object_tracker.match_kps(kps_id, kps, kps_score)

        return self.kps, self.id2bbox, self.kps_score

    def classify_whole(self, pred_img, show_img):
        pred = self.CNN_model.classify_whole(pred_img, show_img)
        return pred

    def classify(self, pred_img, show_img, id2bbox):
        preds = self.CNN_model.classify(pred_img, id2bbox)
        self.CNN_model.visualize(show_img, preds)
        return preds
Esempio n. 13
0
class HumanDetection:
    def __init__(self, show_img=True):
        self.object_detector = ObjectDetectionYolo(cfg=yolo_cfg, weight=yolo_weight)
        self.object_tracker = ObjectTracker()
        self.pose_estimator = PoseEstimator(pose_cfg=pose_cfg, pose_weight=pose_weight)
        self.BBV = BBoxVisualizer()
        self.KPV = KeyPointVisualizer()
        self.IDV = IDVisualizer(with_bbox=False)
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.img_black = np.array([])
        self.frame = np.array([])
        self.id2bbox = {}
        self.kps = {}
        self.kps_score = {}
        self.show_img = show_img

    def init_sort(self):
        self.object_tracker.init_tracker()

    def clear_res(self):
        self.boxes = tensor([])
        self.boxes_scores = tensor([])
        self.frame = np.array([])
        self.id2bbox = {}
        self.kps = {}
        self.kps_score = {}

    def visualize(self):
        img_black = cv2.imread('video/black.jpg')
        if config.plot_bbox and self.boxes is not None:
            self.frame = self.BBV.visualize(self.boxes, self.frame, self.boxes_scores)
            # cv2.imshow("cropped", (torch_to_im(inps[0]) * 255))
        if config.plot_kps and self.kps is not []:
            self.frame = self.KPV.vis_ske(self.frame, self.kps, self.kps_score)
            img_black = self.KPV.vis_ske_black(self.frame, self.kps, self.kps_score)
        if config.plot_id and self.id2bbox is not None:
            self.frame = self.IDV.plot_bbox_id(self.id2bbox, self.frame)
            # frame = self.IDV.plot_skeleton_id(id2ske, copy.deepcopy(img))
        return self.frame, img_black

    def process_img(self, frame, gray=False):
        self.clear_res()
        self.frame = frame

        with torch.no_grad():
            if gray:
                gray_img = gray3D(copy.deepcopy(frame))
                box_res = self.object_detector.process(gray_img)
            else:
                box_res = self.object_detector.process(frame)
            self.boxes, self.boxes_scores = self.object_detector.cut_box_score(box_res)

            if box_res is not None:
                self.id2bbox = self.object_tracker.track(box_res)
                boxes = self.object_tracker.id_and_box(self.id2bbox)

                inps, pt1, pt2 = crop_bbox(frame, boxes)
                kps, kps_score, kps_id = self.pose_estimator.process_img(inps, boxes, pt1, pt2)
                self.kps, self.kps_score = self.object_tracker.match_kps(kps_id, kps, kps_score)

        return self.kps, self.id2bbox, self.kps_score