QQ登录

只需一步,快速开始

halcon gen_cube_map_mosaic函数介绍

[ 复制链接 ]
gen_cube_map_mosaic(Images : Front, Rear, Left, Right, Top, Bottom : CameraMatrices, RotationMatrices, CubeMapDimension, StackingOrder, Interpolation : )

gen_cube_map_mosaic从Images中创建6个立方体映射图像,
分别是 Front, Left, Rear, Right, Top 及 Bottom。
空间图像的位姿是用来计算图像相对于球体表面的位置的,
可以用stationary - camera_self - calibration来确定。
利用定标法计算的摄像机和旋转矩阵可用于摄像机和旋转矩阵的计算。


stationary_camera_self_calibration计算的相机参数
可以向CameraMatrices,RotationMatrices传递使用。
球面马赛克只能由使用固定摄像机拍摄的图像创建(请参见stationary_camera_self_calibration)。


可以通过设置参数CubeMapDimension来选择输出多维数据集映射图像的宽度和高度。
该值表示宽度和高度(以像素为单位)。


将图像添加到马赛克中的模式由StackingOrder给出。
对于StackingOrder = 'voronoi',马赛克图像中的点由各自输入图像的voronoi单元确定。
这意味着灰度值是从输入图像的点取的,其中心与马赛克图像中的像素在球面上的距离最小。


这种模式的优点是,晕渲和未校正的径向畸变在马赛克图像中不太明显,
因为它们通常是相对于图像中心对称的。
或者,通过选择如下所述的参数,可以选择一种模式,
其效果与连续将图像绘制到马赛克图像中一样。
在这里,将图像添加到马赛克图像中的顺序非常重要。
因此,可以按堆栈顺序传递整数值数组。


这个数组中的第一个索引最终会在图像堆栈的底部,而最后一个索引将在顶部。
如果“default”给定,而不是一个整数数组,那么规范顺序(Images中的顺序)将被使用。
因此,如果没有使用“voronoi”和“default”,那么StackingOrder必须包含排列,1…n,
n是Images传递的图像数量。
应该注意的是,模式“voronoi”不能永远使用。
例如,必须通过至少两个图像来使用这种模式。
此外,在图像中心位置的特殊配置中,Voronoi细胞不能唯一确定。
使用StackingOrder = 'blend',可以使用另一种模式,它可以平滑地混合马赛克的图像。
这样,图像之间的接缝就不那么明显了。
图像之间的缝线与“voronoi”中相同。
这种模式使图像在视觉上更吸引人,但需要更多的资源。
如果模式“voronoi”或“blend”由于任何原因不能使用,
则模式将在内部自动切换为“default”。


参数 Interpolation选择所需的插值模式来创建立方体映射
“bilinear”和“bicubic”插值适用于所有 StackingOrder。
“nearest_neighbor”仅在StackingOrder设置为“default”或“voronoi”时可用。


参数
Images为输入的图像
Front,Rear,Left,Right,Top,Bottom为输出前后左右上下映射。
CameraMatrices 3x3投影相机矩阵,确定相机内部参数。
RotationMatrices
由3x3变换矩阵组成的数组,用于确定相机在各自图像中的旋转。
StackingOrder将图像添加到马赛克图像的模式。有: 'blend', 'voronoi', 'default'
Interpolation图像插值模式。有 'nearest_neighbor', 'bilinear', 'bicubic'


halcon自带例程:
dev_close_window ()
dev_open_window (0, 0, 978, 324, 'black', WindowHandle)
dev_set_part (0, 0, 647, 1955)
gen_empty_obj (Images)
for J := 1 to 72 by 1
    read_image (Image, 'panorama/sankt_martin_manual_' + J$'03d')
    concat_obj (Images, Image, Images)
endfor
get_image_size (Image, Width, Height)
FF := [1,1,2,2,3,3,4,4,5,5,6]
TT := [2,7,3,8,4,9,5,10,6,11,12]
From := []
To := []
for J := 0 to 11 by 1
    From := [From,(FF - 1 + 6 * J) % 72 + 1]
    To := [To,(TT - 1 + 6 * J) % 72 + 1]
