Skip to content

Commit

Permalink
testing: Add opencv regression test
Browse files Browse the repository at this point in the history
Make sure we can convert an IC-backed IB to a cv::Mat.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Oct 15, 2023
1 parent a7367a0 commit f6187ef
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libOpenImageIO/imagebufalgo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/imagebufalgo.h>
#include <OpenImageIO/imagebufalgo_util.h>
#include <OpenImageIO/imagecache.h>
#include <OpenImageIO/imageio.h>
#include <OpenImageIO/timer.h>
#include <OpenImageIO/unittest.h>
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f6187ef

Please sign in to comment.