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 ...
随机推荐
- 【开发技术】java+mysql 更改表字段的步骤
1).首先通过SQL更改MYSQL库中的表结构(下面是一些例子) ALTER TABLE `illegalactivate` ADD `macethaddress` varchar(250) NOT ...
- NSString拼接字符串
NSString* string; // 结果字符串 02 NSString* string1, string2; //已存在的字符串,需要将string1和string2连接起来 03 04 / ...
- JAVA BASE64
Base64编码说明: Base64编码要求把3个8位字节(3*8=24)转化为4个6位的字节(4*6=24),之后在6位的前面补两个0,形成8位一个字节的形式. 如果剩下的字符不足3个字节, ...
- CCF系列之最优灌溉(201412-4)
试题编号:201412-4试题名称:最优灌溉时间限制: 1.0s内存限制: 256.0MB 问题描述 雷雷承包了很多片麦田,为了灌溉这些麦田,雷雷在第一个麦田挖了一口很深的水井,所有的麦田都从这口井来 ...
- jQuery hover() 方法
$("p").hover(function(){ $("p").css("background-color","yellow&qu ...
- python_如何定义装饰器类?
案例: 实现一个能将函数调用信息记录到日志的装饰器 需求: 把每次函数的调用时间,执行时间,调用次数写入日志 可以对被装饰函数分组,调用信息记录到不同日志 动态修改参数,比如日志格式 动态打开关闭日志 ...
- myeclipse环境搭建
公司来了几个新人,老是在教他们环境搭建这些,每次在帮他们调试代码的时候老是不厌其烦的看着他们坐等myeclipse编译了,校验了什么的,而且在编码的时候也不使用快捷键,然后我就只能默默的坐回去了.为了 ...
- 微信H5支付网络环境未能通过安全验证,请稍后再试(获取终端ip )
在写微信H5支付的时候需要获取终端IP使用官方的方法是不对的报错如下: 故重写一个:如下 function get_client_ip(){ if(getenv('HTTP_CLIENT_IP') & ...
- Docker for Web Developers目录
在OpenStack在私有云占主导定位之后,后起之秀Docker在PaaS平台.CI/CD.微服务领域展露锋芒.作为Web Developers,我们有必要学习和掌握这门技术. 1. 运行第一个Doc ...
- Go语言学习索引
<Go并发编程实战>示例项目 项目地址: https://github.com/hyper-carrot/goc2p 项目安装: 用git clone获取项目,并将其根目录作为一个工作区. ...