为什么cv2.resize()不能用于整数数组?

2021-04-11 16:04:17 发布

您现在位置:Python中文网/ 问答频道 /正文

[~] python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np, cv2
>>> a=np.arange(10,250,10).reshape((6,4))
>>> a
array([[ 10,  20,  30,  40],
       [ 50,  60,  70,  80],
       [ 90, 100, 110, 120],
       [130, 140, 150, 160],
       [170, 180, 190, 200],
       [210, 220, 230, 240]])
>>> cv2.resize(a,(3,2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/resize.cpp:3596: error: (-215:Assertion failed) func != 0 in function 'resize'

这个问题在Linux下的Python3.6和Windows10下的Python3.7中都存在。Windows 10下的错误消息是:

^{pr2}$

如果我将类型改为float64或float32,例如

a=np.arange(10,250,10).reshape((6,4)).astype(np.float64)

然后cv2.resize突然起作用了。在