综合

image什么意思中文翻译,images相册是什么

  摄像头图像校正专题   

  

  https://份文件。opencv。org/4。x/DC/dbb/教程_ py _校准。超文本标记语言   

  

  目标(目的)   

  

  在本节中,我们将了解(本章节,我们将学习如下的一些知识)   

  

  相机引起的失真类型(摄像头引起的失真变形的类型)   

  

  如何找到内在(固有的、内在的)和外在(外在的、非本质的)相机的属性(如何发现摄像头的内在和外在的特性)   

  

  如何基于这些属性对图像进行去失真(如何基于这些属性取消这些扭曲变形)   

  

  基础知识(基础)   

  

  一些针孔摄像机引入了显著的(明显)失真(扭曲)到图像。(一些针孔摄像头引起明显的图像扭曲两种主要的畸变是径向畸变和切向畸变(两种主要的畸变是径向畸变和切向畸变).   

  

  径向扭曲导致直线看起来是弯曲的。(径向变形会导致直线出现弯曲)距离图像中心越远,径向失真越大。(距离图像中心越远,径向失真越大例如,下面显示了一个图像,其中国际象棋棋盘的两个边缘用红线标记。(例如,下面的图像,图像里面的棋盘的边缘用红线标注)但是,你可以看到棋盘的边框不是一条直线,与红线不匹配。(但是,我们可以看到棋盘的边界并不是一条直线,并不与红线相匹配。所有预期的直线凸出(所有预期的直线都是凸出的。).更多详情请访问失真(光学)。(更多信息需要访问畸变光学网页)   

  

  https://号。维基百科。org/wiki/Distortion _(光学)   

  

     

  

  径向变形可以表示如下(径向畸变可以标识为如下公式)   

  

     

  

  类似地,切向失真发生是因为图像摄取透镜(透镜)没有完全平行于成像平面。(同样,由于摄像透镜未与成像平面完全平行对齐,因此会发生切向失真因此,图像中的某些区域可能看起来比预期的更近。切向变形量可以表示为:以下(因此,图像中的一些区域看起来比预期的更近,切向变形量可表示如下:)   

  

     

  

  简而言之,我们需要找到五个参数,即:给出的失真系数(简而言之,我们需要找到五个参数,成为畸变系数,由下面公式给出:)   

  

     

  

  除此之外,我们还需要一些其他信息,如的内在和外在参数   

the camera.(除此之外,我们还需要一些其他信息,比如相机的内在和外在参数。) Intrinsic parameters are specific to a camera. (内部参数是特定于相机的。)They include information like focal length (fx1, fy1 ) and optical centers ( cx,cy)(他们包括焦距和光学中心). The focal length and optical centers can be used to create a camera matrix, which can be used to remove distortion due to the lenses of a specific camera. (焦距和光学中心可用于创建相机矩阵,该矩阵可用于消除特定相机镜头造成的失真。)The camera matrix is unique to a specific camera, so once calculated, it can be reused on other images taken by the same camera.(摄像机矩阵对于特定摄像机是唯一的,因此一旦计算,它可以在同一摄像机拍摄的其他图像上重复使用。) It is expressed as a 3x3 matrix:(它表示为3*3矩阵)

     

Extrinsic parameters corresponds to rotation and translation vectors which translates a coordinates of a 3D point to a coordinate system.(外部参数对应于将三维点坐标转换为坐标系的旋转和平移向量)

  

For stereo applications, these distortions need to be corrected first. (对于立体应用,首先需要矫正这些失真。)To find these parameters, we must provide some sample images of a well defined pattern (e.g. a chess board). (为了找到这些参数,我们必须提供一些定义良好模式的示例图片(比如棋盘板))We find some specific points of which we already know the relative positions (e.g. square corners in the chess board). (我们找到一些已经确定相对位置的特定点。(比如棋盘中的方角))We know the coordinates(坐标) of these points in real world space and we know the coordinates in the image, so we can solve for the distortion coefficients.(我们知道这些点在真实空间中的坐标和我们知道的图像的坐标,所有我们求解失真系数) For better results, we need at least 10 test patterns.(为了更好的结果,我们需要至少10个点的测试模式。)

  

Code(代码)

  

As mentioned above, we need at least 10 test patterns for camera calibration. (如上所述,我们需要至少10个测试模式用于摄像机校准。)OpenCV comes with some images of a chess board(OpenCV附带了一些棋盘的图像) (see samples/data/left01.jpg – left14.jpg), so we will utilize these. (所以我们将利用这些。)Consider an image of a chess board. (考虑一个棋盘的图像)The important input data needed for calibration of the camera is the set of 3D real world points and the corresponding 2D coordinates of these points in the image.(摄像机校准所需的重要输入数据是一组3D真实世界点以及图像中这些点的相应2D坐标。) 2D image points are OK which we can easily find from the image.(2D图像点可以很容易从图像中找到。) (These image points are locations where two black squares touch each other in chess boards这些图像点就是在棋盘上两个黑色方块相互接触的位置。)

  

What about the 3D points from real world space? (真实世界空间的3D点怎么样?)Those images are taken from a static camera and chess boards are placed at different locations and orientations.(这些图像是通过静态相机拍摄的,棋盘被防止在不同位置和不同方向。) So we need to know(X,Y,Z)values(所以我们需要知道坐标值(X,Y,Z)). But for simplicity, we can say chess board was kept stationary at XY plane, (so Z=0 always) and camera was moved accordingly. (但为了简单起见,我们可以说棋盘在XY平面上保持不动(所以Z=0总是),相机也随着移动。)This consideration helps us to find only X,Y values. (这种考虑有助于我们找到X,Y值。)Now for X,Y values, we can simply pass the points as (0,0), (1,0), (2,0), ... which denotes the location of points. (现在对于坐标X,Y值,我们能沿着点(0,0)(1,0)(2,0)表示点的位置。)In this case, the results we get will be in the scale of size of chess board square. (在这种情况下,我们得到的结果将是棋盘正方形的大小。)But if we know the square size, (say 30 mm), we can pass the values as (0,0), (30,0), (60,0), ... . Thus, we get the results in mm. (但是,如果我们知道正方形的大小(比如30mm),我们可以将值传递为(0,0),(30,0),(60,0)。因此,我们得到了mm的结果。(In this case, we don't know square size since we didn't take those images, so we pass in terms of square size).(本例中,我们不知道正方形的大小,因为我们没有拍摄这些图像,所以我们根据正方形大小进行传递)

  

3D points are called object points and 2D image points are called image points.(3D点称为对象点,2D点称为图像点)

  

Setup(设置)

  

So to find pattern in chess board, we can use the function, cv.findChessboardCorners(). (因此,为了发现棋盘中的模式,我们能用到这个函数cv.findChessboardCorners())We also need to pass what kind of pattern we are looking for, like 8x8 grid, 5x5 grid etc.(我们还需要找到模式的类型,比如8*8网格、5*5网格) In this example, we use 7x6 grid. (Normally a chess board has 8x8 squares and 7x7 internal corners). (在本例中,我们使用7*6网格(通常棋盘有8*8个正方形和7*7个内角))It returns the corner points and retval which will be True if pattern is obtained.(如果获得图案,则返回值为真,它返回值为角点和返回值) These corners will be placed in an order (from left-to-right, top-to-bottom)(这些角按照顺序放置(从左到右,从上到下))

  

Note(注)

  

This function may not be able to find the required pattern in all the images. (这个函数可能无法在所有图像中找出所需的模式)So, one good option is to write the code such that, it starts the camera and check each frame for required pattern.(因此,一个好的选择是写一个代码,这样它启动相机并检查每一帧所需的模式) Once the pattern is obtained, find the corners and store it in a list.(一旦获得了图案,找到角点并存储到列表中。) Also, provide some interval before reading next frame so that we can adjust our chess board in different direction. (另外,在阅读下一帧前,提供一些间隔,以便我们可以在不同方向上调整棋盘。)Continue this process until the required number of good patterns are obtained. 继续这个过程,直到获得所需数量的良好图案。Even in the example provided here, we are not sure how many images out of the 14 given are good. (及时在这里提供的示例中,我们也不确定给定的14个图像中有多少是好的。)Thus, we must read all the images and take only the good ones.(因此,我们必须度出所有的图像,找出最好的。)

  

Instead of chess board, we can alternatively use a circular grid. (我们也可以使用圆形网格代替棋盘格)In this case, we must use the function cv.findCirclesGrid() to find the pattern.(这种情况下,我们必须使用函数cv.findCirclesGrid()发现这种模式) Fewer images are sufficient to perform camera calibration using a circular grid.(很少有图像使用圆形网格执行相机校准。)

  

Once we find the corners, we can increase their accuracy using cv.cornerSubPix(). (一旦找到了角点,我们可以使用cv.cornerSubPix().提高精度。)We can also draw the pattern using cv.drawChessboardCorners(). All these steps are included in below code:(我们也可以使用cv.drawChessboardCorners()绘制图案。所有步骤在如下代码中)

     

One image with pattern drawn on it is shown below:

  

(下图是一个带着模式绘图的图像)

     

Calibration(标定)

  

Now that we have our object points and image points, we are ready to go for calibration. (现在我们有了目标点和图像点,我们可以开始校准了。)We can use the function, cv.calibrateCamera() which returns the camera matrix, distortion coefficients, rotation and translation vectors etc.(我们可以使用函数cv.calibrateCamera(),返回摄像机矩阵、失真系数、旋转和平移向量)

     

Undistortion(不失真)

  

Now, we can take an image and undistort it. (现在我们让图像去掉失真。)OpenCV comes with two methods for doing this.(OpenCV有两种方法实现) However first, we can refine the camera matrix based on a free scaling parameter using cv.getOptimalNewCameraMatrix(). (但是,首先,我们可以使用cv.getOptimalNewCameraMatrix()函数基于自由缩放参数重新顶级摄像机矩阵)If the scaling parameter alpha=0, it returns undistorted image with minimum unwanted pixels.(如果缩放参数alpha=0,它将返回未失真的图像,其中包含最少不需要的像素。) So it may even remove some pixels at image corners.(因此它甚至删除一些图像角点处的像素。) If alpha=1, all pixels are retained with some extra black images. (如果alpha=1,则所有像素都会保留一些额外的黑色图像。)This function also returns an image ROI which can be used to crop the result.(此函数还可以返回用于裁剪结果的图像ROI)

  

So, we take a new image (left12.jpg in this case. That is the first image in this chapter)(因此我们使用一个新图像(本例中,left12.jpg,那时本章中的第一个图像))

     

1. Using cv.undistort()

  

This is the easiest way. Just call the function and use ROI obtained above to crop the result.(这是最简单的方法。只需调用函数并使用上面获得的ROI来裁剪结果。)

     

2. Using remapping

  

This way is a little bit more difficult.(这个方法有点小难) First, find a mapping function from the distorted image to the undistorted image. Then use the remap function.(首先,找到从畸变图像到未畸变图像的映射函数。然后使用remap函数。)

     

Still, both the methods give the same result. See the result below:(尽管如此,这两种方法给出了相同的结果。结果如下:)

     

You can see in the result that all the edges are straight.(你可以在结果中看到所有的边都是直的。)

  

Now you can store the camera matrix and distortion coefficients using write functions in NumPy (np.savez, np.savetxt etc) for future uses.(现在,您可以使用NumPy中的写入函数(np.savez、np.savetxt等)存储相机矩阵和失真系数,以备将来使用)

  

Re-projection Error(Re-projection Error)

  

Re-projection error gives a good estimation of just how exact the found parameters are. (再投影误差可以很好地估计所发现的参数的精确程度。)The closer the re-projection error is to zero, the more accurate the parameters we found are.(再投影误差越接近于零,我们发现的参数越精确。) Given the intrinsic, distortion, rotation and translation matrices, we must first transform the object point to image point using cv.projectPoints(). (给定固有矩阵、畸变矩阵、旋转矩阵和平移矩阵,我们必须首先使用cv.projectPoints()将对象点变换为图像点。)Then, we can calculate the absolute norm between what we got with our transformation and the corner finding algorithm.(然后,我们可以计算通过变换得到的绝对范数和角点查找算法得到的绝对范数。) To find the average error, we calculate the arithmetical mean of the errors calculated for all the calibration images.(为了找到平均误差,我们计算了所有校准图像的误差算术平均值。)

        

********************************************************************************************

  

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*7,3), np.float32)

  

objp = np.mgrid.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('./img/*.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, (7,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, (7,6), corners2, ret)

  

cv.imshow('img', img)

  

ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape, None, None)

  

imga = cv.imread('left12.jpg')

  

h,w = imga.shape

  

newcameramtx,roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))

  

#方法1

  

#dst = cv.undistort(imga, mtx, dist, None, newcameramtx)

  

#x,y,w,h = roi

  

#dst = dst

  

#cv.imwrite('left12B.png', dst)

  

#方法2

  

mapx, mapy = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5)

  

