【发布时间】:2021-08-12 18:38:42
【问题描述】:
我正在使用 OpenCV 2.x 编写 Python 程序 下面是我的代码的摘录,它在已捕获和保存的文件列表上运行。所有图片均为80x60 8 位灰度图片。我得到的最好的是一个相机的投资回报率为[1, 6, 73, 49],但我的另一台相机获得了最好的投资回报率是[8, 9, 55, 39]。我已经在处理这么小的图像了,丢弃大约 50% 的像素并不是一个真正可行的解决方案。我只是不确定是什么导致cv2.getOptimalNewCameraMatrix() 返回如此小的投资回报率,尤其是当我将 15-40 张似乎正确找到角落的图像提供给它时。
import numpy as np
import cv2
import glob
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 100, .01)
goodImages = 0
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((3*4,3), np.float32)
objp[:,:2] = np.mgrid[0:4,0:3].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('*Left.bmp')
for fname in images:
print("Working on file: %s" % (fname))
img = cv2.imread(fname,cv2.CV_LOAD_IMAGE_COLOR)
gray = cv2.imread(fname,0)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (4,3),None)
# If found, add object points, image points (after refining them)
if ret == True:
print("Found Corners for %s" % (fname))
objpoints.append(objp)
cv2.cornerSubPix(gray,corners,(3,3),(-1,-1),criteria)
if corners is None:
print("Something went wrong with cornerSubPix in file: %s" % (fname))
else:
imgpoints.append(corners)
goodImages+=1
# Draw and display the corners
cv2.drawChessboardCorners(img, (4,3), corners,ret)
cv2.imshow('img',img)
cv2.waitKey(0)
if goodImages >9:
ret, intrinsicMatrix, distortionCoeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
h, w = img.shape[:2]
refinedCameraMatrix, roi=cv2.getOptimalNewCameraMatrix(intrinsicMatrix,distortionCoeffs,(w,h),1,(w,h))
np.savez("LeftCamera", refinedCameraMatrix=refinedCameraMatrix, roi=roi, intrinsicMatrix=intrinsicMatrix, distortionCoeffs=distortionCoeffs)
样本数据集可在以下位置下载: http://s000.tinyupload.com/?file_id=67483192025612443532
编辑
经过多次反复试验,我找到了一个数据集,该数据集的投资回报率为[3, 4, 75, 53],因此对这个问题的需求并不迫切,但我确实觉得这个问题很有趣。在我进行实验时,我发现一个好的数据集 + 另一个好的图片并不总是会增加 ROI,实际上会降低 ROI。这对我来说并不直观,因为更多好的数据应该会增加可用区域。
【问题讨论】:
-
好问题。想我会试试...
-
如果有帮助,我会附上一个指向我目前拥有的最佳文件集的链接。 http://s000.tinyupload.com/?file_id=25758342279820518279