From 879a058a10729324fba2a1b9303541672a4e194b Mon Sep 17 00:00:00 2001 From: Xingjian Shi Date: Tue, 21 Nov 2017 15:31:47 -0800 Subject: [PATCH 1/4] fix image io for opencv3.3 --- src/io/image_io.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/io/image_io.cc b/src/io/image_io.cc index d95e750e79f3..32cbe37cc372 100644 --- a/src/io/image_io.cc +++ b/src/io/image_io.cc @@ -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 > 2 && 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 From c9ddc6af114e0860844c553468e337814e1c5353 Mon Sep 17 00:00:00 2001 From: Xingjian Shi Date: Tue, 21 Nov 2017 15:53:41 -0800 Subject: [PATCH 2/4] update function in cv_api --- plugin/opencv/cv_api.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/opencv/cv_api.cc b/plugin/opencv/cv_api.cc index 1508de376d22..4252cc551ee0 100644 --- a/plugin/opencv/cv_api.cc +++ b/plugin/opencv/cv_api.cc @@ -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 > 2 && 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()}); From bd947ed2a6ea82b43fcff1e2430c69b1d4170a68 Mon Sep 17 00:00:00 2001 From: Xingjian Shi Date: Tue, 21 Nov 2017 17:20:04 -0800 Subject: [PATCH 3/4] fix bug --- plugin/opencv/cv_api.cc | 2 +- src/io/image_io.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/opencv/cv_api.cc b/plugin/opencv/cv_api.cc index 4252cc551ee0..1ca14aa4604f 100644 --- a/plugin/opencv/cv_api.cc +++ b/plugin/opencv/cv_api.cc @@ -100,7 +100,7 @@ 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 > 2 && CV_MINOR_VERSION >= 3) +#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); diff --git a/src/io/image_io.cc b/src/io/image_io.cc index 32cbe37cc372..5f01b0eb73ec 100644 --- a/src/io/image_io.cc +++ b/src/io/image_io.cc @@ -156,7 +156,7 @@ 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_MINOR_VERSION >= 3) +#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)) From 9166f9723d770d4bcf60b63de36fa8ef95d8473f Mon Sep 17 00:00:00 2001 From: Xingjian Shi Date: Tue, 21 Nov 2017 18:11:49 -0800 Subject: [PATCH 4/4] fix lint --- src/io/image_io.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/image_io.cc b/src/io/image_io.cc index 5f01b0eb73ec..491370d9a710 100644 --- a/src/io/image_io.cc +++ b/src/io/image_io.cc @@ -159,7 +159,7 @@ void ImdecodeImpl(int flag, bool to_rgb, void* data, size_t size, #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)) +#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