gpt4 book ai didi

python - opencv:相机校准图像未显示

转载 作者:行者123 更新时间:2023-12-02 16:39:49 24 4
gpt4 key购买 nike

所以我用相机拍了几张照片,并按照此处发布的教程进行操作:http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html

但我遇到了一个问题。我从drawchessboardcorners函数中得到的图像为空,我不确定为什么。请注意,我是opencv的新手,因此对于某些人来说这可能是微不足道的,但是现在我无法弄清楚。我正在使用opencv 2.4.10。

码:

import numpy as np
import cv2

# 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((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,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.

for i in range (1,13):
img = cv2.imread('calibrate/calibrate' + str(i) + '.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

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

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

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

# Draw and display the corners
img = cv2.drawChessboardCorners(img, (9,6), corners2,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
else:
print "No Calibration"

cv2.destroyAllWindows()

这是我的网络摄像头拍摄的照片:

这是错误代码的图片:

我对代码进行了一些修改,以处理拍摄的照片(使用编写的程序)。例如,存在for循环的原因很简单,因为我有12张照片,其名称类似calibrate1,calibrate2等。我对此很困惑,希望你们中的一个能给我洞见!谢谢

最佳答案

因此,在@berak发表评论后,我决定卸载opencv 2.4并安装opencv 3.0并注意,上面的代码起作用了!谢谢@berak

关于python - opencv:相机校准图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27500859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com