前言
通常我们使用的相机都是带有一定的畸变的,只是畸变的大小不同。对于我们常见的测量项目来说,对测量精度的要求很高,通常从相机镜头上进行优化,但是即使镜头优化或者成本原因,造成图像仍有一定的畸变时,我们就可是使用棋盘格标定板,进行畸变矫正
1.程序
* Image Acquisition 01: Code generated by Image Acquisition 01
read_image (Image, 'C:/Users/1/Desktop/work/3.8/10.bmp')
*****************************标定矫正过程**************************************
WidthOfGrid := 0.17
NumSquares := 110
create_rectification_grid (WidthOfGrid, NumSquares, 'rectification_grid.ps')
MinContrast := 25
Radius := 10
find_rectification_grid (Image, GridRegion, MinContrast, Radius)
reduce_domain (Image, GridRegion, ImageReduced)
SigmaSaddlePoints := 2
Threshold := 3
saddle_points_sub_pix (ImageReduced, 'facet', SigmaSaddlePoints, Threshold, Row, Col)
gen_cross_contour_xld (SaddlePoints, Row, Col, 20, 1)
dev_display (Image)
dev_display (SaddlePoints)
SigmaConnectGridPoints := 0.9
MaxDist :=5
GridSpacing := 45
dev_set_color ('red')
connect_grid_points (ImageReduced, ConnectingLines, Row, Col, SigmaConnectGridPoints, MaxDist)
gen_grid_rectification_map (ImageReduced, ConnectingLines, Map, Meshes, GridSpacing,0, Row, Col, 'bilinear')
map_image (ImageReduced, Map, ImageMapped)
******************************************存储标定参数*****************
write_image (Map, 'tiff', 0, 'C:/Users/1/Desktop/work/3.8/calib.tiff')
read_image (Map, 'C:/Users/1/Desktop/work/3.8/calib.tiff')
***************************************读取图像测试***********************
read_image (Image, 'C:/Users/1/Desktop/work/3.8/2.bmp')
map_image (Image, Map, ImageMapped)
2.采集标定图像
此次使用激光雕刻的棋盘格,单个格子长宽2mm,图像采集像素值为单格43像素。
标定前,可以根据所需要的视野大小进行标定,当然最佳的方式是标定板应该大于视野范围,以确定边缘畸变的量,同时标定板应该摆放正,如果没有摆放正的情况会出现矫正图像有倾斜的现象。
3.裁剪标定板区域
*实际棋盘格宽度
WidthOfGrid := 0.3
*棋盘格单向数量
NumSquares := 110
*创建标定板
create_rectification_grid (WidthOfGrid, NumSquares, 'rectification_grid.ps')
*最小二值化的值
MinContrast := 25
Radius := 10
find_rectification_grid (Image, GridRegion, MinContrast, Radius)
reduce_domain (Image, GridRegion, ImageReduced)
4.提取网格
*提取每个网格的交点
*预设参数一般不需要修改。但是需要保证每个格子与格子间的角都要找到,哪里没找到,哪里就会矫正缺损
SigmaSaddlePoints := 2
Threshold := 3
saddle_points_sub_pix (ImageReduced, 'facet', SigmaSaddlePoints, Threshold, Row, Col)
gen_cross_contour_xld (SaddlePoints, Row, Col, 20, 1)
dev_display (Image)
dev_display (SaddlePoints)
*生产网格线
SigmaConnectGridPoints := 0.9
MaxDist :=5
*设置矫正后的单个像素值
GridSpacing := 43
dev_set_color ('red')
connect_grid_points (ImageReduced, ConnectingLines, Row, Col, SigmaConnectGridPoints, MaxDist)
gen_grid_rectification_map (ImageReduced, ConnectingLines, Map, Meshes, GridSpacing,0, Row, Col, 'bilinear')
*矫正图像
map_image (ImageReduced, Map, ImageMapped)
注意:当棋盘格上有细小的污点时,会严重影响实际的畸变矫正的效果,所以采集到图像时,需要使用PS或者画图软件将污点去除,在进行运算
5.保存矫正数据和验证
5.1保存数据
******************************************存储标定参数*****************
write_image (Map, 'tiff', 0, 'C:/Users/1/Desktop/work/3.8畸变矫正/calib.tiff')
read_image (Map, 'C:/Users/赵伟/Desktop/work/3.8畸变矫正/calib.tiff')
***************************************读取图像测试***********************
read_image (Image, 'C:/Users/1/Desktop/work/3.8畸变矫正/2.bmp')
map_image (Image, Map, ImageMapped)
5.2验证数据
使用标定板随机重新防止。
然后使用测量助手对中心和边缘的棋盘格的像素进行提取
选取矫正后的图像的中心区域的格子,与边缘区域的格子对比实际距离大小,误差小于0.3像素则代表矫正成功
6.注意事项
1:矫正参数仅适用于,当前高度,焦距,相机,采集到的图像。
2:输入的标定棋盘格图像一定不能存在污点,当有污点时,适用PS或者画图工具手动去除
3:标定板需要摆放正确方向,当矫正后,图像将自动矫正为水平方向,如果标定板摆放不水平时,会出现矫正图像倾斜的情况。