尝试扭曲图像时出现断言错误

时间:2019-03-04 18:48:42

标签: python opencv image-processing computer-vision

我试图了解图像变形,并希望使用OpenCV的remap对图像进行变形。我尝试了以下操作,尝试重新映射原始图像中的每个像素,但是在运行代码时出现错误。

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)

错误提示:

    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

我无法理解该错误。我在做什么错?

0 个答案:

没有答案