faustomorales / keras-ocr

A packaged and flexible version of the CRAFT text detector and Keras CRNN recognition model.
https://keras-ocr.readthedocs.io/
MIT License
1.38k stars 355 forks source link

'tools.read()' method crashes when an empty image file is read [possible fix] #141

Open narolski opened 3 years ago

narolski commented 3 years ago

An error:

error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

occurs when an empty image is passed to the cv2.cvtColor(image, cv2.COLOR_BGR2RGB) method in keras_ocr.tools.

It might be worth to handle such a case better, for instance:

image = cv2.imread(image_path)
if np.shape(image) == ():
       return image

return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)