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. my code compiled on colab but when i compile on my system this worked. do you know that error?
You're trying to fill the array before resizing it, try on line 19
simps[j,:,:,:] = cv.resize(cv.imread(filename),(128,128))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.