Megapose工业物体位姿估计:图像降采样后相机内参适配异常
基于Megapose的工业金属物体位姿估计内参适配问题
我正在搭建基于Megapose的传送带工业金属物体位姿估计全流程,使用1280x1024px分辨率的相机,流程如下:
- 外部触发时采集全分辨率图像
- 将图像降采样至640x512,实现代码:
img = cv2.resize(img_full, (640, 512), interpolation=cv2.INTER_AREA) - 在降采样图像上自动检测目标并生成掩码与bbox
- 结合降采样图像、bbox坐标、.obj模型及相机内参K矩阵进行位姿估计
位姿估计核心代码
cam = CameraData(K=K, resolution=(h, w)) obs = ObservationTensor.from_numpy(rgb=img, depth=None, K=cam.K).cuda() OBJ_LABEL = "85589" OBJ_MESH_PATH = "./85589/85589.obj" obj_data = ObjectData( label=OBJ_LABEL, bbox_modal=np.array([x, y, x + bw, y + bh], dtype=np.float32) ) detections = make_detections_from_object_data([obj_data]).cuda() OBJ_RIGID = [ RigidObject(label=OBJ_LABEL, mesh_path=Path(OBJ_MESH_PATH), mesh_units="mm") ] obj_dataset = RigidObjectDataset(OBJ_RIGID) pose_estimator = load_named_model( "megapose-1.0-RGB-multi-hypothesis", object_dataset=obj_dataset ).cuda() #with torch.no_grad(): data_TCO_final, data = pose_estimator.run_inference_pipeline( observation=obs, detections=detections, n_refiner_iterations=3, n_pose_hypotheses=10, ) T = data_TCO_final.poses[0].cpu().numpy()
可视化异常现象
- 使用原全分辨率(1280x1024)标定的K矩阵时:坐标轴视觉对齐效果良好,但T矩阵平移量严重偏离真实值(例如Z轴平移仅15cm,实际应为70cm)
- 使用按0.5比例缩放fx、fy、cx、cy得到的降采样图像适配K矩阵时:不仅T矩阵平移偏差,坐标轴完全无法匹配目标
相机内参矩阵
全分辨率(1280x1024)K矩阵:
K = np.array([ [9569.51159, 0.0, 654.607481], [ 0.0, 9561.13907, 519.54065], [ 0.0, 0.0, 1.0] ], dtype=np.float64)
降采样(640x512)K矩阵:
K = np.array([ [4786.600316022559, 0.0, 324.6020298466702], [0.0, 4784.247516721188, 235.07637840007217], [0.0, 0.0, 1.0] ], dtype=np.float64)
说明:因GPU内存不足,无法测试全分辨率图像结合原内参的场景,恳请提供解决思路!
内容的提问来源于stack exchange,提问作者MrJ
相关产品推荐
相关产品推荐

