From f6187eff28bd61e2c6d1b007001fd7263814c2af Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Thu, 5 Oct 2023 22:07:13 -0700 Subject: [PATCH] testing: Add opencv regression test Make sure we can convert an IC-backed IB to a cv::Mat. Signed-off-by: Larry Gritz --- src/libOpenImageIO/imagebufalgo_test.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libOpenImageIO/imagebufalgo_test.cpp b/src/libOpenImageIO/imagebufalgo_test.cpp index b762988744..2a8fdae647 100644 --- a/src/libOpenImageIO/imagebufalgo_test.cpp +++ b/src/libOpenImageIO/imagebufalgo_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1108,6 +1109,28 @@ test_opencv() auto comp = ImageBufAlgo::compare(src, dst, 0.0f, 0.0f); OIIO_CHECK_EQUAL(comp.error, false); OIIO_CHECK_EQUAL(comp.maxerror, 0.0f); + + // Regression test: reading from ImageBuf-backed image to OpenCV + auto loaded_image = OIIO::ImageBuf("../../testsuite/common/tahoe-tiny.tif", + 0, 0, ImageCache::create()); + OIIO_CHECK_ASSERT(loaded_image.initialized()); + if (!loaded_image.initialized()) { + std::cout << loaded_image.geterror() << 'n'; + return; + } + auto cv_image = cv::Mat {}; + try { + bool ok = OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1); + OIIO_CHECK_ASSERT(ok); + if (!ok) { + std::cout << "Error when converting: " << OIIO::geterror() << '\n'; + return; + } + } catch (const std::exception& e) { + OIIO_CHECK_ASSERT(0); + std::cout << "Error when converting: " << e.what() << '\n'; + return; + } #endif }