Check whether bytes jpeg is not corrupted jpeg with opencv python

31 Views Asked by At

This cv2.imdecode is only giving warning instead of raising error.

# Decode the JPEG bytes into a numpy array
frame = np.frombuffer(bytes_jpeg, dtype=np.uint8)

# Decode the JPEG numpy array into a frame
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)

Even when I check is none by if frame is None: print('Corrupt'), it's always not printed. How do I catch is bytes_jpeg is corrupted jpeg?

Here is the warnings:

Corrupt JPEG data: premature end of data segment
Corrupt JPEG data: premature end of data segment
Corrupt JPEG data: 45342 extraneous bytes before marker 0xd8
Corrupt JPEG data: 17587 extraneous bytes before marker 0xd9
0

There are 0 best solutions below