OpenImageIO: [BUG] Access violation using IBA::to_OpenCV() with an ImageCache-backed ImageBuf
Describe the bug
I get an Exception 0xc0000005 encountered at address ***: Access violation reading location 0x00000000
while trying to convert a HEIC image to OpenCV format. Here is the PoC I’m working with:
#include <algorithm>
#include <filesystem>
#include <format>
#include <iostream>
#include <ranges>
#include <string>
#include <vector>
#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/imagebufalgo.h>
#include <OpenImageIO/imageio.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include "lib.hpp"
namespace fs = std::filesystem;
namespace rng = std::ranges;
namespace vws = std::ranges::views;
auto main() -> int
{
// Get image paths
auto images = std::vector<fs::path> {};
std::transform(fs::directory_iterator("img/"),
fs::directory_iterator(),
std::back_inserter(images),
[](auto const& entry) { return entry.path(); });
for (auto const& image : images) {
auto loaded_image = OIIO::ImageBuf(image.string());
if (not loaded_image.initialized()) {
std::cout << loaded_image.geterror() << '\n';
continue;
}
auto cv_image = cv::Mat {};
try {
OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1);
cv::imshow(image.filename().string(), cv_image);
}catch(const std::exception& e){
std::cout << "Error when converting: " << e.what() << "\n";
return -1;
}
}
cv::waitKey();
return 0;
}
To Reproduce
- I’m using vcpkg on Windows with
openimageio[libheif,opencv]
as dependencies - In the folder I have .heic images taken with an iPhone
Expected behavior I would expect to see the images shown via OpenCV highUI.
Evidence
When debugging I get a Exception 0xc0000005 encountered at address ***: Access violation reading location 0x00000000
exception.
Platform information:
- OIIO branch/version: 2.4.9.0
- OS: Windows 11
- C++ compiler: Microsoft ® C/C++ Optimizing Compiler Version 19.35.32215 for x64
- Any non-default build flags when you build OIIO:
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15
Commits related to this issue
- fix: IBA::to_OpenCV fails for ImageCache-backed images (#4013) We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed ima... — committed to AcademySoftwareFoundation/OpenImageIO by lgritz 9 months ago
- fix: IBA::to_OpenCV fails for ImageCache-backed images (#4013) We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed ima... — committed to lgritz/OpenImageIO by lgritz 9 months ago
- 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 <lg@larrygritz.com> — committed to AcademySoftwareFoundation/OpenImageIO by lgritz 8 months ago
- fix: IBA::to_OpenCV fails for ImageCache-backed images (#4013) We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed ima... — committed to lgritz/OpenImageIO by lgritz 9 months ago
- 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 <lg@larrygritz.com> — committed to lgritz/OpenImageIO by lgritz 8 months ago
- 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 <lg@larrygritz.com> — committed to lgritz/OpenImageIO by lgritz 8 months ago
Hi! Yes, tested it locally and fully solved the issue for me.