openCV study-Moudle4_摄像机的标定与3D重构

 

REF:


 3D points are called object points (物体坐标) and 2D image points are called image points.(图像坐标)


畸变(径向,切向)

  • 针孔相机 有个缺陷,主要考虑径向畸变,离镜头中心越远越明显,直线变成曲线。

如何数学建模畸变呢?

输入:未畸变的像素的坐标(x,y) 半径r=sqrt(x^2+y^2)

输出:畸变后的坐标 (测量直接获得)

模型参数: k1,k2,k3 ?,notes:3阶,当然也可以更精准,四阶,5阶--实际上是泰勒级数展开。一般3阶够了

通过至少3组方程获得 k1,k2,k3. 推荐多一些点,然后运用最小二乘法,获得最优的畸变方程参数

输入未畸变的绝对坐标(先验测得-chessboard), 输出:图片中的坐标(测得),求出模型参数。

notes: 标定时,标定板的摆放。标定板的原点(0,0)和镜头的中心(0,0)对齐。Z轴=0, XY 平面尽可能和镜头XY 平面平行(肯定会有误差,尽可能做到最小)

We know its coordinates in real world space and we know its coordinates in image!

应用时: 已知输出的畸变坐标,反求未畸变的坐标。(去畸变的过程)

  • 切向畸变

产生原因:安装时,镜头和成像平面不平行(z-axis)),导致物体的有些点,离摄像机偏近或偏远。

有2个参数

合并起来,我们一共有5个参数: 


内参Intrinsic

focal length ( fx,fy),optical centers ( cx,cy) ,

内参矩阵:


外参Extrinsic 

R|t  旋转和平移矩阵

For stereo applications, these distortions need to be corrected first. why ?

distord correction points(u',v')--distortion----> un-distord (u,v)--> intrinsic-->extrinsic-->object points (x,y,z=0)


合并起来:

物理坐标系(X,Y,Z=0)--[R|t] --->相机坐标---[内参,投影+平移]-理想的像素 points[u,v]-- [畸变方程]-->畸变坐标[u',v']

一次性获得全部的矩阵参数。 利用极大似然估计, 是一种估计总体未知参数的方法。它主要用于点估计问题。所谓点估计是指用一个估计量的观测值来估计未知参数的真值。说穿了就一句话:就是在参数空间中选取使得样本取得观测值的概率最大的参数

参考:张正友的论文(OPENCV 也是参考他),4,5 合并变成一步

https://www.cnblogs.com/wangguchangqing/p/8335131.html

https://blog.csdn.net/qq_37059483/article/details/79481014

https://blog.csdn.net/qq_37059483/article/details/79482541

CV_Lesson42_摄像头标定.py

Steps:

1.先准备2个数组,分别用来存储 物理世界的坐标和图像的坐标

2.运用harris 角点检测(集成到了专门找chessboarad的API 中)-findChessboardCorners ,然后提高精度,找亚像素,运用-cornerSubPix, 获得了图像的角点坐标, 一样对应已知的物理坐标( 按照一定顺序排列的,比如7*6,从(0,0)开始)

3. 运用坐标对,放入cv2.calibrateCamera, 最大释然估计出所有参数(内参,外参,畸变) ,(点对越多越精确,推荐10对以上)

double cv::calibrateCamera	(	InputArrayOfArrays 	objectPoints,
InputArrayOfArrays 	imagePoints,
Size 	imageSize,
InputOutputArray 	cameraMatrix,
InputOutputArray 	distCoeffs,
OutputArrayOfArrays 	rvecs,
OutputArrayOfArrays 	tvecs,
OutputArray 	stdDeviationsIntrinsics,
OutputArray 	stdDeviationsExtrinsics,
OutputArray 	perViewErrors,
int 	flags = 0,
TermCriteria 	criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) 
)	

4. 运用获得的畸变参数,把image图片去除畸变


姿态估计: pose estimation

CV_Lesson43_姿态估计.py

input >先验的已知信息相机的内参,畸变(标定获得),物体的坐标(演示用了已知的标定板坐标 ),图像的坐标

不同的摄像机拍摄角度, 通过解PNP(3D-2D 投影解的唯一性) 问题得到不同的外参。已知物体的姿态固定(标定板Z=0) ,
 得到摄像头的姿态,反之,摄像头的姿态固定,(以摄像头为坐标原点),

output> 物体的姿态(外参R|t)就可以估算了。

