TransWikia.com

Calibrating undistortion reducing the size of image

Stack Overflow Asked by Naga kiran on December 30, 2021

I trying calibrate my camera, i have generated calibration matrix and undistortion parameters of

array([[449.23763332,   0.        , 288.9949981 ],
       [  0.        , 509.88847329, 195.85872177],
       [  0.        ,   0.        ,   1.        ]])

array([-0.38496184,  0.21366652, -0.00107046,  0.00090068, -0.07853835])

enter image description here

Following code for undistortion

file = 'snapshot_640_480_1.jpg'
img = cv2.imread(file)
h,  w = img.shape[:2]
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))

mapx, mapy = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5)
dst = cv.remap(img, mapx, mapy, cv.INTER_LINEAR)

# crop the image
x, y, w, h = roi
dst1 = dst[y:y+h, x:x+w]
cv.imwrite('calibresult.png', dst1)
display.Image(filename='calibresult.png')

Resulting image is getting reduced size of (95, 115, 3)

Is there any way i can undistort the image with same size ( resizing distort the image) ?

undistorted image

One Answer

cv.getOptimalNewCameraMatrix allows to alter the generated undistort image size by mentioning the input image size (w,h) and expected image size(w1,h1), by changing the expected image size

by changing the expected image size, we shall achieve referenced answer. Thanks for the inputs @Micka

file = r'snapshot_640_480_1.jpg'
img = cv2.imread(file)
h,  w = img.shape[:2]
# New Image shape to generate
w1,h1 = 5*w,5*h
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w1,h1))

mapx, mapy = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w1,h1), 5)
dst = cv.remap(img, mapx, mapy, cv.INTER_LINEAR)

Answered by Naga kiran on December 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP