Ask Your Question
0

imageio image vs cv image

asked 2020-04-10 13:39:28 -0600

pm100 gravatar 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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-12 07:23:34 -0600

supra56 gravatar image

Untested. You cannot do exactly from imageio to cv2. The cv2 will take as care of it.

digimg = cv2.imread('cell1.png', cv2.IMREAD_GRAYSCALE))
img_resize = cv2.resize(digimg, (128,128))
img_axis = img_resize[np.newaxis,:,:,np.newaxis]

print(img_axis.shape)
print(np.argmax(model.predict(img_axis)[0]))
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-10 13:39:28 -0600

Seen: 3,860 times

Last updated: Apr 12 '20