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.58k stars 3.38k forks source link

do dnn_mmod_face_detection need more configration in project? #1034

Closed jesszgc closed 6 years ago

jesszgc commented 6 years ago

I am working with face detection. when i try to use dlib cnn method for FD, i write a demo code as follows. it works in dnn_mmod_face_detection_ex.cpp, but in my project it stops at "nnnet(img);" without any exception code. do i have to add some extra LIBS or FLAGS in the .pro file(i use qt) ` int cnnfacedetect() { net_type nnnet; deserialize("mmod_human_face_detector.dat") >> nnnet;

cv::VideoCapture cap;
if(!cap.open(0))
{
    std::cout<<"bad cap"<<std::endl;
    return 1;
}
std::cout<<1<<endl;
while (cv::waitKey(1) != 27)
{
    cv::Mat frame;
    matrix<rgb_pixel> img;
    if(!cap.read(frame))
    {
        std::cout<<"video end"<<std::endl;
        break;
    }
    cv::imshow("fff",frame);
    dlib::assign_image(img,cv_image<rgb_pixel>(frame));
    std::cout<<2<<endl;
    double ts=(double)cv::getTickCount();
     std::vector<dlib::mmod_rect> dets ;
    try{
        dets = nnnet(img);
        std::cout<<3<<endl;
    }
    catch (exception& e)
    {
         std::cout<<4<<endl;
        cerr<< e.what();
    }
    double te=(double)cv::getTickCount();
    std::cout<<"facetime::"<<1000*(te-ts)/cv::getTickFrequency()<<endl;
    std::cout<<5<<endl;
    if(dets.size()>0)
    {
        cv::Rect facerect=dlibRectangleToOpenCV111(dets[0].rect);
        cv::rectangle(frame,facerect,cv::Scalar(0,0,255));
    }
    cv::imshow("cnn face detect",frame);
}

`

davisking commented 6 years ago

It’s probably just running out of ram. Use a smaller image or buy more ram.

jesszgc commented 6 years ago

@davisking my image size is 640*480, and the ram is 8GB,with GTX150TI GPU. The code works in the dnn_mmod_face_detection_ex.cpp,but do not work in my project. the output in the console can get 1 and 2,but can never get to 3 or 4.

davisking commented 6 years ago

There aren’t any special compiler options you need to give. So I don’t know what you did to make it not work, but it’s not because there is something dlib specific you need to do.

You should use cmake. It will configure your project correctly.

dlib-issue-bot commented 6 years ago

Warning: this issue has been inactive for 251 days and will be automatically closed on 2018-09-07 if there is no further activity.

If you are waiting for a response but haven't received one it's likely your question is somehow inappropriate. E.g. you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's documentation, or a Google search.

dlib-issue-bot commented 6 years ago

Notice: this issue has been closed because it has been inactive for 255 days. You may reopen this issue if it has been closed in error.