halcon 图像拼接

本文详细介绍了一种使用Halcon库进行图像拼接的技术,包括读取图像、特征点提取、利用金字塔结构进行特征匹配、投影变换计算以及最终的图像拼接展示。此过程涉及到图像金字塔、RANSAC算法、Harris角点检测等关键技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主程序 

read_image (Pingjie1, 'E:/PingJie1.bmp')

read_image (Pingjie2, 'E:/PingJie2.bmp')
concat_obj(Pingjie1, Pingjie2, images)
* 
* Now we can determine the transformations between the image pairs.
From := 1
To := 2
select_obj (images, ImageF, From)
select_obj (images, ImageT, To)
    count_seconds (S1)

*计算量幅图像的特征点
    proj_match_points_ransac_pyramid (ImageF, ImageT, 1, RowFAll, ColFAll, RowTAll, ColTAll, ProjMatrix, Points1, Points2)
    count_seconds (S2)
    * 
    * Generate the mosaic image

*通过两幅图像的特征点 拼接图像
    gen_projective_mosaic (images, MosaicImage, 1, From, To, ProjMatrix, [2,1], 'false', MosaicMatrices2D)
    * 
    * Display mosaic image
    get_image_size (MosaicImage, Width, Height)
    dev_clear_window ()
    dev_display (MosaicImage)

过程 proj_match_points_ransac_pyramid  是halcon的一个内部过程

* This procedure uses an image pyramid to calculate
* the projective transformation between two images.
* 
* If UseRigidTransformation is set to true,
* the results are restricted to rigid transformations
* (instead of projective transformations)
UseRigidTransformation := true
* Parameters for the Harris point detector
SigmaGrad := 0.7
SigmaSmooth := 2
Alpha := 0.04
Threshold := 50
* 
* Generate image pyramids for both input images
gen_gauss_pyramid (ImageF, ImageFPyramid, 'constant', 0.5)
gen_gauss_pyramid (ImageT, ImageTPyramid, 'constant', 0.5)
* At the beginning, no approximated projection is known
HomMat2DGuide := []
* 
* Calculate projective transformation on each pyramid level
for Level := NumLevels to 1 by -1
    * Select images from image pyramid
    select_obj (ImageFPyramid, ImageFLevel, Level)
    select_obj (ImageTPyramid, ImageTLevel, Level)
    * Extract interest points in both images
    points_harris (ImageFLevel, SigmaGrad, SigmaSmooth, Alpha, Threshold, RowsF, ColsF)
    points_harris (ImageTLevel, SigmaGrad, SigmaSmooth, Alpha, Threshold, RowsT, ColsT)
    * Calculate projection from point correspondences
    if (|HomMat2DGuide| = 0)
        * On the highest pyramid level, use proj_mathc_points_ransac
        get_image_size (ImageFLevel, Width, Height)
        proj_match_points_ransac (ImageFLevel, ImageTLevel, RowsF, ColsF, RowsT, ColsT, 'ncc', 10, 0, 0, Height, Width, [rad(-40),rad(40)], 0.5, 'gold_standard', 2.5*pow(2,4-Level), 42, ProjMatrix, Points1, Points2)
    else
        * On lower levels, use approximation from upper level as
        * input for proj_match_points_ransac_guided
        proj_match_points_ransac_guided (ImageFLevel, ImageTLevel, RowsF, ColsF, RowsT, ColsT, 'ncc', 10, HomMat2DGuide, 10*pow(2.0,4.0-Level), 0.5, 'gold_standard', 2.5*pow(2.0,4.0-Level), 42, ProjMatrix, Points1, Points2)
    endif
    if (UseRigidTransformation)
        * Use found point correspondences to calculate rigid transformation
        * with vector_to_rigid
        * Note, that the resulting transformation of proj_match_points_ransac_guided
        * is ignored in this case.
        RowF := subset(RowsF,Points1)
        ColF := subset(ColsF,Points1)
        RowT := subset(RowsT,Points2)
        ColT := subset(ColsT,Points2)
        vector_to_rigid (RowF+0.5, ColF+0.5, RowT+0.5, ColT+0.5, ProjMatrix)
        ProjMatrix := [ProjMatrix,0,0,1]
    endif
    * To be used on the next lower pyramid level, the projection has
    * to be adjusted to the new scale.
    hom_mat2d_scale_local (ProjMatrix, 0.5, 0.5, HomMat2DGuide)
    hom_mat2d_scale (HomMat2DGuide, 2, 2, 0, 0, HomMat2DGuide)
endfor
return ()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值