前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Camera Calibration 摄像头标定

Camera Calibration 摄像头标定

原创
作者头像
vanguard
修改2020-03-06 18:46:05
1.3K0
修改2020-03-06 18:46:05
举报
文章被收录于专栏:vanguard

cv2.cameraCalibration

Pinhole camera calibration calls camera vision from 3D objects in the real world and transforms them into a 2D image.

摄像头标定这里指利用常规(小孔成像)摄像头观察真实三位物体对二维图像的矫正转换。

We named points from objects as objects point and points in image as image points.

3D的点被叫做物体点,而2D的图像点被叫做图像点。

To calibrate camera, we need to undistort radial distortion and tangential distortion.

Radial Distortion: Radial Distortion is the most common type that affects the images, In which when a camera captured pictures of straight lines appeared slightly curved or bent.

Tangential distortion: Tangential distortion occurs mainly because the lens is not parallely aligned to the imaging plane, that makes the image to be extended a little while longer or tilted, it makes the objects appear farther away or even closer than they actually are.

摄像头标定矫正主要解决径向畸变和切向畸变。

径向畸变是图像像素点以畸变中心为中心点,沿着径向产生的位置偏差,从而导致图像中所成的像发生形变。

图像径向畸变是成像过程中最主要的畸变,同时也是对成像效果影响最大的畸变,广角或者鱼眼的畸变效果,

矫正算法采用多项式拟合:

切向畸变,这是由于透镜与成像平面不可能绝对平行造成的。

这种畸变会造成图像中的某些点看上去的位置会比我们认为的位置要近一些。

Five Distortion Coefficients 五个畸变系数:

In math, the Transformation from 3D object points, P of X, Y and Z to X and Y is done by a transformative matrix called the camera matrix(C), we’ll be using this to calibrate the camera.

max = 摄像机矩阵 = 摄像机的内部参数(焦距和光学中心) 内部参数是摄像机本身具有的,包括的信息有焦距(f x ,f y ),光学中心(c x ,c y )。

dist = 外部参数(旋转和变换向量)

外部参数与旋转和变换向量相对应,它可以将 3D 点的坐标转换到坐标系统中。

It’s recommended to use at least 20 images to get a reliable calibration, For this, we have a lot of images here, each chess board has eight by six corners to detect

于是必须要提供一些包含明显图案模式的样本棋盘图片,一般至少需要 10 个(部分中文资料)建议20个这样的图案模式。

or

where

(X, Y, Z) are the coordinates of a 3D point in the world coordinate space

(u, v) are the coordinates of the projection point in pixels

A is a camera matrix, or a matrix of intrinsic parameters

(cx, cy) is a principal point that is usually at the image center

fx, fy are the focal lengths expressed in pixel units.

A chessboard is great for calibration because it's regular, high contrast pattern makes it easy to detect automatically. And we know how an undistorted flat chessboard looks like. So, if we use our camera to take pictures of Chessboard at different angles

棋盘主要是通过角点来计算畸变,

代码语言:python
代码运行次数:0
复制
import numpy as np
import cv2, glob
calibrate_source_path = './data/camera_cal/*.jpg'
calibrate_test_path = './data/test_image.jpg'
# define
objpoints = []
imgpoints = []
nx = 8
ny = 6
objp = np.zeros((ny*nx,3),np.float32)
objp[:,:2] = np.mgrid[0:nx,0:ny].T.reshape(-1,2) 
# chessboard
for path in glob.glob(calibrate_source_path):
 gray = cv2.cvtColor(cv2.imread(path),cv2.COLOR_BGR2GRAY)
 ret,corners = cv2.findChessboardCorners(gray,(nx,ny))
 if ret: 
 objpoints.append(objp)
 imgpoints.append(corners);
 # gray = cv2.drawChessboardCorners(gray, (nx,ny), corners, ret)
# execute
img = cv2.imread(calibrate_test_path)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img.shape[1:], None, None)
dst = cv2.undistort(img, mtx, dist, None, mtx)
# display
cv2.imshow(None, cv2.pyrDown(np.hstack((img,dst))))
cv2.waitKey(0); cv2.destroyAllWindows()

my result was not as good as this image since the chessboard data

我的测试结果不如这个效果好,应该是我棋盘数据的问题

Reference:

https://medium.com/analytics-vidhya/camera-calibration-with-opencv-f324679c6eb7

https://blog.csdn.net/u011808673/article/details/80910252

https://blog.csdn.net/qq_37972112/article/details/96160034

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
图像处理
图像处理基于腾讯云深度学习等人工智能技术,提供综合性的图像优化处理服务,包括图像质量评估、图像清晰度增强、图像智能裁剪等。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档