endfor
HomMatrices2D := []
Rows1 := []
Cols1 := []
Rows2 := []
Cols2 := []
NumMatches := []
for J := 0 to |From| - 1 by 1
    select_obj (Images, ImageF, From[J])
    select_obj (Images, ImageT, To[J])
    points_foerstner (ImageF, 1, 2, 3, 50, 0.1, 'gauss', 'true', RowsF, ColsF, CoRRJunctions, CoRCJunctions, CoCCJunctions, RowArea, ColumnArea, CoRRArea, CoRCArea, CoCCArea)
    points_foerstner (ImageT, 1, 2, 3, 50, 0.1, 'gauss', 'true', RowsT, ColsT, CoRRJunctions1, CoRCJunctions1, CoCCJunctions1, RowArea1, ColumnArea1, CoRRArea1, CoRCArea1, CoCCArea1)
    concat_obj (ImageT, ImageF, ImageTF)
    tile_images_offset (ImageTF, TiledImage, [0,0], [0,Width + 20], [-1,-1], [-1,-1], [-1,-1], [-1,-1], 2 * Width + 20, Height)
    gen_cross_contour_xld (PointsF, RowsF, ColsF + Width + 20, 6, rad(45))
    gen_cross_contour_xld (PointsT, RowsT, ColsT, 6, rad(0))
    rgb1_to_gray (ImageF, ImageFG)
    rgb1_to_gray (ImageT, ImageTG)
    proj_match_points_ransac (ImageFG, ImageTG, RowsF, ColsF, RowsT, ColsT, 'sad', 10, 0, 0, 648, 968, [rad(-10),rad(40)], 30, 'gold_standard', 10, 42, HomMat2D, Points1, Points2)
    HomMatrices2D := [HomMatrices2D,HomMat2D]
    Rows1 := [Rows1,subset(RowsF,Points1)]
    Cols1 := [Cols1,subset(ColsF,Points1)]
    Rows2 := [Rows2,subset(RowsT,Points2)]
    Cols2 := [Cols2,subset(ColsT,Points2)]
    NumMatches := [NumMatches,|Points1|]
    * The rest of the code within the loop visualizes the point matches.
    RF := subset(RowsF,Points1)
    CF := subset(ColsF,Points1) + Width + 20
    RT := subset(RowsT,Points2)
    CT := subset(ColsT,Points2)
    gen_empty_obj (Matches)
    for K := 0 to |RF| - 1 by 1
        gen_contour_polygon_xld (Match, [RF[K],RT[K]], [CF[K],CT[K]])
        concat_obj (Matches, Match, Matches)
    endfor
    dev_clear_window ()
    dev_display (TiledImage)
    dev_set_color ('blue')
    dev_display (Matches)
    dev_set_color ('green')
    dev_display (PointsF)
    dev_display (PointsT)
    dev_set_color ('yellow')
    set_tposition (WindowHandle, 20, 20)
    write_string (WindowHandle, 'Matches between images ' + From[J]$'d' + ' and ' + To[J]$'d')
endfor
dev_clear_window ()
dev_set_window_extents (-1, -1, 856, 428)
dev_set_color ('yellow')
set_tposition (WindowHandle, 20, 20)
write_string (WindowHandle, 'Performing self-calibration...')
stationary_camera_self_calibration (72, 968, 648, 5, From, To, HomMatrices2D, Rows1, Cols1, Rows2, Cols2, NumMatches, 'gold_standard', ['focus','principal_point','kappa'], 'true', CameraMatrix, Kappa, RotationMatrices, X, Y, Z, Error)
dev_clear_window ()
dev_set_color ('yellow')
set_tposition (WindowHandle, 20, 20)
write_string (WindowHandle, 'Removing radial distortions...')
cam_mat_to_cam_par (CameraMatrix, Kappa, 968, 648, CamParam)
change_radial_distortion_cam_par ('fixed', CamParam, 0, CamParOut)
gen_radial_distortion_map (Map, CamParam, CamParOut, 'bilinear')
map_image (Images, Map, Images)
* Since the reference image was not aligned perfectly horizontally, we modify the
* calibrated rotation matrices by rotating them by 6 degrees around the x axis.
hom_mat3d_identity (HomMat3D)
hom_mat3d_rotate (HomMat3D, rad(6), 'x', 0, 0, 0, HomMat3D)
RotMat := [HomMat3D[0:2],HomMat3D[4:6],HomMat3D[8:10]]
RotMats := []
for J := 0 to 71 by 1
    RotMatCalib := RotationMatrices[J * 9:J * 9 + 8]
    hom_mat2d_compose (RotMatCalib, RotMat, RotMatRot)
    RotMats := [RotMats,RotMatRot]
