Skip to content

Commit 575fd73

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

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

0 commit comments

Comments
 (0)