Avoid further decoders loading only .png data using opencv

Viewed 80

I am trying to avoid searching, loading or instantiating any other decoders than the png-Decoder when an image is loaded using opencv's cv::imread or similar functionalities to get a cv::Mat from a .png-file.

However, cv::imread and cv::imdecode do both load several other decoders. Thus I looked up what Decoder-class was instantiated to decode png-data and tried to instantiate and use it in my own png-loader function. This was not successful since the class PngDecoder utilized by the original functions is not accessible from user code.

The code processing the images depends on opencv. I thought about libpng or so, but I wanted to stick to opencv functionalities if possible.

Unfortunately, there is now way for me to compile opencv myself so compiler-flags aren't an option for me at the moment.

Now I was wondering whether any of you guys does know:

  • Is there a way to tell cv::imread or cv::imdecode which decoders to load during runtime?
  • Is there any way to access the specific decoder classes that I didn't found, yet?
  • Is there any known reasons why those classes are hidden from the users in the first place?

Thanks in advance

UPDATE: To avoid further misunderstandings I want to explain the reason for my wish to avoid unnecessary decoders to be loaded:

I compiled my project with gcc's thread sanitizer which informed me about a lock-order-inversion causing a possible deadlock, which matches to some runtime observations I made. The Stacktrace and some code-reduction to determine the responsible code suggested that a cv::imread-call, or more specific a lock of a mutex inside gdal-library within OpenCV code, was the reason for this:

WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=174547)
  Cycle in lock order graph: M456973885219073664 (0x000000000000) => M458095095759505664 (0x000000000000) => M456973885219073664

  Mutex M458095095759505664 acquired here while holding mutex M456973885219073664 in main thread:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4148 (libtsan.so.0+0x4db3a)
    #1 CPLAcquireMutex <null> (libgdal.so.28+0x1074086)

I further investigated how this could happen or how to avoid this. It turned out that on every cv::imread-call gdal dependend decoders were loaded. This brought me to my original question here: How to avoid the loading of unnecessary decoders while loading/decoding images using OpenCV?

0 Answers
Related