首页 > 编程知识 正文

图像拼接算法原理,图像拼接

时间:2023-05-03 14:54:24 阅读:143591 作者:2480

一、图像拼接的大致步骤如下。1.读取图像 --read_image()

2.提取图像特征点 --points_foerstner()

3.构建投影矩阵(可选忽略径向扭曲或消除径向扭曲[radial distortion])

----proj_match_points_distortion_ransac()

4.生成拼接图像 ---gen_projective-mosaic()

*5.显示拼接线 ---projective_trans_pixel()

---gen_contour_polygon_xld()

该例程是根据图像的特征点对图像进行拼接,需要获取两幅图像的特征点。

什么是特征点? 根据算子points_foerstner的解释,特征点有两种,一种是类名为交点特征点,指向这些图像的边缘点,另一种称为区域特征点,例如图像的颜色和亮度与周围不同。

* thisexampleshowshowtouseproj _ match _ points _ distortion _ ran sacto * matchtwoimagesinamosaickingapplication.* * in readanddisplaytheimagesread_image (image1,' mosaic/building_01 ' ) read _ image ) ) imager ' mosaic/bubuilding Height ) dev_close_window ) dev _ open _ windows windowhandle (set _ display _ font ) window handle,16,' mono ' mono ' ' window ',12,12,' black ',' true ' ) disp _ continue _ message (window handle,' black ',' true ' stop ) ) dev ' true ' ) disp _ continue _ message (window handle,' black ',' true ' ) stop (* * extractpointstobematchedfromtheimaged CoRRJunctions,CoRCJunctions,CoCCJunctions,RowArea,ColumnArea,CoRCArea,CoRCArea ) points _ foerstner () CoRCJunctions、CoCCJunctions、RowArea、ColumnArea、CoRRArea、CoRCArea、 coccarea * * wewillfirstperformanormalprojectivematchingthatdoesnottake * theradialdistortionsintoaccounttoshowtheerrrrrorsthatatttttaroke byneglectingtheradialdistortions.*特征点相关投影矩阵proj _ match _ points _ ran sac (image1、Image2、Rows1、Columns1、Rows2、cccord HomMat2DUnrectified,Points1Unrectified,Points2Unrectified ) * constructaprojectivemosaicfromthetwounrectifiedima

ges.concat_obj (Image1, Image2, Images)*生成投射之后的拼接图象-MosaicImageUnrectifiedgen_projective_mosaic (Images, MosaicImageUnrectified, 1, 1, 2, HomMat2DUnrectified, 'default', 'false', MosaicMatrices2DUnrectified)* * Display unrectified resultsget_image_size (MosaicImageUnrectified, Width, Height)dev_set_window_extents (-1, -1, Width, Height)dev_clear_window ()dev_display (MosaicImageUnrectified)* Display seam line --展示拼接处的线条projective_trans_pixel (MosaicMatrices2DUnrectified[9:17], [0,493], [0,0], RowTrans, ColumnTrans)gen_contour_polygon_xld (Contour, RowTrans, ColumnTrans)set_line_style (WindowHandle, [1,5])dev_set_line_width (1)dev_set_color ('yellow')dev_display (Contour)set_line_style (WindowHandle, [])dev_set_draw ('margin')dev_set_color ('red')dev_set_line_width (3)gen_circle (Circle, [82,402], [228,223], [15,15])dev_display (Circle)Message := 'The mosaic image does not fit'Message[1] := 'perfectly, if radial distortions'Message[2] := 'are not taken into account.'disp_message (WindowHandle, Message, 'image', 200, 300, 'black', 'true')disp_continue_message (WindowHandle, 'black', 'true')stop ()* * Now, we will perform a projective matching that takes the radial* distortions into account.get_image_size (Image1, Width, Height)proj_match_points_distortion_ransac (Image1, Image2, Rows1, Columns1, Rows2, Columns2, 'ncc', 10, 0, 0, Height, Width, 0, 0.5, 'gold_standard', 1, 42, HomMat2D, Kappa, Error, Points1, Points2)* Construct camera parameters for the purpose of rectifying the images,* i.e., to remove the radial distortions.gen_cam_par_area_scan_telecentric_division (1.0, Kappa, 1.0, 1.0, 0.5 * (Width - 1), 0.5 * (Height - 1), Width, Height, CamParDist)* Remove the radial distortions from the images.change_radial_distortion_cam_par ('fixed', CamParDist, 0, CamPar)change_radial_distortion_image (Image1, Image1, Image1Rect, CamParDist, CamPar)change_radial_distortion_image (Image2, Image2, Image2Rect, CamParDist, CamPar)* Construct a mosaic from the two rectified images. Note that the images* fit together perfectly.concat_obj (Image1Rect, Image2Rect, ImagesRect)gen_projective_mosaic (ImagesRect, MosaicImage, 1, 1, 2, HomMat2D, 'default', 'false', MosaicMatrices2D)* * Display rectified resultsget_image_size (MosaicImage, Width, Height)dev_set_window_extents (-1, -1, Width, Height)dev_clear_window ()dev_display (MosaicImage)* Display seam lineprojective_trans_pixel (MosaicMatrices2D[9:17], [0,493], [0,0], RowTrans, ColumnTrans)gen_contour_polygon_xld (Contour2, RowTrans, ColumnTrans)set_line_style (WindowHandle, [1,5])dev_set_line_width (1)dev_set_color ('yellow')dev_display (Contour2)set_line_style (WindowHandle, [])dev_set_draw ('margin')dev_set_color ('green')dev_set_line_width (3)gen_circle (Circle, [124,496], [244,239], [15,15])dev_display (Circle)Message := 'The mosaic image fits perfectly,'Message[1] := 'if radial distortions are taken'Message[2] := 'into account.'disp_message (WindowHandle, Message, 'image', 200, 300, 'black', 'true')

仔细观察图像拼接之后的接缝处,发现拼接的效果并不理想,接缝是错开的。原因是两张图像的径向畸变造成的。何为径向畸变?这是所有镜头固有的,当焦距很大或很小时,拍出的图像尤其明显,图像的边缘处向前凹,或者向里凸的效果,仔细观察原来的两张图像,边缘处是向里凸进去的。

*设置相机参数以消除图像 radial-distortiongen_cam_par_area_scan_telecentric_division (1.0, Kappa, 1.0, 1.0, 0.5 * (Width - 1), 0.5 * (Height - 1), Width, Height, CamParDist)* 如下为消除图像的径向扭曲现象change_radial_distortion_cam_par ('fixed', CamParDist, 0, CamPar)change_radial_distortion_image (Image1, Image1, Image1Rect, CamParDist, CamPar)change_radial_distortion_image (Image2, Image2, Image2Rect, CamParDist, CamPar)

★★★这里上下是重点!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

相机内外参数知识恶补:

f【Focus】:相机的主矩,即焦距。
k【Kappa】:径向扭曲的大小,即径向畸变,一般不考虑切向畸变。
sx,sy:图像传感器在水平和垂直方向上相邻像素之间的距离。
cx,cy: 投影中心在成像平面的垂直投影。

==>时刻铭记相机的内外参数是相机标定的重点。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。