Halcon一日一练:图像拼接技术2:步骤与例程
上一篇主要介绍了图像拼接的一些原理和方法,这一篇将主要介绍步骤和例程:
接上一篇:
基于特征的接拼方法,分为四个步骤
1、特征检测:从图像中检测出显著且独特的图像特征,诸如:闭合区域,直线段,边缘,轮廓,点等。
2、特征匹配:从相似度确定图像之间特征的对应关系,又分为如下几类:
2.1:使用空域关系的方法
2.2:使用不变描述符的方法
2.3:松弛方法
2.4:金字塔和小波方法
3、变换模型的估计:变换函数选择和函数参数估计
4、图像变换和重采样:可以通过前向或后向的方式来实现,插值的方法有最近邻插值、双线性插值、双三次函数插值、二次样条插值、三次B样条插值、高阶B样条插值。
基于特征的方法普遍适用于局部结构信息更显著的情况,能够处理图像之间复杂变形的情况,不足之处是特征检测困难且不稳定,最关键的一点是需要有一种判断力很强的、鲁棒性能好的且对图像之间变化保持不变的特征匹配算法。
下面是Halcon自带例程,如何拼接图像
- **此例程讲解了如何将几张局部的PCB图像拼接居一张大的马赛克PCB图像。
- **此例程使用算子proj_match_points_ransac和算子 gen_projective_masaic完成上述工作。
- **请注意:这个PCB图像有一几处看起来像拼接逢合线的破损点,为了更好的区分真正的缝合线,例程呈现逢合线。
- dev_update_off ()
- dev_close_window ()
- dev_open_window (, , , , 'white', WindowHandle)
- dev_set_color ('green')
- set_display_font (WindowHandle, , 'mono', 'true', 'false')
- **一张一张的读取图像。
- gen_empty_obj (Images)
- for J := to by
- read_image (Image, 'mosaic/pcb_' + J$'')
- concat_obj (Images, Image, Images)
- dev_display (Image)
- disp_message (WindowHandle, 'Image ' + J$'d', 'image', -, -, 'black', 'true')
- wait_seconds ()
- endfor
- disp_continue_message (WindowHandle, 'black', 'true')
- stop ()
- * To show the point matches that are used to compute the projective
- * transformation between the images, we will show all images in a large
- * tiled image with some space between the images so that the extents
- * of the images are easily visible.
- dev_set_window_extents (-, -, / , / )
- tile_images_offset (Images, TiledImage, [,,,,,], [,,,,,], [-,-,-,-,-,-], [-,-,-,-,-,-], [-,-,-,-,-,-], [-,-,-,-,-,-], , )
- dev_clear_window ()
- dev_display (TiledImage)
- disp_message (WindowHandle, 'All 6 images', 'window', , , 'black', 'true')
- disp_message (WindowHandle, 'Click \'Run\'\nto continue', 'window', / - , , 'black', 'true')
- stop ()
- * Now we compute point matches between the five pairs of images and with this
- * the projective transformation between the image pairs. Note that the code
- * below calls the point operator for each image pair. Since the images form
- * a strip, with a little book keeping we could make the process a little more
- * efficient by saving the points from the last iteration (ImageT in pair J will
- * be identical to ImageF in pair J+). This is not done here because such an
- * optimization would be quite cumbersome in the general case where the images
- * can lie in a general configuration that cannot be represented by a strip.
- dev_clear_window ()
- dev_display (TiledImage)
- disp_message (WindowHandle, 'Point matches', 'window', , , 'black', 'true')
- * We define the image pairs, i.e., which image should be mapped to which image.
- From := [,,,,]
- To := [,,,,]
- Num := |From|
- * We need a variable to accumulate the projective transformation matrices.
- ProjMatrices := []
- * Furthermore, since we want to create a rigid mosaic below we need to
- * accumulate all the point correspondences and the number of matches per
- * image pair.
- Rows1 := []
- Cols1 := []
- Rows2 := []
- Cols2 := []
- NumMatches := []
- * Now we can determine the transformations between the five image pairs.
- for J := to Num - by
- F := From[J]
- T := To[J]
- select_obj (Images, ImageF, F)
- select_obj (Images, ImageT, T)
- * Extract the points in both images.
- points_foerstner (ImageF, , , , , 0.3, 'gauss', 'false', RowJunctionsF, ColJunctionsF, CoRRJunctionsF, CoRCJunctionsF, CoCCJunctionsF, RowAreaF, ColAreaF, CoRRAreaF, CoRCAreaF, CoCCAreaF)
- points_foerstner (ImageT, , , , , 0.3, 'gauss', 'false', RowJunctionsT, ColJunctionsT, CoRRJunctionsT, CoRCJunctionsT, CoCCJunctionsT, RowAreaT, ColAreaT, CoRRAreaT, CoRCAreaT, CoCCAreaT)
- * Determine the point matches and the transformation for the current
- * image pair.
- proj_match_points_ransac (ImageF, ImageT, RowJunctionsF, ColJunctionsF, RowJunctionsT, ColJunctionsT, 'ncc', , , , , , , 0.5, 'gold_standard', , , ProjMatrix, Points1, Points2)
- * Accumulate the transformation matrix.
- ProjMatrices := [ProjMatrices,ProjMatrix]
- * Accumulate the point matches and number of point matches.
- Rows1 := [Rows1,subset(RowJunctionsF,Points1)]
- Cols1 := [Cols1,subset(ColJunctionsF,Points1)]
- Rows2 := [Rows2,subset(RowJunctionsT,Points2)]
- Cols2 := [Cols2,subset(ColJunctionsT,Points2)]
- NumMatches := [NumMatches,|Points1|]
- * Generate crosses that represent the extracted points in the tiled image.
- * Note that we have to take the row offsets of the images in the tiled image
- * into account.
- gen_cross_contour_xld (PointsF, RowJunctionsF + (F - ) * , ColJunctionsF, , rad())
- gen_cross_contour_xld (PointsT, RowJunctionsT + (T - ) * , ColJunctionsT, , rad())
- * Generate a representation of the matched point pairs as lines. We create
- * XLD contours from the lines so that we can zoom into the graphics window
- * to take a closer look at the matches.
- RowF := subset(RowJunctionsF,Points1) + (F - ) *
- ColF := subset(ColJunctionsF,Points1)
- RowT := subset(RowJunctionsT,Points2) + (T - ) *
- ColT := subset(ColJunctionsT,Points2)
- gen_empty_obj (Matches)
- for K := to |RowF| - by
- gen_contour_polygon_xld (Match, [RowF[K],RowT[K]], [ColF[K],ColT[K]])
- concat_obj (Matches, Match, Matches)
- endfor
- * Now display the extracted data.
- dev_set_color ('blue')
- dev_display (Matches)
- dev_set_color ('green')
- dev_display (PointsF)
- dev_display (PointsT)
- endfor
- disp_message (WindowHandle, 'Click \'Run\'\nto continue', 'window', / - , , 'black', 'true')
- stop ()
- * Finally, we can generate the mosaic image from the projective transformations.
- gen_projective_mosaic (Images, MosaicImage, , From, To, ProjMatrices, 'default', 'false', MosaicMatrices2D)
- get_image_size (MosaicImage, Width, Height)
- dev_set_window_extents (-, -, Width / , Height / )
- dev_clear_window ()
- dev_display (MosaicImage)
- disp_message (WindowHandle, 'Projective mosaic', 'window', , , 'black', 'true')
- disp_message (WindowHandle, 'Click \'Run\'\nto continue', 'window', Height / - , , 'black', 'true')
- stop ()
- * To show more clearly that the folds visible in the image do not result from the
- * mosaicking, we display the seams between the images in the mosaic image.
- * This can be done most easily by creating an image that contains the border
- * of the images, generating a mosaic from it, and segmenting the resulting
- * mosaic image.
- get_image_size (Image, Width, Height)
- gen_image_const (ImageBlank, 'byte', Width, Height)
- gen_rectangle1 (Rectangle, , , Height - , Width - )
- paint_region (Rectangle, ImageBlank, ImageBorder, , 'margin')
- gen_empty_obj (ImagesBorder)
- for J := to by
- concat_obj (ImagesBorder, ImageBorder, ImagesBorder)
- endfor
- gen_projective_mosaic (ImagesBorder, MosaicImageBorder, , From, To, ProjMatrices, 'default', 'false', MosaicMatrices2D)
- threshold (MosaicImageBorder, Seams, , )
- dev_clear_window ()
- dev_display (MosaicImage)
- disp_message (WindowHandle, 'Seams between the\nimages', 'window', , , 'black', 'true')
- dev_set_color ('yellow')
- dev_display (Seams)
- disp_message (WindowHandle, 'Click \'Run\'\nto continue', 'window', , , 'black', 'true')
- stop ()
- * If you look very closely at the projective mosaic above, you may note that
- * there is a very slight projective distortion in the mosaic. This happens
- * because the transformations cannot be determined with perfect accuracy
- * because of very small errors in the point coordinates due to noise. Because
- * of the strip configuration, essentially the overlapping area between the image
- * pairs can act like a hinge around which the images may rotate out of the image
- * plane. In this example, we know that the mapping between the images must
- * be a rigid transformation. If we want to force the transformation to be rigid
- * we can simply use bundle_adjust_mosaic.
- bundle_adjust_mosaic (, , From, To, ProjMatrices, Rows1, Cols1, Rows2, Cols2, NumMatches, 'rigid', MosaicMatrices2D, Rows, Cols, Error)
- * Now, we can generate the mosaic image from the rigid transformations.
- gen_bundle_adjusted_mosaic (Images, MosaicImageRigid, MosaicMatrices2D, 'default', 'false', TransMatrix2D)
- get_image_size (MosaicImageRigid, Width, Height)
- dev_set_window_extents (-, -, Width / , Height / )
- dev_clear_window ()
- dev_display (MosaicImageRigid)
- disp_message (WindowHandle, 'Rigid mosaic', 'window', , , 'black', 'true')
带逢合线的图像 找定位点
最终图像:
下面我们看一下另一个例程:
这个例程使用proj_match_points_ransac_guided 和 gen_projective_mosaic
主要介绍如何使用金字塔算法快速获取两个图像的特征点进行拼接。
- * This example program shows how images can be combined
- * into a mosaic image using proj_match_points_ransac_guided
- * and gen_projective_mosaic.
- * It is shown how the calculation of the projection between two
- * images can be accelerated using an image pyramid.
- *
- * Initializations
- ImgPath := '3d_machine_vision/mosaic/'
- ImgName := 'bga_r_'
- Times := []
- Colors := ['red','coral','yellow','lime green']
- read_image (Images, ImgPath + ImgName + ['',''])
- dev_update_off ()
- dev_close_window ()
- dev_open_window_fit_size (, , , , , , WindowHandle)
- dev_open_window_fit_size (, , , , , , WindowHandle1)
- set_display_font (WindowHandle, , 'mono', 'true', 'false')
- set_display_font (WindowHandle1, , 'mono', 'true', 'false')
- * The internal camera parameters of the used camera
- * (necessary to eliminate radial distortions)
- CamParam := [0.0121693,-2675.63,7.40046e-006,7.4e-006,290.491,258.887,,]
- change_radial_distortion_cam_par ('adaptive', CamParam, , CamParOut)
- change_radial_distortion_image (Images, Images, Images, CamParam, CamParOut)
- * To show the point matches that are used to compute the
- * transformation between the images, we will show both images in a
- * tiled image with some space between the images so that the extents
- * of the images are easily visible.
- tile_images_offset (Images, TiledImage, [,], [,], [-,-], [-,-], [-,-], [-,-], , )
- *
- * Now we can determine the transformations between the image pairs.
- From :=
- To :=
- select_obj (Images, ImageF, From)
- select_obj (Images, ImageT, To)
- *
- * Repeat the calculation times with a different number of pyramid levels
- for NumLevels := to by
- *
- dev_clear_window ()
- dev_set_window (WindowHandle)
- dev_clear_window ()
- dev_display (TiledImage)
- disp_message (WindowHandle, ['Calculate point matches','with ' + NumLevels + ' pyramid levels','Please wait ...'], 'window', , , 'black', 'true')
- *
- * Calculate the projection between the two images
- * Check the procedure's comments for details
- count_seconds (S1)
- proj_match_points_ransac_pyramid (ImageF, ImageT, NumLevels, RowFAll, ColFAll, RowTAll, ColTAll, ProjMatrix, Points1, Points2)
- count_seconds (S2)
- Times := [Times,S2 - S1]
- *
- * Display point correspondences
- gen_cross_contour_xld (PointsF, RowFAll, ColFAll, , rad())
- gen_cross_contour_xld (PointsT, RowTAll + , ColTAll, , rad())
- RowF := subset(RowFAll,Points1)
- ColF := subset(ColFAll,Points1)
- RowT := subset(RowTAll,Points2) +
- ColT := subset(ColTAll,Points2)
- gen_empty_obj (Matches)
- for K := to |RowF| - by
- gen_contour_polygon_xld (Match, [RowF[K],RowT[K]], [ColF[K],ColT[K]])
- concat_obj (Matches, Match, Matches)
- endfor
- dev_display (TiledImage)
- dev_set_color ('blue')
- dev_display (Matches)
- dev_set_color ('green')
- dev_display (PointsF)
- dev_display (PointsT)
- disp_message (WindowHandle, [|RowF| + ' point matches','Time used: ' + (S2 - S1)$'.3' + ' s'], 'window', , , 'black', 'true')
- *
- * Generate the mosaic image
- gen_projective_mosaic (Images, MosaicImage, , From, To, ProjMatrix, [,], 'false', MosaicMatrices2D)
- *
- * Display mosaic image
- get_image_size (MosaicImage, Width, Height)
- dev_set_window (WindowHandle1)
- dev_resize_window_fit_image (MosaicImage, , , [,], )
- dev_clear_window ()
- dev_display (MosaicImage)
- disp_message (WindowHandle1, 'Projective mosaic (used ' + NumLevels + ' pyramid levels)', 'window', , , 'black', 'true')
- disp_continue_message (WindowHandle1, 'black', 'true')
- stop ()
- endfor
- *
- * Display execution times
- dev_set_window (WindowHandle)
- dev_close_window ()
- MaxTime := max(Times)
- BaseRow :=
- RectHeight :=
- disp_message (WindowHandle1, ['Time in s:','(#levels used)'], 'image', BaseRow + , , 'black', 'true')
- for Index := to |Times| - by
- gen_rectangle1 (Rectangle, BaseRow - RectHeight * Times[Index] / MaxTime, + Index * , BaseRow, + Index * )
- disp_message (WindowHandle1, [Times[Index]$'.3','(' + (Index + ) + ')'], 'image', BaseRow + , + * Index, 'black', 'true')
- dev_set_color (Colors[Index])
- dev_set_draw ('fill')
- dev_display (Rectangle)
- endfor
- disp_finished_message (WindowHandle1, 'black', 'true')
Halcon一日一练:图像拼接技术2:步骤与例程的更多相关文章
- Halcon一日一练:读取文件目录图像的三种方法
第一种方法: 读了一个单一图像: read_image(Image,'fabrik') 这种方式可以快速的读取软件自身携带的库图像文件,系统设定了库图像映像文件的快速读取方式,我们也可以通过绝对地址的 ...
- Halcon一日一练:图像拼接技术
图像拼接技术就是针对同一场景的一系列图片,根据图片的特征,比如位置,重叠部分等,拼接成一张大幅的宽视角的图像. 图像拼接要求拼接后图像最大程度的与原图一致,失真尽可能的小,并且要尽量做到天衣无缝即没有 ...
- Halcon一日一练:图像设备介绍
Halcon在设计之初就提供了完整的图像采集方案,适应了多种图像设备采集图像,以及各种不同环境的采集方案. 通常情况下,图像的采集应该是所有机器视觉项目首要解决的任务,不幸的是,需要解决图像采集的问题 ...
- Halcon一日一练:创建三通道图像
首先理解一个什么是三通道图像: 三通道图像就是彩色图像,我们之前黑白相机或黑白电视机都是彩用的灰阶图像,即单通道图像,一般是2的8次方个灰阶,即256个灰阶.彩色图像采用RGB,红绿蓝三个通道来合成彩 ...
- Halcon一日一练:图像、变量实时更新
某些场合,我们需要刷新图像来识别图像处理过程的差异性,便于调试判断问题和预测.Halcon提供了图像刷新操作,这些操作不会改变程序的最终处理结果. 例程: **实时刷新图像 dev_update_wi ...
- Halcon一日一练:图像分辨率与像素
1.图像像素: 像素是指由图像的小方格即所谓的像素(pixel)组成的,这些小方块都有一个明确的位置和被分配的色彩数值,而这些一小方格的颜色和位置就决定该图像所呈现出来的样子.像素是构成图像的基本单元 ...
- Halcon一日一练:CAD类型的相关操作
大很多场合,需要在视觉程序中导入CAD文档,比如,在3C行业,需要对手机外壳进行CNC加工,或者点胶操作,此时,需要获取产品的各个点的数据.如果将CAD直接导入,就会大的减少编程工作量,同时也能达到很 ...
- Halcon一日一练:图像采集设备的基本参数
因操作图像处理之前,需要对图像进行采集.采集图像,我们首先要确定的是图像的像素和采集的效率.这些都需要对设备进行配置与操作.现实情况是图像设备有各自不同的采集方式,配置也各不相同.这就需要设备提供商提 ...
- Halcon一日一练:获取程序运行时间
很多时候,我们需要知道每个函数的运算周期,以提高程序的运行效率.知道运行时间对于图像算法处理很重要 Halcon提供相关的算子,我们先来看代码: **获取图像处理时间 read_image(Image ...
随机推荐
- Android + Eclipse + PhoneGap 环境配置
用了3天的时间,终于把环境搭建完毕,郁闷了N天,终于完成了.这里我只是讲述我安装的过程,仅供大家参考. 环境搭建首先要去下载一些安装包: (下载前注意一下,电脑是32位还是64位的请注意选择安装包) ...
- Angular 4 自定义组件封装遇见的一些事儿
你用Angular 吗? 一.介绍 说说封装Angular 组建过程中遇见的一些问题和感悟.用久了Angular,就会遇见很多坑,许多基于Angular开发的框架最喜欢做的事情就是封装组件,然后复用. ...
- Spring Boot实战:拦截器与过滤器
一.拦截器与过滤器 在讲Spring boot之前,我们先了解一下过滤器和拦截器.这两者在功能方面很类似,但是在具体技术实现方面,差距还是比较大的.在分析两者的区别之前,我们先理解一下AOP的概念,A ...
- Executors线程池
强烈建议程序员使用较为方便的 Executors 工厂方法 Executors.newCachedThreadPool()(无界线程池,可以进行自动线程回收).Executors.newFixedTh ...
- html动态生成的代码,绑定事件
如果使用jQuery,你可以这样写: // .class为你绑定事件的动态生成的结点 $(document).on('click', '.class', function() { // 你要绑定的事件 ...
- python_判断变量类型
需求: 已知有一个变量,我想对他进行预处理判断,如果这个变量是字符串,则在字符串后面加上后缀'_str',如果整形就让其加5,还比如我要求这个变量是整形或者字符串,都行 如何做? #!/usr/bin ...
- VMware PowerCLi 使用示例
这几天研究PowerCLI,积累了几个例子,记下来,以便以后或者大家使用.部分例子来着网络,具体出处参考附录 1 获取vm 磁盘 和磁盘对应的datastore的信息 这个例子可以针对一台虚机有多个磁 ...
- 通过脚本生成poco实体
今天在做开发时,需要把表映射成实体,又没有EF这种工具,就从网上下了一个工具,但使用时觉得太重了,所以就自己写了一个,基于mysql的. 功能:输入表名,得到这个表的poco实体 SELECT COL ...
- android 通过getDimension,getDimensionPixelOffset和getDimensionPixelSize获取dimens.xml文件里面的变量值
dimens.xml里写上三个变量: <dimen name="activity_vertical_margin1">16dp</dimen> <di ...
- 面向对象_06【抽象类:abstract、接口:interface、实现:implements】
抽象类:abstract抽象:没有足够的描述功能,事物不具体的描述,却又有共性. 特点: 1,方法只有声明没有实现时,该方法就是抽象方法,需要被abstract修饰,抽象方法必须定义在抽象类中,该类也 ...