移动端的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
//
// Created by basic on 19-8-17.
//
 
#include <cstring>
#include <cstdio>
#include <unistd.h>
#include <iostream>
#include <vector>
#include "extract.h"
#include <opencv2/opencv.hpp>
#include <iostream>
 
faceExtract::faceExtract(int chan) {
    nChannel = chan < MAX_CHANNEL ? chan : MAX_CHANNEL;
 
    initExtract();
}
 
int faceExtract::initExtract() {
    printf("EF_Init:nChannel:%d \n", nChannel);
    int ret = EF_Init(nChannel);
    if (ret != nChannel) {
        printf("EF_Init failed!(ret=%d)\n", ret);
        return -1;
    }
    featureSize = EF_Size();
    return 0;
}
 
void faceExtract::run(int chan) {
    int ret;
    std::cout << "extractThread...chan:" << chan << std::endl;
    if (chan < 0 && chan >= nChannel) {
        std::cout << "error channel!!" << std::endl;
        return;
    }
 
    std::thread t([&](short chan, faceExtract *pThis){
        std::unique_lock<std::mutex> lock(mtxImg2Extract, std::defer_lock);
        while (true) {
            lock.lock();
            if (!qImg2Extr.empty()) {
//                std::queue<ImgToExtract *> faceExtractTmp;
//                swap(faceExtractTmp, qImg2Extr);
                auto imgToExtr = qImg2Extr.front();
                qImg2Extr.pop();
                lock.unlock();
 
//                while (!faceExtractTmp.empty()) {
//                    auto imgToExtr = faceExtractTmp.front();
                    for (auto face:imgToExtr->vFaces) {
                        FeatureWithID *tmpFeat = new FeatureWithID;
                        tmpFeat->feature = new BYTE[pThis->featureSize];
                        tmpFeat->faceID = face->nFaceID;
                        //todo
                        double t1, t2;
                        t1 = msecond();
                        THFI_FacePos facePos;
                        THFT2THFI_V1(face, &facePos);
                        ret = EF_Extract((short) chan, imgToExtr->imgData, imgToExtr->nWidth,
                                         imgToExtr->nHeight, 3, &facePos, tmpFeat->feature);
                        t2 = msecond();
                        printf("EF_Extract time = %04f ms\n", (float) (t2 - t1));
 
                        if (ret == 1) {
//                        std::unique_lock<std::mutex> lock(mtxFeature2Comp);
//                        qFeature2Comp.push(tmpFeat);
//                            std::cout << "qFeature2Comp.push(tmpFeat); ok:id:" << tmpFeat->faceID << std::endl;
 
                            std::string name = compare(tmpFeat->feature, treshCompare);
                            if (!name.empty()) {
                                std::cout << "tmpFeat->faceID:" << tmpFeat->faceID << std::endl;
                                mIDName[tmpFeat->faceID] = name;
                                emit signalTips(std::string(name) + std::string(",请进"));
                            } else {
                                auto it = mIDName.find(tmpFeat->faceID);
                                if (it != mIDName.end()){
                                    emit signalTips(std::string(it->second) + std::string(",请进"));
                                } else {
                                    emit signalTips(std::string("请联系管理员注册"));
                                }
                            }
 
                            delete tmpFeat->feature;
                            delete tmpFeat;
                        } else {
                            delete tmpFeat->feature;
                            delete tmpFeat;
                        }
                    }
                    delete imgToExtr->imgData;
                    for (auto face:imgToExtr->vFaces) {
                        delete face;
                    }
//                    delete imgToExtr;
//                    faceExtractTmp.pop();
//                }
            } else {
                lock.unlock();
                usleep(10000);
            }
        }
    }, short(chan), this);
 
    t.detach();
 
}
 
std::string faceExtract::compare(BYTE* feature, float threshold){
    std::string result;
    float highestScore = 0;
    for (auto &it:mFaceRec) {
        float score = EF_Compare(feature, it.second);
        std::cout << "key = " << it.first << " " << score << " threshold:" << threshold << std::endl;
        if ((score > threshold) && (score > highestScore)) {
            result = it.first;
        }
    }
    return result;
}
 
//compare==============
 
//faceCompare::faceCompare(){
//
//}
//
//faceCompare::~faceCompare() {
//
//}
 
//std::vector<compareResults>
//faceExtract::compare(BYTE *feature, float threshold) {
//    compareResults result;
//    std::vector<compareResults> results;
//    for (auto &it:tableFeatures) {
//        std::cout << "key = " << it.first << "  value = " << it.second << std::endl;
//
//        float score = EF_Compare(feature, it.second);
//        if (score > threshold) {
//            result.featureID = it.first;
//            result.compareScore = score;
//            results.emplace_back(result);
//        }
//    }
//    return results;
//}