add
houxiao
2017-04-21 a3e29fd900f721007c60284ec76092a6154d4e19
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
#include "STFaceCache.h"
#include <MaterialBuffer.h>
#include <logger.h>
#include <map>
 
#include <sys/types.h>
#include <dirent.h>
 
#include "sample_face_search.h"
 
struct STFaceContext
{
    int dbid;
    std::string dbfn;
    stface_handles handles;
};
 
typedef std::map<int, STFaceContext> stface_ctx_map_t; // <dbid, ctx>
 
STFaceCache::STFaceCache(const std::string& _stfacedbPath)
    : stfacedbPath(_stfacedbPath), stfaceModels(STFACESDK_BASE "/models"), _cacheContext(new stface_ctx_map_t)
{
    LOG_INFO << "st face db: " << stfacedbPath << LOG_ENDL;
    LOG_INFO << "st face sdk models: " << stfaceModels << LOG_ENDL;
}
 
STFaceCache::~STFaceCache()
{
    delete (stface_ctx_map_t*)_cacheContext;
    _cacheContext = nullptr;
}
 
bool STFaceCache::load_dbs()
{
    stface_ctx_map_t& cacheContext(*(stface_ctx_map_t*)_cacheContext);
    
    DIR* dp = opendir(stfacedbPath.c_str());
    if (dp != NULL)
    {
        struct dirent* ep;
        while(ep = readdir(dp))
        {
            //puts(ep->d_name);
            
            STFaceContext ctx;
            ctx.dbfn = ep->d_name;
            ctx.dbid = strtol(ctx.dbfn.c_str(), nullptr, 10);
        }
        closedir(dp);
    }
    else
    {
        LOG_ERROR << "Couldn't open the directory." << LOG_ENDL;
        return false;
    }
}
 
FDP_FaceDetectResult STFaceCache::detect(const STFaceImage& img)
{
    stface_ctx_map_t& cacheContext(*(stface_ctx_map_t*)_cacheContext);
    return FDP_FaceDetectResult(0, 0);
}
 
FDP_FaceDetectResult STFaceCache::save(const STFaceImage& img)
{
    stface_ctx_map_t& cacheContext(*(stface_ctx_map_t*)_cacheContext);
    return FDP_FaceDetectResult(0, 0);
}