一、图像拼接在很多项目中都有使用,一般用于视觉检测和结果展示。最简单的图像拼接是一个图像数组,确定横向还是纵向拼接,确定好行数或者列数,然后整合成一张大图。缺点是横向和纵向只能选其一,无法任意设置。另一种图像拼接是可以任意设置行列,可以任意设置拼接的位置。下面对两种拼接方式做解答。
二、算子详解
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:=Widthcols - offsetC*(cols-1)
totalHeight:=Heightrows - offsetR(rows-1)
cropRow:=[]
cropCol:=[]
for i := 0 to rows-1 by 1
for j := 0 to cols-1 by 1
cropRow:=[cropRow, iHeight - ioffsetR]
cropCol:=[cropCol, jWidth - joffsetC]
endfor
endfor
这里默认不裁剪小图
tuple_gen_const (rowscols, -1, Newtuple)
tile_images_offset (imgs, TiledImage1, cropRow, cropCol, Newtuple, Newtuple, Newtuple, Newtuple, totalWidth, totalHeight)
输入图片
结果图