Premature end of JPEG file opencv

  1. Problem description

‘Premature end of JPEG file’ is a warning when using cv2 (python version of opencv ) to read the image, the warning code is located in libjpeg

JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
184	JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
186	         "Corrupt JPEG data: found marker 0x%02x instead of RST%d")

The specific link is

When debugging the positioning image, it is indeed found that the image is broken.

Second, the solution

In order to let the python code catch the exception, the program is modified as follows:

    img =
except IOError:
    img= np.array(img, dtype=np.float32)
except :
    print('corrupt img',absolute_path)

absolute_path is the full path (absolute path) of the file, i.e. file path + file name

Leave a Comment

Your email address will not be published. Required fields are marked *