实际应用时> 物体的坐标如何获得? --需要Deep dive

Finds an object pose from 3D-2D point correspondences using the RANSAC scheme.

§ solvePnPRansac()
bool cv::solvePnPRansac	(	
InputArray 	objectPoints,
InputArray 	imagePoints,
InputArray 	cameraMatrix,
InputArray 	distCoeffs,
OutputArray 	rvec,
OutputArray 	tvec,
bool 	useExtrinsicGuess = false,
int 	iterationsCount = 100,
float 	reprojectionError = 8.0,
double 	confidence = 0.99,
OutputArray 	inliers = noArray(),
int 	flags = SOLVEPNP_ITERATIVE 
)		

pose_1.jpg

pose_2.jpg


对极几何 Epipolar Geometry---

QOO' 对极平面

è¿éåå¾çæè¿°

原理分析:

SLAM入门之视觉里程计(3):两视图对极约束 基础矩阵

https://blog.csdn.net/u012936940/article/details/80723609 

''OPENCV"

 Essential Matrix contains the information about translation and rotation, which describe the location of the second camera relative to the first in global coordinates , 两个相机之间的相对位姿 R|t  ,如果是双目相机,水平对齐的(共面, R=0)只有t--baseline 已知。不需要求解。 特征点匹配就逐行, 算法复杂度大幅降低。

 Fundamental Matrix F, maps a point in one image to a line (epiline) in the other image ( E*内参K)

< A minimum of 8 such points are required to find the fundamental matrix (while using 8-point algorithm). More points are preferred and use RANSAC to get a more robust result.>

 

对极几何及单应矩阵

CV_Lesson44_对极几何_双目摄像机.py-- SIFT 有问题--代码没问题,只是找不到匹配点,所以报错,SIFT 的API 参数说明信息太少。不知道怎么调整。

CV_Lesson44_对极几何_双目摄像机ORB.py ---ok

点,


Stereo 双目相机测距--depth imgage

学习如何双目标定 TBC

y轴方向,(如果相机垂直放置)-y轴方向就有视差

水平放置的镜头,x方向有视差

原理分析:

已知双目相机水平放置

运用相似三角形,先考虑横坐标

消掉:物体的世界横坐标X, 分子分母同时相减

, 越远,视差越小,所有,双目测距,也是有距离限值。可能80开外置信度也掉的比较多。

焦距越大,看的越远。景深越深。

有个问题,

如果双目的焦距f不同,---> 双目测距希望镜头参数越接近,越容易CV 处理。不同的话,无法逐行比较特征点了,可能长焦镜头有的点包含在广角镜头的图片中(广角有的点,长焦没有)。具体解决方法TBD,市面上有用3个不同的前视摄像头的。ZF, Nio ...

想了一下,也是可以求得的,只是特征点难(尺度不同),精度也不一定好。解不完全。!

理论:

x and x′ are the distance between points in image plane corresponding to the scene point 3D and their camera center. B is the distance between two cameras (which we know) and f is the focal length of camera (already known).

static Ptr<StereoBM> cv::StereoBM::create	(	int 	numDisparities = 0,
int 	blockSize = 21 
)		
static
Creates StereoBM object.

Parameters
numDisparities	the disparity search range. For each pixel algorithm will find the best disparity from 0 (default minimum disparity) to numDisparities. The search range can then be shifted by changing the minimum disparity.

blockSize	the linear size of the blocks compared by the algorithm. The size should be odd (as the block is centered at the current pixel). Larger block size implies smoother, though less accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher chance for algorithm to find a wrong correspondence.

The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for a specific stereo pair.

CV_Lesson44_深度图_双目摄像机.py

通过调整 numDisparities --numDisparities must be positive and divisble by 16 in functio 16 的倍数
和 blockSize--奇数 的值--越小越精确,噪声越多。

step:

  1. 通过特征匹配算法,找到相似的像素点X 的坐标,算出disparity (水平放置的双目镜头,那就逐行比较,)
  2. 已知相机的内参,
  3. 带入公式,获得depth信息。

http://www.sohu.com/a/203027140_100007727

https://blog.csdn.net/piaoxuezhong/article/details/79016615

https://www.cnblogs.com/adong7639/p/4240396.html

https://blog.csdn.net/piaoxuezhong/article/details/79016615

扩展: stereo_match.py in OpenCV-Python samples


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值