IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 计算机视觉:摄像机标定与畸变校正 -> 正文阅读

[人工智能]计算机视觉:摄像机标定与畸变校正

  1. 任务1:利用OpenCV实现摄像机参数标定
  1. 设置好棋盘格参数(边长、行列数等),打印方形棋盘格并粘贴,拍摄多张标定图像;
  2. 估计标定参数,可视化标定结果。

??????

  1. 任务2:根据标定参数进行畸变校正
  1. 根据标定参数进行畸变校正;
  2. 展示畸变校正前后的图像,观察其差异。

参考资料:

  1. 棋盘格制作:Camera Calibration Pattern Generator – calib.io
  2. OpenCV文档:https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html
  3. Demo1:OpenCV: Camera Calibration
  4. Demo2:https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html
  5. Demo3:Camera Calibration using OpenCV | LearnOpenCV #
  6. Demo4:Understanding Lens Distortion | LearnOpenCV #
  7. Demo5:Calibrating & Undistorting with OpenCV in C++ (Oh yeah) - AI Shack
import numpy as np
import cv2 as cv
import glob
# termination criteria
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*8,3), np.float32)
objp[:,:2] = np.mgrid[0:8,0:6].T.reshape(-1,2)
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.
images = glob.glob('C:\\Users\\26909\Desktop\camera_data\*.jpg')
for fname in images:
    img = cv.imread(fname)
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    # Find the chess board corners
    ret, corners = cv.findChessboardCorners(gray, (8,6), None)
    # If found, add object points, image points (after refining them)
    if ret == True:
        objpoints.append(objp)
        corners2 = cv.cornerSubPix(gray,corners, (11,11), (-1,-1), criteria)
        imgpoints.append(corners)
        # Draw and display the corners
        cv.drawChessboardCorners(img, (8,6), corners2, ret)
        cv.imshow('img', img)
        cv.waitKey(500)
cv.destroyAllWindows()

#参数
ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
print("ret:", ret)
print("mtx:\n", mtx) # 内参数矩阵
print("dist:\n", dist)  # 畸变系数   distortion cofficients = (k_1,k_2,p_1,p_2,k_3)
print("rvecs:\n", rvecs)  # 旋转向量  # 外参数
print("tvecs:\n", tvecs ) # 平移向量  # 外参数

#畸变矫正
img = cv.imread('C:\\Users\\26909\Desktop\camera_data\IMG12.jpg')
h,  w = img.shape[:2]
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))
# undistort
dst = cv.undistort(img, mtx, dist, None, newcameramtx)
# crop the image
x, y, w, h = roi
dst = dst[y:y+h, x:x+w]
cv.imwrite('calibresult.png', dst)

实验结果

3.1 相机参数标定及可视化

?

?

?

标定结果:

ret: 0.7404995966474621

mtx:

?[[274.4022963??? 0.???????? 309.41661229]

?[? 0.???????? 274.81034452 228.80419383]

?[? 0.?????????? 0.?????????? 1.??????? ]]

dist:

?[[-0.3454201?? 0.1457639? -0.00195636? 0.00171827 -0.02320787]]

rvecs:

?(array([[ 0.14050152],

?????? [-0.08172329],

?????? [ 1.55213876]]), array([[-0.50002852],

?????? [-0.20014157],

?????? [-1.38796715]]), array([[-0.20899323],

?????? [-0.3015702 ],

?????? [ 1.17631626]]), array([[ 0.14426414],

?????? [-0.48615287],

?????? [ 1.25333586]]), array([[-0.11196678],

?????? [ 0.13929802],

?????? [-1.51166718]]), array([[-0.20041373],

?????? [ 0.21822841],

?????? [-1.48091619]]), array([[-0.23701475],

?????? [ 0.18275228],

?????? [-0.84192608]]), array([[-0.1877632 ],

?????? [ 0.08558443],

?????? [-0.38675306]]), array([[-0.12538803],

?????? [ 0.23143798],

?????? [-1.36803536]]), array([[-0.25324129],

?????? [ 0.26484299],

?????? [-1.0249051 ]]), array([[-0.15181587],

?????? [ 0.17507901],

?????? [-1.19285926]]), array([[ 0.16808607],

????? ?[ 0.09056166],

?????? [-0.01890093]]), array([[0.00670207],

?????? [0.36090502],

?????? [1.46210405]]), array([[0.575493? ],

?????? [0.1586262 ],

?????? [1.02133379]]), array([[-0.06530318],

?????? [ 0.2759119 ],

?????? [-0.76715368]]), array([[-0.17849515],

?????? [ 0.1838762 ],

?????? [ 0.00634664]]), array([[-0.2013951 ],

?????? [ 0.09738451],

?????? [ 0.72377849]]), array([[-0.44136116],

?????? [ 0.37411479],

?????? [-0.53144601]]), array([[-0.5093139 ],

?????? [ 0.11895948],

?????? [-0.65299492]]), array([[-0.57225479],

?????? [-0.06450065],

?????? [-1.01460071]]))

tvecs:

?(array([[ 2.07154433],

?????? [-2.30660832],

?????? [ 7.4506053 ]]), array([[-3.95294077],

?????? [ 3.55032646],

?????? [ 8.64371851]]), array([[ 2.99558578],

?????? [-3.57085102],

?????? [11.73926593]]), array([[ 2.3984248 ],

?????? [-3.01994723],

?????? [10.69421613]]), array([[-0.31440216],

?????? [ 4.03730762],

?????? [11.24204555]]), array([[-0.96673367],

?????? [ 3.831028? ],

?????? [ 9.009737? ]]), array([[-3.63737237],

?????? [ 1.72964791],

?????? [10.5699932 ]]), array([[-4.74312794],

?????? [-0.28685914],

?????? [10.31412678]]), array([[-3.13384807],

?????? [ 3.48362812],

?????? [12.11070046]]), array([[-6.74105261],

?????? [ 1.96433573],

?????? [12.56616204]]), array([[-5.97698749],

?????? [ 2.40248059],

?????? [ 8.73901348]]), array([[-3.365379? ],

?????? [-2.08857099],

?????? [ 7.58537102]]), array([[ 4.60034986],

?????? [-1.63283684],

?????? [10.16924106]]), array([[ 0.96341843],

?????? [-2.83724946],

?????? [ 7.42342456]]), array([[-3.96962978],

?????? [ 1.8225874 ],

?????? [11.23708158]]), array([[-3.97587032],

?????? [-1.26762813],

?????? [11.19197982]]), array([[-2.10782797],

?????? [-4.64916982],

?????? [10.41076044]]), array([[-6.00656584],

?????? [-0.11113525],

?????? [11.82626777]]), array([[-8.59365244],

?????? [-1.02351119],

?????? [11.98704289]]), array([[-6.2890475 ],

?????? [ 1.47511978],

?????? [ 9.99562781]]))

使用MATLAB的相机标定工具cameraCalibrator进行可视化:

3.2 根据标定参数进行畸变校正

校正前: ???????????????????????????????校正后:

?

?

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-10-08 20:42:06  更:2022-10-08 20:45:49 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 22:28:14-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码