BSI-OFIQ / OFIQ-Project

Open Source Facial Image Quality
Other
38 stars 12 forks source link

cv::imread returning an empty matrix when using libofiq and OpenCV #23

Closed PrefectSol closed 4 months ago

PrefectSol commented 4 months ago

I am trying to use libofiq and OpenCV in my project, but cv::imread is not working correctly. When I build just an OpenCV project, everything is okay and the image reads correctly. However, when I add libofiq to the project, imread returns an empty matrix.

OpenCV version: 4.9.0

Libofiq was installed with ./build.sh

cmake_minimum_required(VERSION 3.12)

project(proj)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_BUILD_TYPE Release)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/lib/OFIQlib/include)
include_directories(${CMAKE_SOURCE_DIR}/lib/onnxruntime-linux-x64-1.14.1/include)

link_directories(${CMAKE_SOURCE_DIR}/lib/OFIQlib/lib)
link_directories(${CMAKE_SOURCE_DIR}/lib/onnxruntime-linux-x64-1.14.1/lib)

file(GLOB SOURCE_FILES src/main.cpp)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE -lofiq_lib)
target_link_libraries(${PROJECT_NAME} PRIVATE -lonnxruntime)

simple test app:

#include <opencv2/opencv.hpp>

int main()
{
cv::Mat image = cv::imread("/input/image.jpg");
cv::imshow("img", image);
cv::waitKey(0);
}

Imread does not throw any errors - it just returns an empty matrix.

bbtams commented 4 months ago

I tried your CMakeLists.txt with OpenCV 4.5 (which is provided by apt in Ubuntu 22.04). There, the image loads when using your sample test app (not an empty matrix).

I suppose there is a conflict when you try to link OpenCV 4.9.0 and OFIQlib which statically contains OpenCV 4.5.5. Do you have the possibility to check if linkage with OpenCV 4.5.5 works?

PrefectSol commented 4 months ago

It didn't help me. I built OpenCV version 4.5.5 and tried it with different versions of GCC - the result is still the same - I used ArchLinux. (empty image)

Gtk-WARNING **: 22:59:06.498: Theme parsing error: gtk.css:6691:68: Invalid name of pseudo-class
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.5) opencv-4.5.5/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Building on a Debian VM helped, maybe there are some dependencies or something else - I don't know. Thanks for the help, and it would be nice to specify compatible versions somewhere. If you have any suggestions about what the problem is, then it would be interesting to know, but in general the problem has been solved

PrefectSol commented 4 months ago

It didn't help me. I built OpenCV version 4.5.5 and tried it with different versions of GCC - the result is still the same - I used ArchLinux. (empty image)

Gtk-WARNING **: 22:59:06.498: Theme parsing error: gtk.css:6691:68: Invalid name of pseudo-class
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.5) opencv-4.5.5/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Building on a Debian VM helped, maybe there are some dependencies or something else - I don't know. Thanks for the help, and it would be nice to specify compatible versions somewhere. If you have any suggestions about what the problem is, then it would be interesting to know, but in general the problem has been solved

The compatible version of gcc is 12.2.0

PrefectSol commented 4 months ago

Sorry, it seems I jumped to conclusions and put together the wrong assembly. Still, OpenCV 4.5.5 does not link to OFIQ, no matter how hard I try. I also tried to build on Ubuntu 22.04, but the error remains

terminate called after throwing an instance of 'cv::Exception'

  what():  OpenCV(4.5.5) /home/prefect/Libraries/opencv-4.5.5/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Aborted (core dumped)
PrefectSol commented 4 months ago

I tried your CMakeLists.txt with OpenCV 4.5 (which is provided by apt in Ubuntu 22.04). There, the image loads when using your sample test app (not an empty matrix).

I suppose there is a conflict when you try to link OpenCV 4.9.0 and OFIQlib which statically contains OpenCV 4.5.5. Do you have the possibility to check if linkage with OpenCV 4.5.5 works?

@bbtams Can you test this code?

#include <opencv2/opencv.hpp>
#include <ofiq_lib.h>

int main()
{
    auto a = OFIQ::Interface::getImplementation();
    cv::Mat image = cv::imread("input/image.jpg");
    cv::imshow("image", image);
    cv::waitKey(0);
}

It is possible that the ofiq_lib connection is omitted during compilation because it is not used

PrefectSol commented 4 months ago

For those who are faced with the same problem, do not use the script build.sh , and make the build yourself in advance by collecting all the libraries that stretch ofiqlib, also paying attention to version compatibility. It helped me.