LumiGuide / haskell-opencv

Haskell binding to OpenCV-3.x
Other
154 stars 44 forks source link

`imdecode` can throw C++ exceptions. #143

Closed TravisWhitaker closed 5 years ago

TravisWhitaker commented 5 years ago

The OpenCV documentation for imdecode states:

If the buffer is too short or contains invalid data, the empty matrix/image is returned.

Sadly, this is a lie. imdecode will throw a cv::Exception if the buffer is empty:

>>=import OpenCV.ImgCodecs
m1 = imdecode ImreadColor "this is not a valid image"
>>=matInfo m1
MatInfo {miShape = [], miDepth = Depth_8U, miChannels = 1}
>>=m2 = imdecode ImreadColor ""
>>=matInfo m2
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.5) /build/source/modules/imgcodecs/src/loadsave.cpp:751: error: (-215:Assertion failed) !buf.empty() && buf.isContinuous() in function 'imdecode_'

Aborted

So we're on our own for implementing the documented semantics.

TravisWhitaker commented 5 years ago

@basvandijk @roelvandijk Anything else needed to merge this? The Travis job seems to be unrelatedly broken (other jobs are timing-out).

TravisWhitaker commented 5 years ago

@ocharles @tolysz Any thoughts on this?

TravisWhitaker commented 5 years ago

Pinging recent committers. @roelvandijk @yorickvP @basvandijk @nh2 @CSVdB

ocharles commented 5 years ago

Apologies Travis, I missed all the notifications! Will try and look tomorrow, but at a glance it looks sane.

TravisWhitaker commented 5 years ago

Pinging recent committers. @roelvandijk @yorickvP @basvandijk @nh2 @CSVdB @ocharles

roelvandijk commented 5 years ago

Hi @TravisWhitaker. Sorry for the long wait. I'll take a look and see if I can merge this.

roelvandijk commented 5 years ago

I tested the change and the test suite still passes. We do have some issues related to the new style cabal builds, but that is not related to this issue.