Halcon 图像拼接-多图数组任意行列

一、图像拼接在很多项目中都有使用,一般用于视觉检测和结果展示。最简单的图像拼接是一个图像数组,确定横向还是纵向拼接,确定好行数或者列数,然后整合成一张大图。缺点是横向和纵向只能选其一,无法任意设置。而且被拼接的图像尺寸必须是一致的。另一种图像拼接是可以任意设置行列,可以任意设置拼接的位置。下面对两种拼接方式做解答。
二、算子详解
2.1 void TileImages(const HObject& Images, HObject* TiledImage, const HTuple& NumColumns, const HTuple& TileOrder)
Images 图像数组
TiledImage 结果图
NumColumns 行/列数
TileOrder 水平horizontal/竖直vertical
代码案例:
read_image (BinSwitch1, ‘bin_switch_1.png’)
read_image (BinSwitch2, ‘bin_switch_2.png’)
read_image (BinSwitch3, ‘bin_switch_3.png’)
concat_obj (BinSwitch1, BinSwitch2, imgs)
concat_obj (imgs, BinSwitch3, imgs)
tile_images (imgs, TiledImage, 1, ‘vertical’)

输入图像
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
结果图
在这里插入图片描述
2.2 void TileImagesOffset(const HObject& Images, HObject* TiledImage, const HTuple& OffsetRow, const HTuple& OffsetCol, const HTuple& Row1, const HTuple& Col1, const HTuple& Row2, const HTuple& Col2, const HTuple& Width, const HTuple& Height)
Images 图像数组
TiledImage 结果图
OffsetRow 待拼接小图应该在结果大图的位置(左上角的行坐标)
OffsetCol 待拼接小图应该在结果大图的位置(左上角的列坐标)
Row1 待拼接小图是否被裁剪(-1 不裁剪,其余值裁剪),裁剪左上角行坐标
Col1 待拼接小图是否被裁剪(-1 不裁剪,其余值裁剪),裁剪左上角列坐标
Row2 待拼接小图是否被裁剪(-1 不裁剪,其余值裁剪),裁剪右下角行坐标
Col2 待拼接小图是否被裁剪(-1 不裁剪,其余值裁剪),裁剪右下角列坐标
如果这四个参数中的任何一个设置为-1,则不会裁剪相应的输入图像。在任何情况下,所有四个参数各自长度都必须与输入图像数组长度一致。
Width 结果图宽
Height 结果图高
代码案例:
read_image (BinSwitch1, ‘bin_switch_1.png’)
read_image (BinSwitch2, ‘bin_switch_2.png’)
read_image (BinSwitch3, ‘bin_switch_3.png’)
read_image (BinSwitch4, ‘bin_switch_4.png’)
read_image (BinSwitch5, ‘bin_switch_5.png’)
read_image (BinSwitch6, ‘bin_switch_6.png’)
concat_obj (BinSwitch1, BinSwitch2, imgs)
concat_obj (imgs, BinSwitch3, imgs)
concat_obj (imgs, BinSwitch4, imgs)
concat_obj (imgs, BinSwitch5, imgs)
concat_obj (imgs, BinSwitch6, imgs)
rows:=2
cols:=3
*重叠补偿默认为0 ,需要拼接图像有重叠,可以设置指定行列数
offsetR:=0
offsetC:=0
get_image_size (BinSwitch1, Width, Height)
totalWidth:=Width x cols - offsetC x (cols-1)
totalHeight:=Height x rows - offsetR x (rows-1)
cropRow:=[]
cropCol:=[]
for i := 0 to rows-1 by 1
for j := 0 to cols-1 by 1
cropRow:=[cropRow, i x Height - i x offsetR]
cropCol:=[cropCol, j x Width - j x offsetC]
endfor
endfor
*这里默认不裁剪小图
tuple_gen_const (rows x cols, -1, Newtuple)
tile_images_offset (imgs, TiledImage1, cropRow, cropCol, Newtuple, Newtuple, Newtuple, Newtuple, totalWidth, totalHeight)
输入图片
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
结果图
在这里插入图片描述

### Halcon 图像拼接实现方法 图像拼接通常指的是将图像直接按照一定的排列规则拼接成一张大,而不进行图像之间的特征匹配或形变校正。在 Halcon 中,可以通过 `tile_images` 算子实现这种硬拼接操作。 #### 基本原理 硬拼接的核心思想是将图像按照指定的行列数和排列顺序拼接在一起,生成一个更大的图像。这种方式适用于图像之间已经对齐或者不需要复杂的几何变换的情况。 #### 实现步骤 1. **读取图像**:使用 `read_image` 读取需要拼接图像。 2. **合并图像对象**:通过 `concat_obj` 将图像合并为一个图像数组。 3. **调用 `tile_images` 算子**:设置好拼接参数(如列数、拼接方向等),生成最终的拼接图像。 #### 参数说明 - `Images`:输入的图像数组- `TiledImage`:输出的拼接结果图像- `NumColumns`:指定每行显示的图像数量。如果设置为 1,则表示竖直方向拼接;若大于 1,则表示水平方向拼接- `TileOrder`:拼接顺序,支持 `'horizontal'`(横向)和 `'vertical'`(纵向)两种方式。 #### 示例代码 ```hdevelop * 读取三张图像 read_image (BinSwitch1, 'bin_switch_1.png') read_image (BinSwitch2, 'bin_switch_2.png') read_image (BinSwitch3, 'bin_switch_3.png') * 合并图像对象 concat_obj (BinSwitch1, BinSwitch2, imgs) concat_obj (imgs, BinSwitch3, imgs) * 设置拼接参数:1 列,纵向拼接 tile_images (imgs, TiledImage, 1, 'vertical') ``` 上述代码实现了将三张图像按纵向排列拼接成一张大的效果。若希望横向拼接,可以将 `NumColumns` 设置为图像数量,并将 `TileOrder` 设为 `'horizontal'`。 #### 注意事项 - 图像尺寸不一致时,拼接后的图像可能会出现空白区域。 - 若需精确对齐图像内容,应考虑使用基于特征匹配的软拼接技术。 - 拼接方向与 `TileOrder` 参数密切相关,务必根据实际需求选择合适的排列方式 [^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值