Cv2.cuda.remap assertion error
Hi all, I'm trying to use remap for removing fisheye . I have done calibration and found the K and D values the trying to remove remove fisheye by using remap.
When I tried with cv2.remap it works fine.code without cuda module
import numpy
import cv2 ,sys
import numpy as np
import time
import traceback
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]])
cam = cv2.VideoCapture(0)
i = 0
a=[]
while i<10:
k = cv2.waitKey(1)
ret, frame = cam.read()
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
try:
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, DIM, cv2.CV_16SC2)#
if i == 1 :
a.extend(['map1 : ',map1,"map2 : ",map2])
print("Map 1 : ",map1)
print("Map 2 : ",map2)
#map1 = map1.astype(np.float32)
#map2 = map2.astype(np.float32)
#map1 = cv2.cuda_GpuMat(map1)
#map2 = cv2.cuda_GpuMat(map2)
new_w,new_h = (1920, 1012)
resized = cv2.resize(frame, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
#resized = cv2.cuda.resize(img2, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
#print("Resizing")
uDst = cv2.remap(resized,map1,map2, interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
#uDst = cv2.cuda.remap(resized,map1,map2, interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
#print("Remapping")
#img = uDst.download()
cv2.imshow("test", uDst)
#print(img)
#time.sleep(.1)
i=i+1
except Exception:
#print("Exceptoin")
print("Oops!",sys.exc_info()[0],"occured.")
print(traceback.format_exc())
#return [False, False]
pass
when trying with cuda module,
map1 = map1.astype(np.float32)
map2 = map2.astype(np.float32)
map1 = cv2.cuda_GpuMat(map1)
map2 = cv2.cuda_GpuMat(map2)
new_w,new_h = (1920, 1012)
resized = cv2.cuda.resize(img2, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
print("Resizing")
uDst=cv2.cuda.remap(resized,map1,map2,interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
got error like,
rawImg = cv2.cuda.remap(rawImg, self.map1,self.map2,interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT)
cv2.error: OpenCV(4.2.0-dev) F:\Dev\Repos\opencv_contrib_fork_1\modules\cudawarping\src\remap.cpp:82: error: (-215:Assertion failed) xmap.type() == CV_32F && ymap.type() == CV_32F && xmap.size() == ymap.size() in function 'cv::cuda::remap'
Are both
and
no , it's for map1.type = 13 and map2.type = 5
From the help in this answer both
. @Param xmap X values. Only CV_32FC1 type is supported. . @Param ymap Y values. Only CV_32FC1 type is supported.
I Don't know how to convert to the expected type
Can you use
cv2.CV_32F1
mappingsIt's working thanks!!!!