From 144a7f5e5ff7296d767f333d63b930107c3bfadf Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 18 七月 2019 10:10:19 +0800
Subject: [PATCH] fix init
---
dbpersoninfo.go | 108 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 66 insertions(+), 42 deletions(-)
diff --git a/dbpersoninfo.go b/dbpersoninfo.go
index 7846cd9..cfaa6c2 100644
--- a/dbpersoninfo.go
+++ b/dbpersoninfo.go
@@ -7,11 +7,10 @@
"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"
)
@@ -21,17 +20,17 @@
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()
@@ -42,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 == ""{
+ 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()
@@ -67,44 +75,60 @@
fmt.Println()
}
-//func main(){
-// Init()
-// Getdbpersonmsg("")
-//}
+func GetComparePersonBaseInfo(tableid []string, faceFeature []byte, compareThreshold int) []byte {
-func Getdbpersonmsg(tableid, teststring string, IsCompare bool) ([]byte) {
+ totalmap := make(map[string]float32)
- var buf []byte
- if !IsCompare {
+ if faceFeature == nil {
return nil
}
- if teststring == "" {
- return nil
- }
-
- for id, value := range Cmap.cam{
- if id == tableid{
- fmt.Println(id)
- buf =value.Walk(Printest, teststring)
+ if tableid == nil {
+ //瀵规瘮鍏ㄩ儴
+ for _, val := range Cmap.Cam {
+ tmpmap := val.Walk(Printest, faceFeature)
+ for key, sec := range tmpmap {
+ if sec > 70*0.01 {
+ 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 > 70{
+ if sec > compareThreshold {
+ totalmap[key] = sec
+ }
+ }else {
+ if sec > 70*0.01 {
+ totalmap[key] = sec
+ }
+ }
- fmt.Println()
- fmt.Println()
+ }
- firsttime := time.Now()
- fmt.Println(time.Since(firsttime))
- return buf
+ }
+ }
+
+ 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){
-
- //ci_d, err := base64.StdEncoding.DecodeString(ci)
- //if err != nil {
- // fmt.Println("ci_d : error : ", err)
- // return -1
- //}
+func Printest(ci []byte, co string ) (float32){
co_d, err := base64.StdEncoding.DecodeString(co)
if err != nil {
@@ -112,6 +136,6 @@
return -1
}
- sec := gosdk.FaceCompare([]byte(ci), co_d)
+ sec := gosdk.FaceCompare(ci, co_d)
return sec
}
--
Gitblit v1.8.0