日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用OpenCV库快速求解相机内参

發(fā)布時(shí)間:2023/12/10 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用OpenCV库快速求解相机内参 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文主要介紹如何使用OpenCV庫函數(shù)求解相機(jī)內(nèi)參。具體可查閱官網(wǎng):https://docs.opencv.org/master/dc/dbb/tutorial_py_calibration.html。
關(guān)于相機(jī)內(nèi)參的求解還有很多其它的工具,如使用MATLAB求解會(huì)更方便,直接調(diào)用MATLAB中的APP即可。

1.背景知識

關(guān)于相機(jī)標(biāo)定的詳細(xì)理論可以參考博客:《深入理解張正友相機(jī)標(biāo)定法:數(shù)學(xué)理論詳細(xì)推導(dǎo)》。
相機(jī)內(nèi)參形式如下,是一個(gè)3×33\times33×3的矩陣,其中(fx,fy)(f_x,f_y)(fx?,fy?)是相機(jī)焦距,(cx,cy)(c_x,c_y)(cx?,cy?)是光學(xué)中心。相機(jī)內(nèi)參對于相機(jī)而言是唯一的,因此只要計(jì)算出了相機(jī)內(nèi)參,就可以在同一相機(jī)拍攝的其它圖像上重復(fù)使用。
K=[fx0cx0fycy001](1)K = \left[ \begin{matrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{matrix} \right] \tag{1} K=???fx?00?0fy?0?cx?cy?1????(1)


2.OpenCV庫求相機(jī)內(nèi)參

這里使用官方提供的圖片來演示如何求解相機(jī)內(nèi)參,目前已有某一相機(jī)拍攝的棋盤格圖片若干張(20-30張不等),部分圖片如下:

image1image2

使用OpenCV庫求解相機(jī)內(nèi)參代碼如下,其中mtx為相機(jī)內(nèi)參, dist為畸變系數(shù),

import numpy as np import cv2 import glob# extract object points and image points 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 = [] imgpoints = [] images = glob.glob('calibration_wide/GO*.jpg')# Step through the list and search for chessboard corners for idx, fname in enumerate(images):img = cv2.imread(fname)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# Find the chessboard cornersret, corners = cv2.findChessboardCorners(gray, (8, 6), None) if ret == True:objpoints.append(objp)imgpoints.append(corners)# Draw and display the cornerscv2.drawChessboardCorners(img, (8, 6), corners, ret)cv2.imshow('img', img)cv2.waitKey(500)# calibrate img = cv2.imread('test_image.jpg') img_size = (img.shape[1], img.shape[0])# Do camera calibration given objects points and image points ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img_size, None, None)dst = cv2.undistort(img, mtx, dist, None, mtx) cv2.imwrite('test_undist.jpg', dst)

標(biāo)定是根據(jù)查找棋盤格頂點(diǎn)來標(biāo)定的,如圖所示:

image1image2

最后,根據(jù)求得的相機(jī)內(nèi)參畸變系數(shù),可以對失真的圖片進(jìn)行還原,還原效果如下:

undist_imagedist_image

總結(jié)

以上是生活随笔為你收集整理的使用OpenCV库快速求解相机内参的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。