// // Created by basic on 19-8-17. // #include #include #include #include #include #include "extract.h" #include #include 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 lock(mtxImg2Extract, std::defer_lock); while (true) { lock.lock(); if (!qImg2Extr.empty()) { // std::queue 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 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 //faceExtract::compare(BYTE *feature, float threshold) { // compareResults result; // std::vector 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; //}