| | |
| | | "sync" |
| | | "encoding/base64" |
| | | |
| | | "basic.com/pubsub/cache.git/esutil" |
| | | "basic.com/pubsub/cache.git/esutil" |
| | | "basic.com/pubsub/cache.git/shardmap" |
| | | "basic.com/pubsub/protomsg.git" |
| | | |
| | | "basic.com/valib/gosdk.git" |
| | | ) |
| | |
| | | var querynum = flag.Int("querynum", 10, "the query number from database") |
| | | var threadnum = flag.Int("threadnum",32, "the number of thread to deal data.") |
| | | |
| | | var Cmap *shardmap.ShardMap |
| | | type CmapItem struct { |
| | | sync.Mutex |
| | | cam map[string]*shardmap.ShardMap |
| | | } |
| | | |
| | | var Cmap *CmapItem |
| | | |
| | | func Init(){ |
| | | flag.Parse() |
| | | gosdk.InitFaceExtractor(16, 0) |
| | | |
| | | Cmap = shardmap.New(uint8(*threadnum)) |
| | | Cmap = &CmapItem{ |
| | | cam: make(map[string]*shardmap.ShardMap), |
| | | } |
| | | |
| | | temptime := time.Now() |
| | | var wg sync.WaitGroup |
| | | |
| | | for i:=0; i<*threadnum; i++ { |
| | | j := i*(*querynum) |
| | | wg.Add(1) |
| | | go func(qs int){ |
| | | defer wg.Done() |
| | | |
| | | escache, err := esutil.DbPersoninfos(qs, *querynum) |
| | | escache, err := esutil.DbPersoninfos(qs, *querynum) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return |
| | | } |
| | | |
| | | for _, value := range escache { |
| | | Cmap.Set(value.FaceFeature,value) |
| | | Cmap.Lock() |
| | | |
| | | for _, value := range escache{ |
| | | if _, ok :=Cmap.cam[value.Tableid]; !ok { |
| | | Cmap.cam[value.Tableid]=shardmap.New(uint8(*threadnum)) |
| | | } |
| | | |
| | | Cmap.cam[value.Tableid].Set(value.Id,value.FaceFeature) |
| | | } |
| | | |
| | | Cmap.Unlock() |
| | | |
| | | }(j) |
| | | } |
| | | wg.Wait() |
| | | fmt.Println("get number of es: ", Cmap.GetLen()) |
| | | fmt.Println("time of get data from es.", time.Since(temptime)) |
| | | fmt.Println() |
| | | } |
| | |
| | | // Getdbpersonmsg("") |
| | | //} |
| | | |
| | | func Getdbpersonmsg(teststring string, IsCompare bool) ([]byte) { |
| | | func Getdbpersonmsg(tableid string, teststring []byte, IsCompare bool) ([]byte) { |
| | | |
| | | var binfos protomsg.Binfos |
| | | var buf []byte |
| | | |
| | | if !IsCompare { |
| | | return nil |
| | | } |
| | | |
| | | if teststring == "" { |
| | | testcache, _:= esutil.DbPersoninfos(0,1) |
| | | teststring = testcache[0].FaceFeature |
| | | if teststring == nil { |
| | | 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 |
| | | } |
| | | } |
| | | } |
| | | |
| | | fmt.Println() |
| | | fmt.Println("======华丽的分割线============") |
| | | fmt.Println() |
| | | |
| | | firsttime := time.Now() |
| | | Rscore := Cmap.Walk(Printest, teststring) |
| | | |
| | | binfos.Infos = append(binfos.Infos, Rscore...) |
| | | binfosbytes, err := binfos.Marshal() |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return nil |
| | | } |
| | | fmt.Println(time.Since(firsttime)) |
| | | return binfosbytes |
| | | return buf |
| | | } |
| | | |
| | | func Printest(ci, co string ) (float32){ |
| | | func Printest(ci []byte, co string ) (float32){ |
| | | |
| | | ci_d, err := base64.StdEncoding.DecodeString(ci) |
| | | if err != nil { |
| | | fmt.Println("ci_d : error : ", err) |
| | | return -1 |
| | | } |
| | | |
| | | co_d, err := base64.StdEncoding.DecodeString(co) |
| | | co_d, err := base64.StdEncoding.DecodeString(co) |
| | | if err != nil { |
| | | fmt.Println("co_d : error : ", err) |
| | | return -1 |
| | | } |
| | | |
| | | sec := gosdk.FaceCompare(ci_d, co_d) |
| | | sec := gosdk.FaceCompare(ci, co_d) |
| | | return sec |
| | | } |