Ask Your Question
1

cv::imread() fails when I use opencv and dlib in single c++ project

asked 2020-01-28 06:03:28 -0500

Amogh gravatar image

updated 2020-06-09 18:11:23 -0500

I have a c++ project created in visual studio 2019. I compiled and build openCV version 4.2.0 and dlib version 19.19.0 and used in my c++ project. My motto using opencv and dlib in single project is I want to do face detection using opencv's DNN (caffe) and dlib's hog + svm based face detector (get_frontal_face_detector()).

My both functions are separate, i.e detectFaceByOpenCVDNN() for opencv based face detection and detectFaceBydlibHOG() for dlib based HOG + SVM based detector.

I added include directory of both projects, lib directories (additional library directories) and mentioned additional dependencies with .lib files.

Build of this project is successful and generates .lib file. By using this file another c++ console application calls for detectFaceByOpenCVDNN() (opencv face detector).

Code of detectFaceByOpenCVDNN():

#include <opencv2/imgcodecs.hpp>
#include <opencv2/dnn/dnn.hpp>

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>

using namespace dlib;
using namespace std;
using namespace cv::dnn;

void namespace_name::FaceDetection::detectFaceByOpenCVDNN(std::string filename)
{    

Net net;        
cv::Mat frame = cv::imread(filename);

if (frame.empty())
    throw std::exception("provided image file is not found or unable to open.");

int frameHeight = frame.rows;
int frameWidth = frame.cols;
    .... // code continues
}

When I this function, I receive exception as "provided image file is not found or unable to open." which is throw if frame.empty() return true. No other exception is displayed on console.

While just digging what makes this fail, I got to know that, If I remove dlib19.19.0_debug_32bit_msvc1924.lib entry from Properties->Linker->Input->Additional Dependencies then frame.empty() returns false and program continues.

One more observation, Even if I remove every code related to dlib (detectFaceBydlibHOG() function, #include entries, using statements) then also cv::imread() fails. But, as soon as I remove entry of dlib19.19.0_debug_32bit_msvc1924.lib from Additional Dependencies program reads image.

Why cv::imread() fails when I use opencv and dlib in single c++ project?

edit retag flag offensive close merge delete

Comments

Can you give exact configuration? debug in 32 bits what is your opencv version? Are you sure that all library are in debug?

LBerger gravatar imageLBerger ( 2020-01-28 06:44:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
5

answered 2020-01-28 11:49:32 -0500

Amogh gravatar image

updated 2020-01-29 05:13:01 -0500

I could able to solve the issue with the guidance from Davis King (owner dlib), It's due to conflict between libjpeg library. As both, opencv and dlib uses it. To solve this, link both opencv and dlib to the same libjpeg. or if that library is not needed by dlib then build it without DLIB_JPEG_SUPPORT and DLIB_PNG_SUPPORT.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-01-28 06:03:28 -0500

Seen: 286 times

Last updated: Jan 29 '20