| | |
| | | "sync" |
| | | "encoding/base64" |
| | | |
| | | "basic.com/pubsub/cache.git/esutil" |
| | | "encoding/json" |
| | | |
| | | "basic.com/pubsub/cache.git/esutil" |
| | | "basic.com/pubsub/cache.git/shardmap" |
| | | |
| | | "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 |
| | | func Init(){ |
| | | type CmapItem struct { |
| | | sync.Mutex |
| | | Cam map[string]*shardmap.ShardMap |
| | | } |
| | | |
| | | var Cmap *CmapItem |
| | | |
| | | func Init(indexName string, serverIp string, serverPort string, analyServerId string){ |
| | | 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.Personinfos(qs, *querynum, indexName, serverIp, serverPort, analyServerId) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return |
| | | } |
| | | |
| | | for _, value := range escache { |
| | | Cmap.Set(value.FaceFeature,value) |
| | | Cmap.Lock() |
| | | |
| | | var tableidstring string |
| | | for _, value := range escache{ |
| | | |
| | | // 如果没有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[tableidstring].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() |
| | | } |
| | | |
| | | //func main(){ |
| | | // Init() |
| | | // Getdbpersonmsg("") |
| | | //} |
| | | func GetComparePersonBaseInfo(tableid []string, faceFeature []byte, compareThreshold float32) []byte { |
| | | |
| | | func Getdbpersonmsg(teststring string) { |
| | | Init() |
| | | totalmap := make(map[string]float32) |
| | | |
| | | if teststring == "" { |
| | | testcache, _:= esutil.DbPersoninfos(0,1) |
| | | teststring = testcache[0].FaceFeature |
| | | if faceFeature == nil { |
| | | return nil |
| | | } |
| | | |
| | | fmt.Println() |
| | | fmt.Println("======华丽的分割线============") |
| | | fmt.Println() |
| | | 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 |
| | | } |
| | | } |
| | | |
| | | firsttime := time.Now() |
| | | Rscore := Cmap.Walk(Printest, teststring) |
| | | fmt.Println(Rscore) |
| | | 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 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) |
| | | fmt.Println("比对得分为:",sec) |
| | | return sec |
| | | } |