endfor
dev_clear_window ()
dev_set_color ('yellow')
set_tposition (WindowHandle, 20, 20)
write_string (WindowHandle, 'Creating blended spherical mosaic...')
* Create the blended spherical mosaic.
gen_spherical_mosaic (Images, SphericalMosaic, CameraMatrix, RotMats, -90, 90, -180, 180, 0, 'blend', 'bilinear')
get_image_size (SphericalMosaic, Width, Height)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_clear_window ()
dev_display (SphericalMosaic)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 300, 20)
write_string (WindowHandle, 'Blended spherical mosaic image')
set_tposition (WindowHandle, Height - 150, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_set_window_extents (-1, -1, 409, 409)
dev_set_part (0, 0, 1633, 1633)
dev_set_color ('yellow')
set_tposition (WindowHandle, 40, 40)
write_string (WindowHandle, 'Creating blended cube map mosaic...')
* Create the blended cube map mosaic.
gen_cube_map_mosaic (Images, Front, Rear, Left, Right, Top, Bottom, CameraMatrix, RotMats, 0, 'blend', 'bilinear')

get_image_size (Front, Width, Height)
dev_clear_window ()
dev_display (Front)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Front cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_display (Left)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Left cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_display (Rear)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Rear cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_display (Right)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Right cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_display (Top)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Top cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_display (Bottom)
dev_set_color ('yellow')
set_tposition (WindowHandle, Height - 200, 20)
write_string (WindowHandle, 'Bottom cube map image')
set_tposition (WindowHandle, Height - 100, 20)
write_string (WindowHandle, 'Press \'Run\' to continue')
stop ()
dev_clear_window ()
dev_set_window_extents (-1, -1, Width / 2, 3 * Height / 8)
dev_set_part (0, 0, 3 * Height - 1, 4 * Width - 1)
dev_set_color ('yellow')
set_tposition (WindowHandle, 100, 100)
write_string (WindowHandle, 'Creating tiled cube map mosaic...')
* Create a tiled version of the cube map mosaic in which the horizontal looking
* images (front, left, rear, and right) are aligned in a strip and the top and bottom
* images are aligned above and below the front image.
concat_obj (Top, Left, CubeMaps)
concat_obj (CubeMaps, Front, CubeMaps)
concat_obj (CubeMaps, Right, CubeMaps)
concat_obj (CubeMaps, Rear, CubeMaps)
concat_obj (CubeMaps, Bottom, CubeMaps)
tile_images_offset (CubeMaps, CubeMapTiled, [0,Height,Height,Height,Height,2 * Height], [Width,0,Width,2 * Width,3 * Width,Width], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], 4 * Width, 3 * Height)
dev_clear_window ()
dev_display (CubeMapTiled)
dev_set_color ('yellow')
set_tposition (WindowHandle, 3 * Height - 200, 2 * Width + 200)
write_string (WindowHandle, 'Tiled cube map image')



