Skip to content

Commit

Permalink
testing: Add opencv regression test (AcademySoftwareFoundation#4024)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lgritz committed Oct 20, 2023
1 parent 8e5ff58 commit 6f5566b
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 @@ -23,6 +23,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 @@ -1107,6 +1108,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 6f5566b

Please sign in to comment.