尝试使用 cv2.resize 调整大小时出现错误消息
Error message when trying to resize with cv2.resize
我正在尝试加载 .npy
文件并使用 cv2.resize
调整其大小,但我收到以下错误消息:
cv2.error: OpenCV(4.5.1-dev) /home/name/opencv_build/opencv/modules/imgproc/src/resize.cpp:3688: error: (-215:Assertion failed) !dsize.empty() in function 'resize'
这是我的代码:
filepath = 'data.npy'
img = np.load(filepath)
print(img.shape)
res = cv2.resize(img, (352, 1216))
print(img.shape)
的输出是 (1, 1, 192, 640)
。
opencv 中的图像如果 grayscale/single 通道应该只有 2 个暗淡的,如果是颜色的话应该只有 3 个暗淡的。您似乎有一个 gray/single 频道图像 [192,640],它包含在 2 个列表 [1,1,---]
中
所以要获取图像,您需要从这 2 个列表中获取它。
img = np.load(filepath)[0][0]
或者如果你不确定它包含了多少个列表,你可以这样做
img = np.squeeze(np.load(filepath)
但只要这些列表中只有 1 张图像,它就可以工作
我正在尝试加载 .npy
文件并使用 cv2.resize
调整其大小,但我收到以下错误消息:
cv2.error: OpenCV(4.5.1-dev) /home/name/opencv_build/opencv/modules/imgproc/src/resize.cpp:3688: error: (-215:Assertion failed) !dsize.empty() in function 'resize'
这是我的代码:
filepath = 'data.npy'
img = np.load(filepath)
print(img.shape)
res = cv2.resize(img, (352, 1216))
print(img.shape)
的输出是 (1, 1, 192, 640)
。
opencv 中的图像如果 grayscale/single 通道应该只有 2 个暗淡的,如果是颜色的话应该只有 3 个暗淡的。您似乎有一个 gray/single 频道图像 [192,640],它包含在 2 个列表 [1,1,---]
中所以要获取图像,您需要从这 2 个列表中获取它。
img = np.load(filepath)[0][0]
或者如果你不确定它包含了多少个列表,你可以这样做
img = np.squeeze(np.load(filepath)
但只要这些列表中只有 1 张图像,它就可以工作