Exemplo n.º 1
0
    def __call__(self, img):
        if img is None:
            return None
        (height, width, channel) = img.shape
        preds = self.predict(img)

        detections = []
        for *xyxy, conf, cls in reversed(preds):
            xyxy[0] = int(xyxy[0].to('cpu').detach().numpy().copy())
            xyxy[1] = int(xyxy[1].to('cpu').detach().numpy().copy())
            xyxy[2] = int(xyxy[2].to('cpu').detach().numpy().copy())
            xyxy[3] = int(xyxy[3].to('cpu').detach().numpy().copy())
            conf = conf.to('cpu').detach().numpy()
            label = f'{self.names[int(cls)]}'
            list = {
                'bbox': xyxy,
                'rbbox': bbox_to_rbbox(xyxy, img),
                'label': int(cls),
                'label_name': f'{self.names[int(cls)]}',
                'prob': conf,
                'color': self.colors[int(cls)]
            }
            detections.append(list)

        #print('detections :{}'.format(detections))
        return [detections]
Exemplo n.º 2
0
    def update_target_detection_with_tracking(self):
        if self.frame_id % 1 == 0 or not self.is_tracking:
            self.is_tracking = None
            self.target_detection = self._object_detection()
            print('target detections :{}'.format(self.target_detection))
            if self.target_detection is not None:
                self.tracker = cv2.TrackerKCF_create()
                self.tracker.init(self.cv_image,
                                  bbox_to_roi(self.target_detection['bbox']))

        if self.target_detection is not None:
            self.is_tracking, roi = self.tracker.update(self.cv_image)
            self.target_detection['bbox'] = roi_to_bbox(roi)
            self.target_detection['rbbox'] = bbox_to_rbbox(
                self.target_detection['bbox'], self.cv_image)
Exemplo n.º 3
0
 def update_target_detection(self):
     self.target_detection = self._object_detection()
     print('target detections :{}'.format(self.target_detection))
     if self.target_detection is not None:
         self.target_detection['rbbox'] = bbox_to_rbbox(
             self.target_detection['bbox'], self.cv_image)