I am trying to understand image warping and wanted warp an image using OpenCV's remap
. I tried the following where I try to remap each pixel in the original image but as I run the code, I get an error.
import cv2
import numpy as np
img = cv2.imread("./images/cube.png", 0)
h, w = img.shape
blank_image = np.zeros((h,w))
blank_image[::2,::2] = 10
warped = cv2.remap(src = img, map1 = img + blank_image, map2 = img + blank_image, interpolation = cv2.INTER_CUBIC, borderMode = cv2.BORDER_REFLECT101)
cv2.imwrite("./images/warped.png", warped)
The error says:
OpenCV(3.4.1) Error: Assertion failed (((map1.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3))
|| map1.type() == (((3) & ((1 << 3) - 1)) + (((2)-1) << 3))) && map2.empty()) ||
(map1.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3)) && map2.type() == (((5) & ((1 << 3) - 1))
+ (((1)-1) << 3)))) in remap, file /io/opencv/modules/imgproc/src/imgwarp.cpp, line 1840
Traceback (most recent call last):
File "warp.py", line 13, in <module>
warped = cv2.remap(src = img, map1 = img + blank_image, map2 = img + blank_image,
interpolation = cv2.INTER_CUBIC, borderMode = cv2.BORDER_REFLECT101)
cv2.error: OpenCV(3.4.1) /io/opencv/modules/imgproc/src/imgwarp.cpp:1840: error: (-215)
((map1.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || map1.type() == (((3)
& ((1 << 3) - 1)) + (((2)-1) << 3))) && map2.empty()) || (map1.type() == (((5) & ((1 << 3) - 1))
+ (((1)-1) << 3)) && map2.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3))) in function remap
I could not understand the error. What am I doing incorrectly?