0

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?

1
  • 1
    If answer helped,don't forget to accept it by checking the mark beside the answer. Commented May 24, 2020 at 10:10

1 Answer 1

1

You're trying to fill the array before resizing it, try on line 19

simps[j,:,:,:] = cv.resize(cv.imread(filename),(128,128))
Sign up to request clarification or add additional context in comments.

1 Comment

if this doesn't work you might have to use an intermediate array, current = cv.imread(filename) then current = cv.resize(current,(128,128) then simps[j,:,:,:] = current

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.