pansen
2018-12-18 96024c860270477fe9cf387ba855632a3ead08ee
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Created by ps on 18-12-18.
//
 
#include <Debug.h>
#include "FaceTrackingWrapper.h"
 
using namespace cv;
 
//get current system time
double msecond() {
    struct timeval tv;
    gettimeofday(&tv, 0);
    return (tv.tv_sec * 1.0e3 + tv.tv_usec * 1.0e-3);
}
 
int main(int argc, char **argv) {
 
    ENABLEGLOG("./log/");
    FaceTrackingWrapper faceTrackingWrapper;
 
    bool bOpen;
    VideoCapture vc;
// rtsp stream address
    bOpen = vc.open("rtsp://admin:a1234567@192.168.1.188:554/h264/ch1/main/av_stream");
    //camera
//    if (1) {
//        bool bSet1 = vc.set(CV_CAP_PROP_FRAME_WIDTH, w);
//        bool bSet2 = vc.set(CV_CAP_PROP_FRAME_HEIGHT, h);
//        bOpen = vc.open(devID);
//
//    }
//        //video file
//    else {
//        bOpen = vc.open("test.avi");
//
//    }
    if (!bOpen) {
        printf("Open video source faild.");
        return 0;
    }
 
    int nWidth = vc.get(CV_CAP_PROP_FRAME_WIDTH);
    int nHeight = vc.get(CV_CAP_PROP_FRAME_HEIGHT);
 
    printf("FRAME_WIDTH=%d,FRAME_HEIGHT=%d\n", nWidth, nHeight);
 
 
    BasicFace::InitParam initParam;
    initParam.nDeviceID = 0;
    initParam.nImageWidth = nWidth;
    initParam.nImageHeight = nHeight;
    initParam.nMaxFaceNum = 50;
    initParam.nSampleSize = nWidth / 2;
    initParam.nDetectionIntervalFrame = 12;
 
    faceTrackingWrapper.setChannelParam(0, initParam);
    faceTrackingWrapper.setChannelParam(1, initParam);
    faceTrackingWrapper.setChannelParam(2, initParam);
 
    faceTrackingWrapper.initHandle();
    Mat frame;
 
    while (1) {
 
        vc >> frame;
        if (frame.empty()) {
            waitKey(30);
            continue;
        }
 
        int nNum = 0;
        THFT_FaceInfo *pFaceInfos = new THFT_FaceInfo[50];
        double t1, t2;
        t1 = msecond();
//        nNum = THFT_FaceTracking(2, frame.data, pFaceInfos);
 
        BasicFace::FaceImage faceImage2{frame.cols, frame.rows, frame.step, frame.data};
        auto t_lists = faceTrackingWrapper.trackingFace(2, faceImage2);
        t2 = msecond();
        delete[] pFaceInfos;
        printf("face tracking time=%fms  faceNun is %d\n", t2 - t1, (int) t_lists.size());
 
        imshow("Face Tracking", frame);
        waitKey(30);
    }
    destroyWindow("Face Tracking");
 
    vc.release();
    THFT_Release();
 
    getchar();
    return 0;
 
 
    INFO("test");
 
}