简体   繁体   English

cv2.resize Error "(-215:Assertion failed).dsize.empty()" 对于 16 位图像但不是 8 位图像

[英]cv2.resize Error "(-215:Assertion failed) !dsize.empty()" for 16-bit images but not for 8-bit

I am trying to resize an image with the cv2.resize function and I get the following error:我正在尝试使用cv2.resize function 调整图像大小,但出现以下错误:

error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\opencv\modules\imgproc\src\resize.cpp:3688: error: (-215:Assertion failed).dsize:empty() in function 'cv::hal::resize'错误:OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\opencv\modules\imgproc\src\resize.cpp:3688: 错误: (-215 :断言失败).dsize:empty() 在 function 'cv::hal::resize'

My images are uint16 arrays:我的图像是 uint16 arrays:

img_ms.shape
(4, 57, 62)

img_pan.shape
(1, 1140, 1240)

The sample function I am using inside an image pansharpening script is:我在图像全色锐化脚本中使用的示例 function 是:

downsampled_img_pan = cv2.resize(img_pan, (img_ms.shape[2], img_ms.shape[1]), 
                                 interpolation = cv2.INTER_AREA)[:, :, np.newaxis]

With an 8-bit image I don't get the error.对于 8 位图像,我没有得到错误。 What happens with 16-bit images? 16 位图像会怎样?

You need to transpose your data.您需要转置数据。 Typically EO images are (C,H,W) (if you're using something like rasterio ) whereas cv2.resize expects (H,W,C) .通常 EO 图像是(C,H,W) (如果您使用的是rasterio类的东西),而cv2.resize期望是(H,W,C)

downsampled_img_pan = cv2.resize(img_pan.transpose(1,2,0),
                                 (img_ms.shape[2], img_ms.shape[1]),
                                 interpolation = cv2.INTER_AREA).transpose(2,0,1)

Note you may also need to transpose back to channel-first.请注意,您可能还需要移调回通道优先。

OpenCV will happily resize images of any depth - the following should all work: OpenCV 会愉快地调整任何深度的图像大小 - 以下应该都有效:

im = (np.random.random((640,640,3))*65535).astype(np.float32)
cv2.resize(im, None, fx=0.5, fy=0.5)

im = (np.random.random((640,640,3))*65535).astype(np.uint16)
cv2.resize(im, None, fx=0.5, fy=0.5)

im = (np.random.random((640,640,3))*255).astype(np.uint8)
cv2.resize(im, None, fx=0.5, fy=0.5)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cv2.resize() - 错误 - OpenCV(4.2.0) - 错误:(-215:Assertion failed) - 循环图像 - cv2.resize() - error - OpenCV(4.2.0) - error: (-215:Assertion failed) - loop over images 错误:(-215:Assertion failed).ssize.empty() in function 'resize' 在为框架设置 cv2.resize 时出现 - error: (-215:Assertion failed) !ssize.empty() in function 'resize' shows up when setting a cv2.resize for frame small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' - small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' CV2 图像错误:错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - CV2 Image Error: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' cv2.resize() function 将16位灰度改为24位灰度 - cv2.resize() function changes 16 bit grayscale to 24 bit grayscale resize.cpp:4052: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OPEN-CV 错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - OPEN-CV error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 错误:OpenCV(4.1.0) 错误:(-215:Assertion failed) !ssize.empty() in function 'cv::resize' - error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV(4.1.2) 错误: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - OpenCV(4.1.2) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 此错误的问题: (-215:Assertion failed).ssize:empty() in function 'cv::resize' OpenCV - Problem with this error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM