【问题标题】:OpenCV resize() TypeError: only integer scalar arrays can be converted to a scalar indexOpenCV resize() TypeError:只有整数标量数组可以转换为标量索引
【发布时间】:2022-01-03 11:10:36
【问题描述】:

这是我正在运行的代码

import cv2
import glob
for image in glob.glob("*.jpg"):
img=cv2.imread(image,1)
rs=img.resize(img, int(img.shape[0]/2),int(img.shape[1]/2))
cv2.imshow(img)
cv2.waitKey(2000)
cv2.destoryAllWindows()
cv2.imwrite("Resized"+img,rs)

但我在调整大小方法时收到以下错误

TypeError: only integer scalar arrays can be converted to a scalar index

即使我指定了我仍然会收到此错误

rs=img.resize(img, 300,500)

为什么会这样?感谢您对此的帮助。

席德

【问题讨论】:

  • 发生这种情况是因为您调用的是图像的resize 成员(即numpy.ndarray.resize),而不是cv2.resize

标签: python opencv image-processing


【解决方案1】:

您必须拨打cv2.resize(img, (300,500)) 而不是img.resize(img, 300,500)

【讨论】:

    猜你喜欢
    • 2021-01-27
    • 2019-04-26
    • 2017-12-15
    • 2021-10-31
    • 1970-01-01
    • 2018-04-04
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多