dst1 = cv.remap(imga, mapx, mapy, cv.INTER_LINEAR)

  

x, y, w, h = roi

  

dst1 = dst1

  

cv.imwrite('left12B1.png', dst1)

  

xx=cv.waitKey(0)

  

print(xx)

  

cv.destroyAllWindows()

  

********************************************************************************************

  

文件结构:

                                            

其他文章

  • 23家银行信用卡还款到账时间
  • 做到这几点,信用卡提额是迟早的事
  • 你正在使用哪家银行的信用卡?
  • 刘先生用支付宝花呗提现,结果人财两空
  • 网上办理信用卡,这两个便宜不能沾!
  • 申卡、提额、超限等全套实战更新!
  • 测一测你是否适合使用信用卡
  • 恶意透支信用卡不还后果堪忧
  • 信用卡的养卡技巧,轻松解决资金问题!
  • 2017信用卡大变身,这6点你必须知晓
  • 香港大公文交所股吧
  • 最牛的基金经理,排名前十的基金经理
  • 上海商铺价格为什么低?
  • 优秀青年基金获得者怎么查(优秀青年科学基金获得者)
  • 最新000061农产品股吧_农产品000061重组
  • 云维实业股吧_600725云维股吧
  • 美国更大的私募基金,美国十大私募基金公司
  • 上海机场股吧最新行情(600009上海机场股吧)
  • 建议大家不要开通手机银行
  • 基金(150244)简介行情