资讯动态

image_to_world_plane 如何计算校正图像(rectified image)的尺寸、比例(Scale)、位姿(Pose)

发布时间:2026/10/9 9:41:50 来源:尧图企业网站定制
第一步定义校正后图像的尺寸WidthMappedImage : 652 HeightMappedImage : 494设定校正后图像的宽度为 652 像素高度为 494 像素。第二步根据世界坐标系WCS与图像坐标系ICS中点间距的比值确定像素尺度Scale为了使校正图像的局部尺度与原始图像在关注区域附近尽可能一致程序通过以下方式计算ScaleDist_ICS : 1 // 在图像坐标系中取1个像素的距离将中心点及其上下/左右偏移1像素的点转换到世界坐标系image_points_to_world_plane(CamParam, Pose, CenterRow, CenterCol, 1, CenterX, CenterY) // 向下偏移1像素行1 image_points_to_world_plane(CamParam, Pose, CenterRow Dist_ICS, CenterCol, 1, BelowCenterX, BelowCenterY) // 向右偏移1像素列1 image_points_to_world_plane(CamParam, Pose, CenterRow, CenterCol Dist_ICS, 1, RightOfCenterX, RightOfCenterY)计算世界坐标系中对应的垂直和水平距离distance_pp(CenterY, CenterX, BelowCenterY, BelowCenterX, Dist_WCS_Vertical) distance_pp(CenterY, CenterX, RightOfCenterY, RightOfCenterX, Dist_WCS_Horizontal)由此得到局部尺度ScaleVertical : Dist_WCS_Vertical / Dist_ICS // 每像素对应的世界垂直距离 ScaleHorizontal : Dist_WCS_Horizontal / Dist_ICS // 每像素对应的世界水平距离 ScaleForCenteredImage : (ScaleVertical ScaleHorizontal) / 2.0 // 取平均作为最终Scale✅ 这样可确保在校正图像中心区域像素密度与原始图像接近避免过度拉伸或压缩。第三步调整测量平面的位姿使指定点位于校正图像中心为了让(CenterRow, CenterCol)对应的世界点(CenterX, CenterY)出现在校正图像的正中心需平移世界坐标系原点DX : CenterX - ScaleForCenteredImage * WidthMappedImage / 2.0 DY : CenterY - ScaleForCenteredImage * HeightMappedImage / 2.0 DZ : 0 set_origin_pose(Pose, DX, DY, DZ, PoseForCenteredImage) 原理校正图像左上角 WCS 原点图像中心 (Width/2, Height/2) × Scale因此要让(CenterX, CenterY)落在中心需将 WCS 原点设为(CenterX - W/2×S, CenterY - H/2×S)封装为 HDevelop 过程Procedure上述逻辑被封装在以下过程里parameters_image_to_world_plane_centered( :: CamParam, Pose, CenterRow, CenterCol, WidthMappedImage, HeightMappedImage : ScaleForCenteredImage, PoseForCenteredImage )该过程属于示例程序%HALCONEXAMPLES%\solution_guide\3d_vision\transform_image_into_wcs.hdev第四步执行图像校正使用计算好的参数生成映射并校正图像gen_image_to_world_plane_map( Map, CamParam, PoseForCenteredImage, WidthOriginalImage, HeightOriginalImage, WidthMappedImage, HeightMappedImage, ScaleForCenteredImage, bilinear) map_image(Image, Map, ImageMapped)✅ 此方法高效适用于多帧图像处理。示例程序第二部分确保整幅原始图像可见于校正图像中若目标是完整保留原始图像内容而非聚焦某一点则需将原始图像的四个边界映射到世界坐标系并据此设定校正图像的范围full_domain(Image, ImageFull) // 获取图像完整区域 get_domain(ImageFull, Domain) // 提取定义域 gen_contour_region_xld(Domain, ImageBorder, border) // 生成边界轮廓 contour_to_world_plane_xld(ImageBorder, ImageBorderWCS, CamParam, Pose, 1)后续可从ImageBorderWCS中提取世界坐标的最小/最大 X、Y 值从而确定校正图像的WidthMappedImage/HeightMappedImage新的PoseForCenteredImage使整个区域居中合适的ScaleForCenteredImage这样可生成一张包含全部原始图像信息的无畸变校正图。然后确定图像在世界坐标系中的范围extentsmallest_rectangle1_xld (ImageBorderWCS, MinY, MinX, MaxY, MaxX) ExtentX : MaxX - MinX ExtentY : MaxY - MinY该步骤计算原始图像边界轮廓已转换到世界坐标系的最小外接矩形从而得到其在 X 和 Y 方向上的总跨度。接着计算校正图像的像素尺度Scale即世界坐标系中的物理尺寸与校正图像的像素尺寸之比ScaleX : ExtentX / WidthMappedImage ScaleY : ExtentY / HeightMappedImage为保证整个原始图像内容都能完整容纳在校正图像内且不发生裁剪需选择两个方向中较大的尺度值作为最终统一的缩放比例避免某方向被压缩ScaleForEntireImage : max([ScaleX, ScaleY])最后将世界坐标系的原点平移到该外接矩形的左下角或左上角取决于坐标系定义以确保校正图像覆盖全部区域set_origin_pose (Pose, MinX, MinY, 0, PoseForEntireImage)✅ 此操作使校正后图像的左上角对应世界坐标(MinX, MinY)从而完整包含原始图像投影区域。封装过程上述逻辑已被封装为 HDevelop 过程parameters_image_to_world_plane_entire ( Image : : CamParam, Pose, WidthMappedImage, HeightMappedImage : ScaleForEntireImage, PoseForEntireImage )该过程是示例程序的一部分%HALCONEXAMPLES%\solution_guide\3d_vision\transform_image_into_wcs.hdev应用对比总结目标推荐方法完整显示整幅图像内容平面场景parameters_image_to_world_plane_entiregen_image_to_world_plane_map聚焦某点并保持局部尺度一致parameters_image_to_world_plane_centered非平面物体校正gen_grid_rectification_map仅去除镜头畸变保留原始视角gen_radial_distortion_map

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