[英]Opencv error - Imread statement in python
I compiled this code:我编译了这段代码:
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)
but get this error:但得到这个错误:
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)
this error is on cv.imread()
but my code is correct.此错误在
cv.imread()
上,但我的代码是正确的。 my code compiled on colab but when i compile on my system this worked.我的代码是在 colab 上编译的,但是当我在我的系统上编译时,它起作用了。 do you know that error?
你知道那个错误吗?
You're trying to fill the array before resizing it, try on line 19您正在尝试在调整数组大小之前填充数组,请在第 19 行尝试
simps[j,:,:,:] = cv.resize(cv.imread(filename),(128,128))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.