cv2.cuda.remap and initUndistortRectifyMap()

asked 2020-02-17 08:56:39 -0600

Imran B gravatar image

Hi all,I'm trying to remove fisheye from image with initUndistortRectifyMap() and cv2.cuda.remap but it's not properly coming I don't know where I'm doing mistake,my code :

import cv2
import numpy as np


DIM=(4096, 2160)
K=np.array([[3528.8238233303578, 0.0, 1896.057963692419], [0.0, 3560.253850219697, 949.5032468663909], [0.0, 0.0, 1.0]])
D=np.array([[0.699564792566421], [-0.9597137933330322], [0.9269878560500789], [1.5974705131747455]])

rawImg = cv2.imread('test.png')
raw_DIM =  rawImg.shape
rawImg = cv2.cuda_GpuMat(rawImg)
scale = raw_DIM[0] / DIM[0]
#tmpK = K * scale
#print("Scale", tmpK)
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, tuple(DIM), cv2.CV_32FC1)
map1 = map1.astype(np.float32)
map2 = map2.astype(np.float32)

map1 = cv2.cuda_GpuMat(map1)
map2 = cv2.cuda_GpuMat(map2)
mp = (map1.type(),map2.type())
print(mp)
#BORDER_REPLICATE ,BORDER_CONSTANT
rawImg = cv2.cuda.remap(rawImg,map1,map2,interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
#minX,minY = 50,50
#maxX,maxY = 2000,2000

p = rawImg.download()
cv2.imshow("Image",p)
cv2.waitKey(0)
cv2.destroyAllWindows()
edit retag flag offensive close merge delete