jpeg4py.JPEG(path).decode() Open Image Error [How to Solve]

Recorded:

import jpeg4py
path = template_image[0]
im = jpeg4py.JPEG(path).decode()
"""
Note: template_image is ndarray type
"""

1. Error Message:
\jpeg4py._py.JPEGRuntimeError: tjDecompressHeader2() failed with error -1 and error string Not a JPEG

2. Reason: Problem with data type

>>> type(path)
<class 'numpy.str_'>
>>> # Although equal
>>> str(path) == path
True
>>> # But they are different types
>>> type(str(path))
<class 'str'>

3. Solution:

import jpeg4py
path = template_image[0]
im = jpeg4py.JPEG(str(path)).decode()
"""
Note: path-->str(path) 
Type from <class 'numpy.str_'> modify to <class 'str'>
"""

 

Read More: