移动端的qt版本人脸流程
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// Created by basic on 19-8-19.
//
 
#include "common.h"
#include <sys/time.h>
#include <stdlib.h>
#include <iostream>
 
std::queue<ImgToExtract *> qImg2Extr;
std::mutex mtxImg2Extract;
 
std::queue<FeatureWithID *> qFeature2Comp;
std::mutex mtxFeature2Comp;
 
std::map<std::string, BYTE*> mFaceRec;
std::map<long, std::string> mIDName;
 
//std::mutex mtxFrameShow;
//std::queue<ImgToShow> qFrameShow;
 
void pushQImg2Extr(ImgToExtract *imgToExtract) {
    std::unique_lock<std::mutex> lock(mtxImg2Extract, std::defer_lock);
    lock.lock();
    if (qImg2Extr.size() > MAX_IMG2EXT) {
        auto imgFaces = qImg2Extr.front();
        std::cout << "qImg2Extr.size() > MAX_IMG2EXT" << &(imgFaces->imgData)<< std::endl;
        delete imgFaces->imgData;
        for (auto face:imgFaces->vFaces) {
            delete face;
        }
        qImg2Extr.pop();
    }
 
    std::cout << "qImg2Extr.push" << std::endl;
    qImg2Extr.push(imgToExtract);
    lock.unlock();
}
 
//ImgToExtract *popQImg2Extr() {
//    std::unique_lock<std::mutex> lock(mtxImg2Extract);
//    if (!qImg2Extr.empty()) {
//        ImgToExtract *imgFaces = qImg2Extr.front();
//        qImg2Extr.pop();
//        return imgFaces;
//    }
//    return nullptr;
//}
 
double msecond(void) {
    struct timeval tv;
    gettimeofday(&tv, 0);
    return (tv.tv_sec * 1.0e3 + tv.tv_usec * 1.0e-3);
}
 
static long int crv_tab[256];
static long int cbu_tab[256];
static long int cgu_tab[256];
static long int cgv_tab[256];
static long int tab_76309[256];
static unsigned char clp[1024];   //for clip in CCIR601
 
void init_yuv420p_table(void) {
    long int crv, cbu, cgu, cgv;
    int i, ind;
 
    crv = 104597;
    cbu = 132201;  /* fra matrise i global.h */
    cgu = 25675;
    cgv = 53279;
 
    for (i = 0; i < 256; i++) {
        crv_tab[i] = (i - 128) * crv;
        cbu_tab[i] = (i - 128) * cbu;
        cgu_tab[i] = (i - 128) * cgu;
        cgv_tab[i] = (i - 128) * cgv;
        tab_76309[i] = 76309 * (i - 16);
    }
 
    for (i = 0; i < 384; i++)
        clp[i] = 0;
    ind = 384;
    for (i = 0; i < 256; i++)
        clp[ind++] = i;
    ind = 640;
    for (i = 0; i < 384; i++)
        clp[ind++] = 255;
}
 
/**
内存分布
                    w
            +--------------------+
            |Y0Y1Y2Y3...         |
            |...                 |   h
            |...                 |
            |                    |
            +--------------------+
            |U0U1      |
            |...       |   h/2
            |...       |
            |          |
            +----------+
            |V0V1      |
            |...       |  h/2
            |...       |
            |          |
            +----------+
                w/2
 */
void yuv420p_to_rgb24_c(unsigned char *yuvbuffer, unsigned char *rgbbuffer, int width, int height) {
    int y1, y2, u, v;
    unsigned char *py1, *py2;
    int i, j, c1, c2, c3, c4;
    unsigned char *d1, *d2;
    unsigned char *src_u, *src_v;
    static int init_yuv420p = 0;
 
    src_u = yuvbuffer + width * height;   // u
    src_v = src_u + width * height / 4;  // v
 
    py1 = yuvbuffer;   // y
    py2 = py1 + width;
    d1 = rgbbuffer;
    d2 = d1 + 3 * width;
 
    if (init_yuv420p == 0) {
        init_yuv420p_table();
        init_yuv420p = 1;
    }
 
    for (j = 0; j < height; j += 2) {
        for (i = 0; i < width; i += 2) {
            u = *src_u++;
            v = *src_v++;
 
            c1 = crv_tab[v];
            c2 = cgu_tab[u];
            c3 = cgv_tab[v];
            c4 = cbu_tab[u];
 
            //up-left
            y1 = tab_76309[*py1++];
            *d1++ = clp[384 + ((y1 + c4) >> 16)];
            *d1++ = clp[384 + ((y1 - c2 - c3) >> 16)];
            *d1++ = clp[384 + ((y1 + c1) >> 16)];
 
            //down-left
            y2 = tab_76309[*py2++];
            *d2++ = clp[384 + ((y2 + c4) >> 16)];
            *d2++ = clp[384 + ((y2 - c2 - c3) >> 16)];
            *d2++ = clp[384 + ((y2 + c1) >> 16)];
 
            //up-right
            y1 = tab_76309[*py1++];
            *d1++ = clp[384 + ((y1 + c4) >> 16)];
            *d1++ = clp[384 + ((y1 - c2 - c3) >> 16)];
            *d1++ = clp[384 + ((y1 + c1) >> 16)];
 
            //down-right
            y2 = tab_76309[*py2++];
            *d2++ = clp[384 + ((y2 + c4) >> 16)];
            *d2++ = clp[384 + ((y2 - c2 - c3) >> 16)];
            *d2++ = clp[384 + ((y2 + c1) >> 16)];
        }
        d1 += 3 * width;
        d2 += 3 * width;
        py1 += width;
        py2 += width;
    }
}