Skip to content

Commit 6f5566b

Browse files
committed
testing: Add opencv regression test (AcademySoftwareFoundation#4024)
Testing to make sure we can convert an IC-backed IB to a cv::Mat. Related to issue AcademySoftwareFoundation#3800 and PR AcademySoftwareFoundation#4013 Signed-off-by: Larry Gritz <[email protected]>
1 parent 8e5ff58 commit 6f5566b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libOpenImageIO/imagebufalgo_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <OpenImageIO/imagebuf.h>
2424
#include <OpenImageIO/imagebufalgo.h>
2525
#include <OpenImageIO/imagebufalgo_util.h>
26+
#include <OpenImageIO/imagecache.h>
2627
#include <OpenImageIO/imageio.h>
2728
#include <OpenImageIO/timer.h>
2829
#include <OpenImageIO/unittest.h>
@@ -1107,6 +1108,28 @@ test_opencv()
11071108
auto comp = ImageBufAlgo::compare(src, dst, 0.0f, 0.0f);
11081109
OIIO_CHECK_EQUAL(comp.error, false);
11091110
OIIO_CHECK_EQUAL(comp.maxerror, 0.0f);
1111+
1112+
// Regression test: reading from ImageBuf-backed image to OpenCV
1113+
auto loaded_image = OIIO::ImageBuf("../../testsuite/common/tahoe-tiny.tif",
1114+
0, 0, ImageCache::create());
1115+
OIIO_CHECK_ASSERT(loaded_image.initialized());
1116+
if (!loaded_image.initialized()) {
1117+
std::cout << loaded_image.geterror() << 'n';
1118+
return;
1119+
}
1120+
auto cv_image = cv::Mat {};
1121+
try {
1122+
bool ok = OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1);
1123+
OIIO_CHECK_ASSERT(ok);
1124+
if (!ok) {
1125+
std::cout << "Error when converting: " << OIIO::geterror() << '\n';
1126+
return;
1127+
}
1128+
} catch (const std::exception& e) {
1129+
OIIO_CHECK_ASSERT(0);
1130+
std::cout << "Error when converting: " << e.what() << '\n';
1131+
return;
1132+
}
11101133
#endif
11111134
}
11121135

0 commit comments

Comments
 (0)