问题描述
可能,我只见树木不见森林......
我使用 Python 3.0 和 OpenCV 以通用棋盘法来表征相机的校准参数。 现在,我想将找到的内在参数应用到由同一台相机拍摄的另一张任意照片,比如风景图像。
当我正确理解校准过程时,使用棋盘面板校准期间发现的相机矩阵(=mtx)和失真系数(=dist)应该是可能的。
因此以下代码不起作用
import numpy as np
import cv2 as cv
import glob
# Read in an arbitrary image
# this is already gray scale
img = cv.imread('IMAGE.tif')
这会创建一个变量“img”,但它是“NoneType”对象(在我看来应该是“Float32 数组”或“Uint16 数组”......?) -> 为什么这不起作用?
接下来我定义我的内在参数(将来它应该从一个calibration_parameters.txt文件中读取)
# Numpy arrays of intrinsic camera parameters found by calibration process with chessboard:
mtx=np.array([[2.21937125e+03,0.00000000e-00,1.01761900e+03],[0.00000000e-00,2.22117861e+03,7.96777422e+02],1.00000000e-00]])
dist=np.array([[-1.28884542e-01,1.04684534e-01,1.83413115e-03,-3.12811919e-05,1.56791936e-01]])
我给图片尺寸
# image dimension in pixel:
h = 2064
w = 1544
# alternative when img is not a 'NoneType' object anymore:
# img.shape[:2]
最后,我使用固有的相机参数重新映射图像:
# refine the camera matrix based on a free scaling parameter
newcameramtx,roi=cv.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,h))
# Remapping the image:
mapx,mapy = cv.initUndistortRectifyMap(mtx,None,newcameramtx,5)
dst = cv.remap(img,mapx,mapy,cv.INTER_LINEAR)
# Crop and Show the image:
x,y,w,h = roi
dst = dst[y:y+h,x:x+w]
cv.imwrite('calibresult.png',dst)
cv.imshow('calibresult.png')
任何提示为什么这不起作用?
全部代码:
import numpy as np
import cv2 as cv
import glob
# Read in an arbitrary image
# this is already gray scale
img = cv.imread('IMAGE.tif')
# Numpy arrays of intrinsic camera parameters found by calibration process with chessboard:
mtx=np.array([[2.21937125e+03,1.56791936e-01]])
# image dimension in pixel:
h = 2064
w = 1544
# alternative when img is not a 'NoneType' object anymore:
# img.shape[:2]
# refine the camera matrix based on a free scaling parameter
newcameramtx,dst)
cv.imshow('calibresult.png')
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)