我正在尝试使用openCv重新映射图像,使用cv2和numpy,但我遇到了一些问题。我收到的错误是:
OpenCV错误:断言失败(((map1.type()== CV_32FC2 || map1.type()== CV_16SC2)&& map2.empty())||(map1.type()== CV_32FC1&&&&&&&&&&> map2.type()== CV_32FC1))重新映射,文件/tmp/binarydeb/ros-kinetic-opencv3-3.2.0/modules/imgproc/src/imgwarp.cpp,第5043行
但是这两个地图都是float32类型 - 所以我不太了解错误。我在函数中运行以下代码:
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 )
提前致谢
答案 0 :(得分:0)
转换为必填类型
Mat mat1 = new Mat() // or may be the input mat/map
Imgproc.cvtColor(mat1, mat1, Imgproc.COLOR_BGR2GRAY); //Call this before conversion otherwise it won't work
mat1.convertTo(mat1,CvType.CV_32FC1);