Пример #1
0
    def detect(self, img, x=0, y=0, w=0, h=0):
        detector = tello_center.get_preloaded(
            YoloService.PRELOAD_YOLO_DETECTOR)  # type: Detect
        if detector is None:
            raise BaseException('detector not loaded')
        if w == 0 or h == 0:
            return self.post_detect(img)
        else:
            c = np.copy(img[y:y + h, x:x + w])
            locks.imshow('copy', c)
            results = self.post_detect(c)

            if results is not None:
                for r in results:
                    r.x1 += x
                    r.x2 += x
                    r.y1 += y
                    r.y2 += y
            else:
                results = []

            # for r in detector.detect(img) or []:
            #     results.append(r)
            if len(results) == 0:
                return None
            return results
Пример #2
0
 def __getattribute__(self, item):
     if item == 'key':
         return object.__getattribute__(self, item)
     handler = tello_center.get_preloaded(self.key)
     if handler is None:
         if item == 'enable':
             return False
         return None
     return handler.__getattribute__(item)
Пример #3
0
 def post_detect(self, img):
     if tello_center.get_config(YoloService.CONFIG_DETECT_ON_MAIN_THREAD,
                                fallback=True):
         task = DetectImage(
             tello_center.get_preloaded(YoloService.PRELOAD_YOLO_DETECTOR),
             img)
         return task.invoke_on(self.task_loop)
     else:
         return self.get_detector().detect(img)
Пример #4
0
 def loop_thread(self):
     while self.flag():
         detector = tello_center.get_preloaded(
             YoloService.PRELOAD_YOLO_DETECTOR)  # type: Detect
         if self.backend.available() and detector is not None:
             img, _ = self.backend.drone.get_image_and_state()
             if img is None:
                 time.sleep(0.1)
                 continue
             img = np.copy(img)
             result = self.detect(img)
             #result = self.detect(img, 480, 100, 480, 360)
             detector.draw_result(img, result)
             locks.imshow('detect', img)
             time.sleep(0.3)
         else:
             time.sleep(0.1)
     self.logger.info('exit loop detection')
Пример #5
0
        def spinCameraTask(task):
            #self = startup
            angleDegrees = task.time*30.0
            # angleDegrees = 0
            angleRadians = angleDegrees*(pi/180.0)

            if self.backend.available() and self.backend.drone.get_state() is not None:
                state = self.backend.drone.get_state()  # type: tello_data.TelloData
                if state.mid > 0:
                    pos = state.get_pos()
                    hpr = state.get_hpr() / np.pi * 180
                    tello.setPos(pos[0], pos[1], pos[2])
                    tello.setDirection(hpr[0], hpr[1], hpr[2])
                else:
                    pass
            else:
                tello.setPos(3*sin(angleRadians), -3*cos(angleRadians), 1.6)
                tello.setDirection(angleDegrees, 0, 0)

            pos = tello_center.get_preloaded(tello_image_process.FireDetector.PRELOAD_FIRE_POS)
            if pos is not None:
                box.setPos(pos[0], pos[1], pos[2])
            time.sleep(1.0/60.0)
            return Task.cont
Пример #6
0
 def get_detector(self) -> Detect:
     return tello_center.get_preloaded(
         YoloService.PRELOAD_YOLO_DETECTOR)  # type: Detect