-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Access violation using IBA::to_OpenCV() with an ImageCache-backed ImageBuf #3800
Comments
Sorry this went so long without a response. Do you run into this problem when reading any heic image? If only some of them trigger the exception, can you please supply one that can reproduce the problem? |
Hi, no problem. Thanks for reaching out. Yes, in general with heic images. I downloaded this test image (attached image1.zip) from here: https://github.com/tigranbs/test-heic-images. I tried today with version 2.4.14.0#2 (using vcpkg as toolchain) and the error persists. Here is the minimal code to reproduce: #include <iostream>
#include <string>
#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/imagebufalgo.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace std::string_literals;
auto main() -> int
{
auto file_path = "image1.heic"s;
auto loaded_image = OIIO::ImageBuf(file_path);
if (not loaded_image.initialized()){
std::cout << loaded_image.geterror() << 'n';
return -1;
}
auto cv_image = cv::Mat{};
try{
OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1);
}catch(const std::exception& e){
std::cout << "Error when converting: " << e.what() << '\n';
return -1;
}
cv::imshow(file_path, cv_image);
cv::waitKey();
return 0;
}
|
Thanks for the example. I'm unable to reproduce it on my end, it works fine. (In this case, I'm using OIIO master, on MacOS, with OpenCV 4.8.1). The I would like to suggest that you change the part of your program that calls to_OpenCV to include some error checking: bool ok = OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1);
if (!ok){
std::cout << "Error when converting: " << OIIO::geterror() << '\n';
return -1;
} Does this print anything that might give us additional clues? |
Ohh, that is strange 🤔 I'll try again under WSL and see if I get different results using GCC. This could mean it is an environment issue with my Windows 11 and msvc configuration. I'm attaching the full PoC project with vcpkg and cmake configuration. Probably I have something wrong with how I'm importing the packages. I'll report back with my tests. |
Can you build OIIO in debug mode, run this in gdb and get a stack trace that tells you the full call stack for where this is crashing? |
Hi, sorry for taking so long, I had issues with my dev environment.
I'm running it within WSL2 on Windows 11 using GCC 11.4.0 |
Ok, so I'm going through it step by step. When it reaches the On imagebufalgo_opencv.cpp:
By this moment the source is still valid, but On imagebuf.cpp
cachedpixels() returns false, making the whole thing return nullptr and then the copy_image eventually fails.+ Nonetheless, adding |
The issue was solved adding this before the conversion step:
For some reason the image is not being loaded on demand for HEIF in particular 🤔 |
Yes, in retrospect, this all makes sense! What's happening is that the IB is read lazily, and in this case it's backed underneath by an ImageCache. For such images, the pixeladdr() will be null, but of course, to_OpenCV needs the whole thing in the buffer. Duh. I will have a patch submitted shortly. |
I think this is the correct fix: #4013 |
Awesome! Thank you @lgritz 🙌 |
@jorgemb Are you able to test that patch on your end to verify that it fully solves it for you? |
Hi! Yes, tested it locally and fully solved the issue for me. |
Thanks, @jorgemb. This fix will be in the next OIIO release. |
We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed image. Instead, "wrap" the cv::Mat with an IB and then use IBA::copy(). This handles both in-memory and IC-backed ImageBuf's, and also has many other advantages (such as format conversion) we may wish to take advantage of in the future. Fixes #3800 Signed-off-by: Larry Gritz <[email protected]>
…reFoundation#4013) We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed image. Instead, "wrap" the cv::Mat with an IB and then use IBA::copy(). This handles both in-memory and IC-backed ImageBuf's, and also has many other advantages (such as format conversion) we may wish to take advantage of in the future. Fixes AcademySoftwareFoundation#3800 Signed-off-by: Larry Gritz <[email protected]>
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]>
…reFoundation#4013) We were using parallel_convert_image but not realizing that asking for the IB::localpixels() would give us nullptr for an IC-backed image. Instead, "wrap" the cv::Mat with an IB and then use IBA::copy(). This handles both in-memory and IC-backed ImageBuf's, and also has many other advantages (such as format conversion) we may wish to take advantage of in the future. Fixes AcademySoftwareFoundation#3800 Signed-off-by: Larry Gritz <[email protected]>
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]>
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]>
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:To Reproduce
openimageio[libheif,opencv]
as dependenciesExpected 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:
The text was updated successfully, but these errors were encountered: