| | |
| | | "sync" |
| | | "encoding/base64" |
| | | |
| | | "test/cache/esutil" |
| | | "test/cache/shardmap" |
| | | // "basic.com/pubsub/cache.git/esutil" |
| | | // "basic.com/pubsub/cache.git/shardmap" |
| | | // "basic.com/pubsub/protomsg.git" |
| | | "encoding/json" |
| | | |
| | | "basic.com/pubsub/cache.git/esutil" |
| | | "basic.com/pubsub/cache.git/shardmap" |
| | | |
| | | "basic.com/valib/gosdk.git" |
| | | ) |
| | |
| | | |
| | | type CmapItem struct { |
| | | sync.Mutex |
| | | cam map[string]*shardmap.ShardMap |
| | | Cam map[string]*shardmap.ShardMap |
| | | } |
| | | |
| | | var Cmap *CmapItem |
| | | |
| | | func Init(){ |
| | | func Init(indexName string, serverIp string, serverPort string, analyServerId string){ |
| | | flag.Parse() |
| | | gosdk.InitFaceExtractor(16, 0) |
| | | |
| | | Cmap = &CmapItem{ |
| | | cam: make(map[string]*shardmap.ShardMap), |
| | | Cam: make(map[string]*shardmap.ShardMap), |
| | | } |
| | | |
| | | temptime := time.Now() |
| | |
| | | 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 == ""{ |
| | | 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() |
| | |
| | | fmt.Println() |
| | | } |
| | | |
| | | //func main(){ |
| | | // Init() |
| | | // Getdbpersonmsg("") |
| | | //} |
| | | func GetComparePersonBaseInfo(tableid []string, faceFeature []byte, compareThreshold float32) []byte { |
| | | |
| | | func Getdbpersonmsg(tableid string, teststring []byte, IsCompare bool) ([]byte) { |
| | | totalmap := make(map[string]float32) |
| | | |
| | | var buf []byte |
| | | if !IsCompare { |
| | | if faceFeature == nil { |
| | | return nil |
| | | } |
| | | |
| | | if tableid == "" { |
| | | return nil |
| | | } |
| | | |
| | | if tableid == "" { |
| | | for _, val := range Cmap.cam{ |
| | | tmpbuf := val.Walk(Printest, teststring) |
| | | buf =append(buf, tmpbuf...) |
| | | } |
| | | |
| | | }else{ |
| | | |
| | | for id, value := range Cmap.cam{ |
| | | if id == tableid{ |
| | | fmt.Println(id) |
| | | buf =value.Walk(Printest, teststring) |
| | | break |
| | | if tableid == nil { |
| | | //对比全部 |
| | | for _, val := range Cmap.Cam { |
| | | tmpmap := val.Walk(Printest, faceFeature) |
| | | for key, sec := range tmpmap { |
| | | if sec > 50*0.01 { |
| | | fmt.Println("map为",totalmap[key],sec) |
| | | totalmap[key] = sec |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | for _, tid := range tableid { |
| | | shardins, ok := 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 > 50*0.01{ |
| | | if sec > compareThreshold { |
| | | fmt.Println("map为",totalmap[key],sec) |
| | | totalmap[key] = sec |
| | | } |
| | | }else { |
| | | if sec > 50*0.01 { |
| | | fmt.Println("map为",totalmap[key],sec) |
| | | totalmap[key] = sec |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | fmt.Println() |
| | | fmt.Println() |
| | | fmt.Println(totalmap) |
| | | |
| | | firsttime := time.Now() |
| | | fmt.Println(time.Since(firsttime)) |
| | | return buf |
| | | buf, err := json.Marshal(totalmap) |
| | | if err != nil { |
| | | fmt.Println("map to json error!", err) |
| | | return nil |
| | | } |
| | | return buf |
| | | } |
| | | |
| | | func Printest(ci []byte, co string ) (float32){ |
| | |
| | | } |
| | | |
| | | sec := gosdk.FaceCompare(ci, co_d) |
| | | fmt.Println("比对得分为:",sec) |
| | | return sec |
| | | } |