cv2.undistort中没有类型的未失真图像

时间:2017-06-06 07:12:48

标签: python opencv

我正在尝试删除相机中的失真。我已经校准了相机,现在正尝试使用cv2.undistort()来减少失真。 我尝试了以下代码:

enter code here
import cv2
import numpy as np 
import glob

mtx = np.loadtxt('CAMERA_MATRIX.txt')
dist = np.loadtxt('DISTORTION_COEFF.txt')
imgs = glob.glob('test_imgs/*.jpg')

for imagename in imgs:
    im = cv2.imread(imagename)
    imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
    h, w = im.shape[:2]
    newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,(w,h))
    # undistort
    dst = cv2.undistort(im, mtx, dist, None, newcameramtx)
    # crop the image
    x,y,w,h = roi
    dst = dst[y:y+h, x:x+w]
    dst = cv2.resize(dst,(900,900),cv2.INTER_LINEAR)
    #dst_res = cv2.resize(dst,(w,h),cv2.INTER_LINEAR)
    #imstack = np.hstack((im,dst))
    cv2.imshow('Undistortion',dst)
    cv2.waitKey(500)
cv2.destroyAllWindows()

发生以下错误:

OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize, file /home/atul/opencv/modules/imgproc/src/imgwarp.cpp, line 3496 Traceback (most recent call last): File "testing.py", line 20, in <module> dst = cv2.resize(dst,(900,900),cv2.INTER_LINEAR) cv2.error: /home/atul/opencv/modules/imgproc/src/imgwarp.cpp:3496: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

如何调试?

0 个答案:

没有答案