Пример #1
0
 def start(self):
     info = tello_center.get_config(JudgeServerLocal.CONFIG_BOX_INFO,
                                    fallback=None)
     if info is None:
         info = {
             1: IDX_CAT,
             2: IDX_GAS_TANK,
             3: IDX_BABY,
             4: IDX_FILES,
             5: IDX_PAINTING
         }
     self.targets = []
     self.results = []
     rand = random.Random(
         tello_center.get_config(JudgeServerLocal.CONFIG_RANDOM_SEED,
                                 fallback=None))
     while len(self.targets) != 3:
         idx = rand.randint(1, 5)
         if idx in self.results:
             continue
         self.results.append(idx)
         self.targets.append(info[idx])
     self.logger.info("Initial with {%d: %s, %d: %s, %d: %s}" %
                      (self.results[0], id2name[self.targets[0]],
                       self.results[1], id2name[self.targets[1]],
                       self.results[2], id2name[self.targets[2]]))
Пример #2
0
 def preload(service: tello_center.PreLoadService):
     if tello_center.get_config(YoloService.CONFIG_USE_YOLO, fallback=True):
         weights = tello_center.get_config(YoloService.CONFIG_YOLO_WEIGHTS,
                                           fallback='fire_new_1207.pt')
         service.put_loaded(YoloService.PRELOAD_YOLO_DETECTOR,
                            Detect(0.1, weights=weights))
     else:
         service.put_loaded(YoloService.PRELOAD_YOLO_DETECTOR,
                            detect.Detect(0.1))
Пример #3
0
    def start(self):
        if tello_center.get_config(YoloService.CONFIG_LOOP_DETECTION,
                                   fallback=True):
            self.logger.info('start loop detection')
            t = threading.Thread(target=self.loop_thread)
            t.daemon = True
            t.start()

        if tello_center.get_config(YoloService.CONFIG_DETECT_ON_MAIN_THREAD,
                                   fallback=True):
            self.task_loop = TaskLoop(flag=self.flag)

            def override_lock_loop():
                tello_center.input_exit_thread(daemon=True)
                self.task_loop.start()

            tello_center.lock_loop = override_lock_loop
Пример #4
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)
Пример #5
0
 def on_request_exit(self):
     tello_center.Service.on_request_exit(self)
     if tello_center.get_config(
             TelloBackendService.CONFIG_AUTO_LAND_ON_EXIT, True):
         self.drone.land()
Пример #6
0
    def process(self, image, state: tello_data.TelloData, showimg):
        x, y, w, h = redball_detecter.find_red_ball(image)
        if x is not None:
            cv2.rectangle(showimg, (x, y), (x + w, y + h), (255, 0, 0),
                          thickness=2)
            px = x + w / 2.0
            py = y + h / 2.0
            view = 45 / 180.0 * np.pi
            det = 10 / 180.0 * np.pi
            _y, _dis_y, _det_y = solve_system(det, (np.pi - view) / 2, view,
                                              720, x, x + h, 10)

            pix_size = 1.0 / w * 10  # 单位像素对应的实际长度
            la_x = 480
            la_y = 168
            cx = int(x + w / 2)
            cy = int(y + h / 2)

            rh = _y(la_y) - _y(cy)  # (360 - cy) * pix_size
            # delta = 20
            # ry1 = _y(la_y)
            # ry2 = _y(la_y + delta)
            # scale = (ry2 - ry1) / delta
            ry = (cx - la_x) * pix_size  # (cx - 480) * pix_size
            ry += (180 - state.x) * np.tan(state.mpry[1] / 180.0 * np.pi)
            cv2.line(showimg, (la_x, la_y), (cx, la_y), (0, 255, 0),
                     thickness=2)
            cv2.line(showimg, (cx, la_y), (cx, cy), (0, 255, 0), thickness=2)
            s = "y offset: %.2fcm" % ry
            cv2.putText(showimg,
                        s, (la_x, la_y),
                        cv2.FONT_HERSHEY_PLAIN,
                        1, (0, 0, 0),
                        thickness=5)
            cv2.putText(showimg,
                        s, (la_x, la_y),
                        cv2.FONT_HERSHEY_PLAIN,
                        1, (255, 255, 255),
                        thickness=1)
            s = "h offset: %.2fcm" % rh
            cv2.putText(showimg,
                        s, (cx, la_y + 20),
                        cv2.FONT_HERSHEY_PLAIN,
                        1, (0, 0, 0),
                        thickness=5)
            cv2.putText(showimg,
                        s, (cx, la_y + 20),
                        cv2.FONT_HERSHEY_PLAIN,
                        1, (255, 255, 255),
                        thickness=1)

            pos = state.get_pos()
            ray = state.get_ray(px, py)
            if self.world.available():
                pos = self.world.collide_ray_window(pos, ray)
                if pos is not None:
                    pos = pos[0]
                    # print(pos)
                    self.detectedPos.append(pos)
                    if self.pos_handler is not None:
                        self.pos_handler(pos)
                    s = '%.2f %.2f %.2f' % (pos[0], pos[1], pos[2])
                    la_x = 960 - 200
                    la_y = 720 - 30
                    cv2.putText(showimg,
                                s, (la_x, la_y),
                                cv2.FONT_HERSHEY_PLAIN,
                                1, (0, 0, 0),
                                thickness=5)
                    cv2.putText(showimg,
                                s, (la_x, la_y),
                                cv2.FONT_HERSHEY_PLAIN,
                                1, (255, 255, 255),
                                thickness=1)
                    if tello_center.get_config(
                            FireDetector.CONFIG_SHOW_POS_MAP, fallback=False):
                        fmap = np.array([206, 300, 3])
                        locks.imshow('fire_map', fmap)
                    self.preload.put_loaded(FireDetector.PRELOAD_FIRE_POS,
                                            np.copy(pos))
                elif self.pos_handler is not None:
                    self.pos_handler(None)