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

Commit

Permalink
[ImageIO] Fix image io for opencv3.3 (#8757)
Browse files Browse the repository at this point in the history
* fix image io for opencv3.3

* update function in cv_api

* fix bug

* fix lint
  • Loading branch information
sxjscience authored and piiswrong committed Nov 22, 2017
1 parent 5ad6eab commit 1f6d586
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions plugin/opencv/cv_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ MXNET_DLL int MXCVImdecode(const unsigned char *img, const mx_uint len,
ndout.CheckAndAlloc();
cv::Mat buf(1, len, CV_8U, img_cpy);
cv::Mat dst(dims[0], dims[1], flag == 0 ? CV_8U : CV_8UC3, ndout.data().dptr_);
#if (CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >= 3))
cv::imdecode(buf, flag | cv::IMREAD_IGNORE_ORIENTATION, &dst);
#else
cv::imdecode(buf, flag, &dst);
#endif
CHECK(!dst.empty());
delete[] img_cpy;
}, ndout.ctx(), {}, {ndout.var()});
Expand Down
5 changes: 4 additions & 1 deletion src/io/image_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ void ImdecodeImpl(int flag, bool to_rgb, void* data, size_t size,
} else {
dst = cv::Mat(out->shape()[0], out->shape()[1], flag == 0 ? CV_8U : CV_8UC3,
out->data().dptr_);
#if (CV_MAJOR_VERSION > 2 || (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4))
#if (CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >= 3))
cv::imdecode(buf, flag | cv::IMREAD_IGNORE_ORIENTATION, &dst);
CHECK(!dst.empty()) << "Decoding failed. Invalid image file.";
#elif(CV_MAJOR_VERSION > 2 || (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4))
cv::imdecode(buf, flag, &dst);
CHECK(!dst.empty()) << "Decoding failed. Invalid image file.";
#else
Expand Down

0 comments on commit 1f6d586

Please sign in to comment.