1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
inline std::vector<image_window::overlay_line> render_face_detections (
        const std::vector<full_object_detection>& dets,
        const rgb_pixel color = rgb_pixel(0,255,0)
    )
    {
        std::vector<image_window::overlay_line> lines;
        for (unsigned long i = 0; i < dets.size(); ++i)
        {
            DLIB_CASSERT(dets[i].num_parts() == 68,
                "\t std::vector<image_window::overlay_line> render_face_detections()"
                << "\n\t Invalid inputs were given to this function. "
                << "\n\t dets["<<i<<"].num_parts():  " << dets[i].num_parts() 
            );
 
            const full_object_detection& d = dets[i];
            // Around Chin. Ear to Ear
            for (unsigned long i = 1; i <= 16++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
                
            // Line on top of nose
            for (unsigned long i = 28; i <= 30++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            
            // left eyebrow
            for (unsigned long i = 18; i <= 21++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            // Right eyebrow
            for (unsigned long i = 23; i <= 26++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            // Bottom part of the nose
            for (unsigned long i = 31; i <= 35++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            // Line from the nose to the bottom part above
            lines.push_back(image_window::overlay_line(d.part(30), d.part(35), color));
 
            // Left eye
            for (unsigned long i = 37; i <= 41++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            lines.push_back(image_window::overlay_line(d.part(36), d.part(41), color));
 
            // Right eye
            for (unsigned long i = 43; i <= 47++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            lines.push_back(image_window::overlay_line(d.part(42), d.part(47), color));
 
            // Lips outer part
            for (unsigned long i = 49; i <= 59++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            lines.push_back(image_window::overlay_line(d.part(48), d.part(59), color));
 
            // Lips inside part
            for (unsigned long i = 61; i <= 67++i)
                lines.push_back(image_window::overlay_line(d.part(i), d.part(i-1), color));
            lines.push_back(image_window::overlay_line(d.part(60), d.part(67), color));
        }
        return lines;
    }
cs



1~16 : 턱

18~21 : 왼쪽 눈썹

23~26 : 오른쪽 눈썹

28~30 : 콧대

31~35 : 콧망울

37~41 : 왼쪽 눈

43~47 : 오른쪽 눈

49~59 : 입술 바깥 라인

61~67 : 입술 안쪽 라인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    //cam open
    cv::VideoCapture cap(0);
    if (!cap.isOpened()){
        MessageBox(_T("Cam is not open"));
        return;
    }
 
    //calculate fps values
    time_t start, end;
    double seconds;
    float dFps;
    int count = 0;
 
    //window create
    image_window win;
    //frame
    cv::Mat temp;
 
    //Start Time
    time(&start);
    // Grab and process frames until the main window is closed by the user.
    while (!win.is_closed()){
        // Grab a frame
        cap >> temp;
            
        //End Time
        time(&end);
        //frame plus
        count++;
 
        seconds = difftime(end, start);
        dFps = count / seconds;
 
        cv_image<bgr_pixel> cimg(temp);
 
        rectangle r;            
        //r.set_top(10);
        //r.set_bottom(10);
        //r.set_left(10);
        //r.set_right(10);
 
        stringstream ss;
        ss << "fps : " << dFps << endl;
        string str;
        str = ss.str();
 
        // Display it all on the screen
        win.clear_overlay();
        win.set_image(cimg);
        win.add_overlay(dlib::image_window::overlay_rect(r, rgb_pixel(25500), str));
    }
cs


fps를 출력하는 부분이 이상함(윈도우창 내부가 아니라 테두리에 걸쳐서 시작함)

추후에 수정!

http://www.learnopencv.com/speeding-up-dlib-facial-landmark-detector/

[작업환경]

DLIB버전 : DLIB 19.2 
VS 버전 : vs2015 Community
Debug ver./Release ver.

[DLIB 설치 방법]
1. DLIB 다운
최신 버전으로 다운로드(ver 19.2)

2. Cmake 컴파일
위의 포스트 참조하여 cmake로 컴파일

3. VS 2015 설정
1) 구성 속성 -> 링커 -> 일반 -> 추가 라이브러리 디렉터리
Debug : D:\Program Files (x86)\dlib-19.2(dilb 설치 경로)\build\dlib_build\Debug 추가
Release : D:\Program Files (x86)\dlib-19.2(dilb 설치 경로)\build\dlib_build\Release 추가

2) 구성 속성 -> 링커 -> 입력 -> 추가 종속성
dlib.lib 추가

3) 구성 속성 -> C/C++ -> 전처리기 -> 전처리기 정의
DLIB_JPEG_STATIC
DLIB_JPEG_SUPPORT
DLIB_PNG_STATIC
DLIB_PNG_SUPPORT
추가

4) 프로젝트 파일 소스코드 내부에 dlib 폴더 복사








+ Recent posts