Halcon算子笔记2__通过proj_match_points_ransac和gen_projective_mosai
时间:2026-01-24
时间:2026-01-24
在halcon学习过程中,针对例程进行逐一解析。Halcon算子笔记2__通过proj_match_points_ransac和gen_projective_mosaic来实现图像拼接
40、gen_projective_mosaic.hdev:图像拼接,使用proj_match_points_ransac和gen_projective_mosaic。* This example program shows how several images of a PCB can be combined into a large mosaic image of the PCB. The program shows how to use proj_match_points_ransac and gen_projective_mosaic to achieve this. Please note that the PCB has some degradations on its surface, which looklike folds and may easily be mistaken as the seams between the images in the mosaic image. To show that this is not the case, the program also displays the true seams of the mosaic image.
*此示例程序显示了PCB的几个图像如何组合成PCB的大型镶嵌图像。该程序显示如何使*用proj_match_points_ransac和gen_projective_mosaic来实现这一点。请注意,印刷电路板*的表面有一些退化,看起来像褶皱,很容易被误认为马赛克图像中的图像之间的接缝。为*了表明情况并非如此,程序还显示了马赛克图像的真实接缝。
dev_update_off ()
*关闭更新
dev_close_window ()
*关闭窗口
dev_open_window (0, 0, 640, 480, 'white', WindowHandle)
*创建窗口
dev_set_color ('green')
*设置显示颜色为绿色
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*设置窗口内字体几大小
* Read in the images and show them one-by-one. Please not the fold-like degradations running across the PCB.
*读图像并逐一显示。请不要在意PCB板上的褶皱状退化。
gen_empty_obj (Images)
创建一个空的目标元组。
for J := 1 to 6 by 1
read_image (Image, 'mosaic/pcb_'+J$'02')
*依次读取图像
concat_obj (Images, Image, Images)
*把两个图像数组合并在一起
dev_display (Image)
*显示图像
disp_message (WindowHandle, 'Image '+J$'d', 'image', -1, -1, 'black', 'true')
*显示读取图像的进度
wait_seconds (1)
*等待1秒
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.
在halcon学习过程中,针对例程进行逐一解析。Halcon算子笔记2__通过proj_match_points_ransac和gen_projective_mosaic来实现图像拼接
*为了显示用于计算图像之间的投影变换的点匹配,我们在大平铺图像的所有图像与图像之*间留了一些空间,这样更容易看清楚没个图像的范围。
dev_set_window_extents (-1, -1, 640/4, 2980/4)
*改变一个图形窗口的位置和大小
tile_images_offset (Images, TiledImage, [0,500,1000,1500,2000,2500], [0,0,0,0,0,0], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], [-1,-1,-1,-1,-1,-1], 640, 2980)
*简单拼图
dev_clear_window ()
*清除活动图像窗口
dev_display (TiledImage)
*显示图像
disp_message (WindowHandle, 'All 6 images', 'window', 12, 12, 'black', 'true')
*显示读取全部图像的消息
disp_message (WindowHandle, 'Click \'Run\'\nto continue', 'window', 2980/4-50, 12, '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+1). 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.
*现在我们计算五对图像之间的点匹配,并用这个图像对之间的投影变换。请注意,以下代*码将为每个图像对调用点运算符。由于图像形成一个条带,稍微保留一点,我们可以通过*保存最后一次迭代的点(J对中的ImageT将与J + 1对中的ImageF相同)使得处理更有效*率。这不是在这里完成的,因为这样的优化在一般情况下是非常麻烦的,即图像可能处于*一个不能用条表示的一般配置。
dev_clear_window ()
*清除活动图像窗口
dev_display (TiledImage)
*显示图像
disp_message (WindowHandle, 'Point matches', 'window', 12, 3, 'black', 'true')
*显示点匹配的消息
* We define the image pairs, i.e., which image should be mapped to which image.
*定义图像对,即,所述图像应该被映射到哪个图像。
From := [1,2,3,4,5]
To := [2,3,4,5,6]
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.
在halcon学习过程中,针对例程进行逐一解析。Halcon算子笔记2__通过proj_match_points_ransac和gen_projective_mosaic来实现图像拼接
*此外,由于我们要在下面创建一个严格的马赛克,我们需要累积所有的点对应关系和每个*图像对 …… 此处隐藏:8308字,全部文档内容请下载后查看。喜欢就下载吧 ……
上一篇:常微分方程计算题(3)