gpt4 book ai didi

python - OpenCV错误-python中的Imread语句

转载 作者:行者123 更新时间:2023-12-02 17:21:35 25 4
gpt4 key购买 nike

我编译了这段代码:

import numpy as np
import cv2 as cv
simps = np.zeros((8000,128,128,3))
j = 0
for i in range(1000,9001):

print(j)

if (i % 10 == i and i != 10):
filename = '/content/cropped/' + str(i) + '.png'
elif (i % 100 == i and i != 100):
filename = '/content/cropped/' + str(i) + '.png'
elif (i % 1000 == i and i != 1000):
filename = '/content/cropped/' + str(i) + '.png'
elif (i % 10000 == i and i != 10000):
filename = '/content/cropped/' + str(i) + '.png'
print(filename)
print(type(filename))
simps[j,:,:,:] = cv.imread(filename)
print(simps[j,:,:,:])
simps[j,:,:,:] = cv.resize(simps[j,:,:,:],(128,128));
j += 1
simps = simps.astype('uint8')
np.save('/content/simps.npy',simps)

但是得到这个错误:
     17         print(filename)
18 print(type(filename))
---> 19 simps[j,:,:,:] = cv.imread(filename)
20 print(simps[j,:,:,:])
21 simps[j,:,:,:] = cv.resize(simps[j,:,:,:],(128,128));

ValueError: could not broadcast input array from shape (200,200,3) into shape (128,128,3)

这个错误在 cv.imread()上,但是我的代码是正确的。我的代码是在colab上编译的,但是当我在系统上编译时,它可以正常工作。你知道那个错误吗?

最佳答案

您正在尝试在调整数组大小之前填充数组,请尝试在第19行

simps[j,:,:,:] = cv.resize(cv.imread(filename),(128,128))

关于python - OpenCV错误-python中的Imread语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61984042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com