主程序
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 ()