Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

failed to catch imdecode exception #11912

@nicklhy

Description

@nicklhy

Hi, I just found that I can not catch some IO exceptions if the program failed to load an image when using mxnet's image decoding API. The problem can be produced like below:

import mxnet as mx

print('MXNet version: %s' % mx.__version__)

with open('test.jpg', 'wb') as fd:
    fd.close()

try:
    with open('test.jpg', 'rb') as fd:
        buf = fd.read()
    im = mx.image.imdecode(buf, flag=1, to_rgb=True)
except:
    print('mxnet imdecode failed to load image.')
~ python3 test_imdecode_error.py
MXNet version: 1.3.0
OpenCV Error: Assertion failed (!buf.empty() && buf.isContinuous()) in imdecode_, file /home/lhy/Documents/Lib/opencv-3.4.0/modules/imgcodecs/src/loadsave.cpp, line 711
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/lhy/Documents/Lib/opencv-3.4.0/modules/imgcodecs/src/loadsave.cpp:711: error: (-215) !buf.empty() && buf.isContinuous() in function imdecode_

[1]    28041 abort (core dumped)  python3 test_imdecode_error.py

However, I would like the program to skip the corrupted images and just continue processing others. Is it a bug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions