繁体   English   中英

如何在python中找到open-cv摄像机校准常数,OpenCV错误:cv :: calibrateCamera中的断言失败(nimages> 0)

[英]How can I find open-cv camera calibration constant in python , OpenCV Error: Assertion failed (nimages > 0) in cv::calibrateCamera

我想用以下代码找到相机校准常数。 但是,我有一些我不知道的错误消息。 请帮我。

import cv2
import numpy as np
import glob[enter image description here][1]

# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# 7*7 chess board, prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
object_point = np.zeros((7*7, 3), np.float32)
object_point[:, :2] = np.mgrid[0:7, 0:7].T.reshape(-1, 2)

# 3d point in real world space
object_points = []
# 2d points in image plane
image_points = []
h, w = 0, 0

images = glob.glob('chess board/*.jpg')

for file_name in images:
    image = cv2.imread(file_name)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    h, w = gray.shape[:2]

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

    # add object points, image points
    if ret:
        object_points.append(object_point)
        cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
        image_points.append(corners)

        # draw and display the corners
        cv2.drawChessboardCorners(image, (7, 7), corners, ret)
        cv2.imshow('image', image)
        cv2.waitKey(500)

# calibration
retval, cameraMatrix, distCoeffs, rvecs, tvecs = cv2.calibrateCamera(object_points, image_points, (w, h), None, None)

print "camera matrix:\n", cameraMatrix

# pi camera intrinsic parameters
ay = cameraMatrix[1, 1]
u0 = cameraMatrix[0, 2]
v0 = cameraMatrix[1, 2]
print "Ay:", ay
print "u0:", u0
print "v0:", v0

cv2.destroyAllWindows()ode here

这是我收到的错误消息:

C:\\ Python27 \\ python.exe“ C:/ Users / MOMO / PycharmProjects / test / training image / picam_calibration.py” OpenCV错误:cv :: calibrateCamera,文件......中的断言失败(nimages> 0) .. \\ opencv \\ modules \\ calib3d \\ src \\ calibration.cpp,第3415行回溯(最近一次调用):文件“ C:/ Users / MOMO / PycharmProjects / test / training image / picam_calibration.py”,第40行,在retval,cameraMatrix,distCoeffs,rvecs,tvecs = cv2.calibrateCamera(object_points,image_points,(w,h),None,None)cv2.error:........ \\ opencv \\ modules \\ calib3d \\ src \\ calibration .cpp:3415:错误:(-215)函数cv :: calibrateCamera中的nimages> 0

您应该检查传递给函数findChessboardCorner的拐角大小是否正确,在代码中为(7,7)。

这符合您的棋盘格图案吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM