sunty
2019-07-17 a298411166eb97edcce21ae42b1aeb763af8a8f0
Refactoring face alignment and caching
2个文件已修改
132 ■■■■■ 已修改文件
dbpersoninfo.go 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
esutil/EsApi.go 51 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dbpersoninfo.go
@@ -25,7 +25,7 @@
var Cmap *CmapItem
func Init(){
func Init(indexName string, serverIp string, serverPort string, analyServerId string){
    flag.Parse()
    gosdk.InitFaceExtractor(16, 0)
@@ -41,20 +41,29 @@
        wg.Add(1)
        go func(qs int){
            defer wg.Done()
            escache, err := esutil.DbPersoninfos(qs, *querynum)
            escache, err := esutil.Personinfos(qs, *querynum, indexName, serverIp, serverPort, analyServerId)
            if err != nil {
                fmt.Println(err)
                return
            }
            Cmap.Lock()
            Cmap.Lock()
            var tableidstring string
            for _, value := range escache{
                if _, ok :=Cmap.Cam[value.Tableid]; !ok {
                   Cmap.Cam[value.Tableid]=shardmap.New(uint8(*threadnum))
                // 如果没有tableid  则  tableidstring = capturetable
                if value.Tableid == nil{
                    tableidstring="capturetable"
                }else{
                    tableidstring = value.Tableid
                }
                if _, ok :=Cmap.Cam[tableidstring]; !ok {
                   Cmap.Cam[tableidstring]=shardmap.New(uint8(*threadnum))
                }
                
                Cmap.Cam[value.Tableid].Set(value.Id,value.FaceFeature)
                Cmap.Cam[tableidstring].Set(value.Id,value.FaceFeature)
            }
            Cmap.Unlock()
@@ -66,49 +75,57 @@
    fmt.Println()
}
func Getdbpersonmsg(tableid string, teststring []byte, IsCompare bool) ([]byte) {
func GetComparePersonBaseInfo(tableid []string, faceFeature []byte, compareThreshold int) []byte {
    totalmap := make(map[string]float32)
    if !IsCompare {
    if faceFeature == nil {
        return nil
    }
    if teststring == nil {
        return nil
    }
    if tableid == "" {
        for id, val := range Cmap.Cam{
            fmt.Println("the id is: ", id)
            tmpmap := val.Walk(Printest, teststring)
    if tableid == nil {
        //对比全部
        for _, val := range cache.Cmap.Cam {
            tmpmap := val.Walk(Printest, faceFeature)
            for key, sec := range tmpmap {
                totalmap[key] = sec
                if sec > 70*0.01 {
                    totalmap[key] = sec
                }
            }
        }
    }else{
       for id, value := range Cmap.Cam{
            if id == tableid{
                fmt.Println("the id is: ", id)
                tmpmap :=value.Walk(Printest, teststring)
                for key, sec := range tmpmap {
                    totalmap[key]= sec
                }
                break
    } else {
        for _, tid := range tableid {
            shardins, ok := cache.Cmap.Cam[tid]
            fmt.Println(ok)
            if !ok {
                fmt.Println("get shad error by id", shardins)
                continue
            }
       }
            tmpmap := shardins.Walk(Printest, faceFeature)
            for key, sec := range tmpmap {
                if compareThreshold > 70{
                    if sec > compareThreshold {
                        totalmap[key] = sec
                    }
                }else {
                    if sec > 70*0.01 {
                        totalmap[key] = sec
                    }
                }
            }
        }
    }
    firsttime := time.Now()
    fmt.Println(time.Since(firsttime))
    fmt.Println(totalmap)
    buf, err := json.Marshal(totalmap)
    if err != nil {
        fmt.Println("map to json error!", err)
         return nil
        return nil
    }
    return  buf
    return buf
}
func Printest(ci []byte, co string ) (float32){
esutil/EsApi.go
@@ -10,12 +10,33 @@
        )
// 查询底库人员信息
func DbPersoninfos( queryindex int, querynums int ) ([]*protomsg.Esinfo, error){
func Personinfos( queryIndex int, queryNums int, indexName string, serverIp string, serverPort string, analyServerId string) ([]*protomsg.Esinfo, error){
            var dbinfos []*protomsg.Esinfo
            point   := strconv.Itoa(queryindex)
            number   := strconv.Itoa(querynums)
            var dbinfoRequest =  `  {
            point   := strconv.Itoa(queryIndex)
            number   := strconv.Itoa(queryNums)
            JsonDSL  := ""
            if indexName == "videopersons" {
                 JsonDSL =  `  {
                    "from": ` + point +  `,
                    "query": {
                        "bool": {
                            "filter": [
                                {
                                    "term": {
                                        "analyServerId": ` + analyServerId + `
                                    }
                                }
                            ]
                        }
                    },
                    "size":`+ number +`,
                    "_source": [
                        "id",
                        "faceFeature"
                    ]
                }`
            }else {
                 JsonDSL =  `  {
                    "from": ` + point +  `,        
                    "query": {
                        "match_all": {}
@@ -27,8 +48,8 @@
                       "faceFeature"
                       ]
                    }`
    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtablepersons/dbpersons/_search",[]byte(dbinfoRequest))
            }
    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(JsonDSL))
    if err != nil {
        return dbinfos ,errors.New("http request dbtablename info is err!")
    }
@@ -45,7 +66,7 @@
}
// 根据底库id查询底库信息
func Dbtablefosbyid (id []string) ([]protomsg.Dbtable, error) {
func Dbtablefosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbtable, error) {
    var dbinfo []protomsg.Dbtable
    dbtableId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
        var dbinfoRequest = `
@@ -54,7 +75,7 @@
                    "bool": {
                        "filter": [{
                            "terms": {
                                "_id": [
                                "id": [
                                    "`+ dbtableId +`"
                                ]
                            }
@@ -63,7 +84,7 @@
                }
            }
        `
    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtables/_search",[]byte(dbinfoRequest))
    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
    if err != nil {
        return dbinfo,  err
    }
@@ -78,7 +99,7 @@
}
// 根据底库人员id查询底库人员信息
func Dbpersoninfosbyid (id []string) ([]protomsg.Dbperson, error) {
func Dbpersoninfosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbperson, error) {
    var dbinfo []protomsg.Dbperson
    dbtablePersonId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
    var dbinfoRequest = `
@@ -87,7 +108,7 @@
                    "bool": {
                        "filter": [{
                            "terms": {
                                "_id": [
                                "id": [
                                    "`+ dbtablePersonId +`"
                                ]
                            }
@@ -96,7 +117,7 @@
                }
            }
        `
    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtablepersons/_search",[]byte(dbinfoRequest))
    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
    if err != nil {
        return dbinfo,  err
    }
@@ -112,7 +133,7 @@
}
// 根据tableid 查询tablename
func Dbtablename(tableid string ) (tablename string, err error) {
func Dbtablename(tableid string, indexName string, serverIp string, serverPort string) (tablename string, err error) {
    var dbinfotable =` {
        "query": {
            "bool": {
@@ -130,7 +151,7 @@
        ]
    }
    `
    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtables/_search",[]byte(dbinfotable))
    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfotable))
    if err != nil {
        return "" ,errors.New("http request dbtablename info is err!")
    }