class TestTag: def setup_class(self): self.tag = Tag() def test_del_tmp_groups(self): # 清理之前自动化创建的标签组 for group in self.tag.list_tag().json()['tag_group']: if 'tmp_group' in group['group_name']: self.tag.del_tag(group_ids=[group['group_id']]) def test_add_tag(self): time_now = time.strftime('%Y%m%d%H%M%S', time.localtime()) group_name = f'tmp_group{time_now}' tag = [{ 'name': f'tmp_tag{time_now}', }] r = self.tag.add_tag(group_name, tag) assert r.status_code == 200 and r.json()['errcode'] == 0 def test_update_tag(self): r = self.tag.update_tag(self.tag.tag_id, name='new_tag_name') assert r.status_code == 200 and r.json()['errcode'] == 0 def test_list_tag(self): r = self.tag.list_tag() assert r.status_code == 200 and r.json()['errcode'] == 0 def test_del_tag(self): group_ids = [self.tag.group_id] tag_ids = [self.tag.tag_id] r = self.tag.del_tag(group_ids=group_ids, tag_ids=tag_ids) assert r.status_code == 200 and r.json()['errcode'] == 0
# Fisheye flag camera_info["fisheye"] = True camera_info["map_1"], camera_info[ "map_2"] = cv2.fisheye.initUndistortRectifyMap(camera_info["K"], camera_info["D"], np.eye(3), camera_info["K"], camera_info["res"], cv2.CV_16SC2) # Tag information TAG_SIZE = .123 FAMILIES = "tagStandard41h12" tags = Tag(TAG_SIZE, FAMILIES) # Add information about tag locations # Function Arguments are id,x,y,z,theta_x,theta_y,theta_z tags.add_tag(0, 76.25, 30.5, 0., 0., 0., 0.) tags.add_tag(1, 115., 31.5, 0., 0., 0., 0.) tags.add_tag(2, 95.75, 50., 0., 0., 0., 0.) tags.add_tag(3, 0., 41., 38.75, 0., -np.pi / 2, 0.) tags.add_tag(4, 0., 54., 19.25, 0., -np.pi / 2, 0.) starting_position = np.array([[.635], [1.0668], [2.7432]]) # Create Apriltags Detector detector = Detector(families=tags.family, nthreads=4) # Create the camera object with PiCamera() as camera: camera.resolution = RES camera.framerate = FPS # Reduce the shutter speed to reduce blur, given in microseconds
cv2.circle(color_img, tuple(tag.corners[0].astype(int)), 2, color=(255, 0, 255), thickness=3) return color_img # Create a Tag object TAG_SIZE = .123 FAMILIES = "tagStandard41h12" tags = Tag(TAG_SIZE, FAMILIES) # Add information about tag locations # Function Arguments are id,x,y,z,theta_x,theta_y,theta_z tags.add_tag(1, 115., 31.5, 0., 0., 0., 0.) tags.add_tag(2, 95.75, 50., 0., 0., 0., 0.) # Create Detector detector = Detector(families=tags.family, nthreads=4) camera_info = {} # Camera Resolution camera_info["res"] = RES # Camera Intrinsic Matrix (3x3) camera_info["K"] = np.array([[313.11130800756115, 0.0, 336.11351317641487], [0.0, 310.34427179740504, 239.24222723346466], [0.0, 0.0, 1.0]]) # The non-default elements of the K array, in the AprilTag specification camera_info["params"] = [313.111, 310.344, 336.114, 239.242] # Fisheye Camera Distortion Matrix