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?