Ask Your Question

Revision history [back]

imageio image vs cv image

(Python) i have a cv image in memory. I have a trained keras CNN. It expects an imagio image (its basically the keras handwritten digit sample). I can convert from cv to imageio by writing the image to a file and reading it back but this feels like a hack to me. this naive test fails (I saved to cv image in my main app, this is a small test app)

digimg = cv2.imread('cell1.png')
#digimg = imageio.imread('cell1.png')

model = load_model('test_model.h5')
digimg = digimg.astype('float32')
digimg = digimg.reshape(1,28,28,1)

digimg /= 255
prediction = model.predict(digimg)
print(prediction.argmax())

Traceback (most recent call last):
  File "c:\work\vision\digrec.py", line 16, in <module>
    digimg = digimg.reshape(1,28,28,1)
ValueError: cannot reshape array of size 2352 into shape (1,28,28,1)

but the imageio version works.

TO be clear I want to call the digrec code by passing in the image object I already have