二.gen_projective_mosaic(Images : MosaicImage : StartImage, MappingSource, MappingDest,
HomMatrices2D, StackingOrder, TransformDomain : MosaicMatrices2D)
gen_projective_mosaic将输入图像Images 内全部图像组合成马赛克图像。
图像的相对位置由3x3投影变换矩阵定义。
数组HomMatrices2D包含这些线性化矩阵的序列。
MappingSource和MappingDest中的值是对应矩阵所应用的图像的索引。
MappingSource=4, MappingDest=7表示矩阵描述了图像4到图像7射影平面的变换。
MappingSource和MappingDest给出的图像对之间的转换矩阵通常由proj_match_points_ransac确定。


与通常访问图像对象的操作符(例如select_obj)一样,图像的编号从1开始,
即、MappingSource、MappingDest、StartImage和StackingOrder)必须包含在Images图像数量和1之间的值。


参数StartImage表示哪个图像定义了最终图像的图像平面,即哪个输入图像在输出图像中保持不变。
这通常是位于图像镶嵌中心附近的图像。


自动选择MosaicImage的原点及其大小,使所有输入图像都完全可见。

将图像添加到马赛克中的顺序由数组 StackingOrder给出。

这个数组中的第一个索引将位于图像堆栈的底部,而最后一个索引将位于顶部。
如果给定的是“default”而不是整数数组,则使用规范顺序(图像Images 中使用的图像顺序)。


参数TransformDomain可以用来确定图像的域是否也被转换。
由于域的转换需要运行时间,因此应该使用这个参数来指定是否需要这样做。
如果将TransformDomain设置为“false”,则忽略输入图像的域,并转换完整的图像。

在输出时,参数MosaicMatrices2D包含一组3x3投影变换矩阵,
用于描述图像中的每个图像到其在马赛克中的位置的映射。
参数:
Images,MosaicImage为输入与输出的图像
StartImage中心输入图像的索引。
MappingSource变换的源图像的索引
MappingDest变换的目标图像的索引。
HomMatrices2D  3x3射影变换矩阵的数组。
StackingOrder马赛克图像的叠加顺序。
TransformDomain 输入图像的域也应该转换标志。
MosaicMatrices2D 由3x3投影变换矩阵组成的数组,用于确定图像在马赛克中的位置。


例程:
gen_empty_obj (Images)
for J := 1 to 6 by 1
    read_image (Image, 'mosaic/pcb_'+J$'02')
    concat_obj (Images, Image, Images)
endfor
From := [1,2,3,4,5]
To := [2,3,4,5,6]
Num := |From|
ProjMatrices := []
stop()
for J := 0 to Num-1 by 1
    F := From[J]
    T := To[J]
    select_obj (Images, ImageF, F)
    select_obj (Images, ImageT, T)
    points_foerstner (ImageF, 1, 2, 3, 200, 0.3, 'gauss', 'false', \
                      RowJunctionsF, ColJunctionsF, CoRRJunctionsF, \
                      CoRCJunctionsF, CoCCJunctionsF, RowAreaF, \
                      ColAreaF, CoRRAreaF, CoRCAreaF, CoCCAreaF)
    points_foerstner (ImageT, 1, 2, 3, 200, 0.3, 'gauss', 'false', \
                      RowJunctionsT, ColJunctionsT, CoRRJunctionsT, \
                      CoRCJunctionsT, CoCCJunctionsT, RowAreaT, \
                      ColAreaT, CoRRAreaT, CoRCAreaT, CoCCAreaT)
    proj_match_points_ransac (ImageF, ImageT, RowJunctionsF, \
                              ColJunctionsF, RowJunctionsT, \
                              ColJunctionsT, 'ncc', 21, 0, 0, 480, 640, \
                              0, 0.5, 'gold_standard', 1, 4364537, \
                              ProjMatrix, Points1, Points2)
    ProjMatrices := [ProjMatrices,ProjMatrix]
endfor
gen_projective_mosaic (Images, MosaicImage, 2, From, To, ProjMatrices, \
                       'default', 'false', MosaicMatrices2D)
  

halcon从自学到接项目视频教程,另外再赠送全网最全资源  

  

欢迎围观我录制的一套halcon自学视频教程(进入)



回复

使用道具 举报

快速回复 返回列表 客服中心 搜索