davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.47k stars 3.37k forks source link

Using dlib with opencv to make "real time" face recognition: conflict between the two librairies? #1205

Closed Toquet closed 6 years ago

Toquet commented 6 years ago

Hello, I am currently working on a project (in c++) that aims at doing face recognition on images coming from a webcam. In order to do so, I use the opencv library which seems to cause issues during the dlib face encoding part:

Expected Behavior

The algorithm is as follow:

As mentioned I need to store the arrays of the known persons before doing the recognition with the webcam. This is where strange things happen:

Current Behavior

It may not be really clear with text so I hope the following code will be more explicit:

Steps to Reproduce

Then as soon as I add the following line, the result of the encoding seems to be random: cv::VideoCapture video(0);

davisking commented 6 years ago

These things (the dlib stuff and openCV tools) have nothing to do with each other. You just have a bug in your code somewhere and it's corrupting the outputs. Maybe you have some kind of memory error. The code you posted has a bunch of raw pointers so that's not helping you. C++ isn't C. You shouldn't have raw pointers or be doing manual memory management.

Toquet commented 6 years ago

I thought it was a memory leak also. However I found an interesting thing: when I run your example program dnn_face_recognition_ex.cpp, everything works fine, the outputs are always the same for the same inputs. However, when I include opencv and I declare a cv::VideoCapture in it, the outputs become random:

cv::VideoCapture video(0);
video.release();

I really believe that there is something strange between the two librairies but I can't find what.

davisking commented 6 years ago

Maybe there is a bug in opencv or you compiled it in some bad way. I don't know. There are no interactions between dlib and opencv though.

Toquet commented 6 years ago

Ok thank you for the answers !

Toquet commented 6 years ago

Just to let you know the end of the story: The issue was caused by the fact that my python libraries were interacting with the c++ ones. I just uninstalled them and reinstalled only the c++ lib and it solved the issue. So you were right! Thank you.