【问题标题】:camera calibration using opencv使用opencv进行相机校准
【发布时间】:2017-04-26 22:09:42
【问题描述】:

我正在使用 opencv python 进行相机校准。我使用 cv2.calibratecamera 函数找到了相机矩阵,但是相机矩阵对于不同的图像是不同的 这是我正在使用的代码-

import numpy as np
import cv2
import glob

# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.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((7 * 7, 3), np.float32)
objp[:, :2] = np.mgrid[0:7, 0:7].T.reshape(-1, 2)
#objp = objp*(2.4625)

# 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('*.jpg')
print('hello')

for r12 in images:
    img = cv2.imread('r12.jpg')
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, (7, 7), None)

    # If found, add object points, image points (after refining them)
    if ret:
        objpoints.append(objp)
        print('yes')

        cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
        imgpoints.append(corners)

        # Draw and display the corners
        cv2.drawChessboardCorners(img, (7, 7), corners, ret)
        cv2.imshow('img', img)
        cv2.waitKey(500)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
#np.savez('coefficientsr',cameramatrixr = mtx,distcoeffsr = dist,rotationalvectorsr = rvecs,translationalvectorsr = tvecs)
print(mtx)
print(dist)

cv2.destroyAllWindows()

【问题讨论】:

    标签: python-2.7 opencv3.0 camera-calibration


    【解决方案1】:

    您可以尝试获取重投影误差,以查看您的参数对于每次校准的准确度。还要确保使用足够多的图像并包含对象的不同角度。

    本教程展示了如何计算重投影误差:http://docs.opencv.org/3.1.0/dc/dbb/tutorial_py_calibration.html

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 2013-01-28
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      相关资源
      最近更新 更多