I am attempting to remap an image with openCv, using cv2 and numpy but I am having some issues. The error I receive is:
OpenCV Error: Assertion failed (((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && map2.empty()) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1)) in remap, file /tmp/binarydeb/ros-kinetic-opencv3-3.2.0/modules/imgproc/src/imgwarp.cpp, line 5043
But both maps are float32 type - so I don't quite understand the error. I am running the following code in a function:
rows, cols, channels = img.shape
map_x = np.zeros( (rows,cols,channels), np.float32 )
map_y = np.zeros( (rows,cols,channels), np.float32 )
for i in xrange( rows ):
for j in xrange( cols ):#
p = [ i, j ]
x = np.array( [ p[0], p[1], 1, p[0]*p[1]] )
#Compute pixel transform
trans = np.round( x.dot( self.w ) )
map_x[i,j] = trans[0]
map_y[i,j] = trans[1]
outimg = cv2.remap( img, map1, map2, cv2.INTER_CUBIC )
Thanks in advance
channels
is not 1, yet the arrays should be single channel (CV_32FC1
-- 32bit float, 1 channel) – Dan Mašek