| by msbeta | 1 comment

车道线识别-相机校正(Camera Calibration)

1.准备

这里使用OpenCV提供的棋盘格方法进行标定。在黑白相间的棋盘格上,二维图像的角点很容易通过角点检测找到,而棋盘格标定板的方块尺寸和放置位置是已知的。因此可以通过不同角度的Camera图片标定相机的参数。

标定板示例,图片来源【2】

获取不同角度的标定图像:

图片来源【2】

2. 相机标定(Camera Calibration)

OpenCv的cv2.findChessboardCorners()可以检测棋盘格图片的内角点,它的输入是棋盘格的灰度(grayscale)图片和棋盘格内角点的个数,输出就是棋盘格的内角点坐标。

def get_obj_img_points(images,grid=(9,6)):
    object_points=[]
    img_points = []
    for img in images:
        #生成object points
        object_point = np.zeros( (grid[0]*grid[1],3),np.float32 )
        object_point[:,:2]= np.mgrid[0:grid[0],0:grid[1]].T.reshape(-1,2)
        #得到灰度图片
        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        #得到图片的image points
        ret, corners = cv2.findChessboardCorners(gray, grid, None)
        if ret:
            object_points.append(object_point)
            img_points.append(corners)
    return object_points,img_points

计算得到棋盘格的内角点(Image Points)之后,再结合已知的实际棋盘格角点坐标(Object Points),就可以使用cv2.calibrateCamera计算出相机校正矩阵(Camera Calibration Matrix)、失真系数(Distortion Coefficients)等;再使用 cv2.undistort()方法就可得到校正后的图片。

def cal_undistort(img, objpoints, imgpoints):
    ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img.shape[1::-1], None, None)
    dst = cv2.undistort(img, mtx, dist, None, mtx)
    return dst
图片来源【1】

3. 校准测试图片

#获取棋盘格图片
cal_imgs = utils.get_images_by_dir('camera_cal')
#计算object_points,img_points
object_points,img_points = utils.calibrate(cal_imgs,grid=(9,6))
#获取测试图片
test_imgs = utils.get_images_by_dir('test_images')

#校正测试图片
undistorted = []
for img in test_imgs:
    img = utils.cal_undistort(img,object_points,img_points)
    undistorted.append(img)

校准前后图片对比效果:

图片来源【1】

再放两张对比高清大图。

图像校准前
图像校准后

参考材料

1.https://github.com/yang1688899/CarND-Advanced-Lane-Lines
2.https://blog.csdn.net/u010128736/article/details/52875137

1 Comment

Franklyn

2020年10月17日 at 上午10:27 回复

Could you ask her to call me? libinex
Broader demonstrations against Prime Minister Tayyip Erdoganthis summer have resurfaced again in recent days, including inat least two Alevi districts of Istanbul. Protests have alsoerupted in Hatay province, an ethnic and religious melting potright on the southern border with Syria.

发表评论