New file |
| | |
| | | package main |
| | | |
| | | import ( |
| | | "fmt" |
| | | "strconv" |
| | | |
| | | "basic.com/dbapi.git" |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/cache.git/shardmap" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/gopherdiscovery.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | const ( |
| | | prefixTASKSDKRULE = "TASKSDKRULE_" |
| | | ) |
| | | |
| | | var cMap *shardmap.ShardMap |
| | | |
| | | // InitDBAPI init dbapi |
| | | func InitDBAPI(ip string, httpPort, heartBeatPort, dataPort int, log func(...interface{})) { |
| | | dbapi.Init(ip, httpPort) |
| | | var initchan = make(chan bool) |
| | | go InitCache(initchan, ip, heartBeatPort, dataPort) |
| | | log("db init done!", <-initchan) |
| | | } |
| | | |
| | | // TaskInfos get camera infos from sqlite db |
| | | func TaskInfos() []protomsg.TaskSdkInfo { |
| | | tAPI := dbapi.TaskApi{} |
| | | tasks := tAPI.FindAll() |
| | | |
| | | return tasks |
| | | } |
| | | |
| | | // SDKInfo get sdk |
| | | func SDKInfo() []sdkstruct.SDKInfo { |
| | | sAPI := dbapi.SdkApi{} |
| | | |
| | | s := sAPI.FindAllSdkRun() |
| | | var sdks []sdkstruct.SDKInfo |
| | | for _, v := range s { |
| | | sdks = append(sdks, sdkstruct.SDKInfo{ |
| | | IpcID: v.IpcId, |
| | | SdkType: v.SdkType, |
| | | }) |
| | | } |
| | | return sdks |
| | | } |
| | | |
| | | // InitCache cache |
| | | func InitCache(initChan chan bool, dbIP string, surveyPort int, pubSubPort int) { |
| | | cMap = shardmap.New(uint8(32)) |
| | | urlSurvey := "tcp://" + dbIP + ":" + strconv.Itoa(surveyPort) |
| | | urlPubSub := "tcp://" + dbIP + ":" + strconv.Itoa(pubSubPort) |
| | | client, _ := gopherdiscovery.ClientWithSub(urlSurvey, urlPubSub, "analysisProc") |
| | | recvMsg := client.HeartBeatMsg() |
| | | fmt.Println(<-recvMsg) |
| | | |
| | | initCacheData(initChan) |
| | | |
| | | peers, _ := client.Peers() |
| | | for b := range peers { |
| | | fmt.Println("peerMsg:", b) |
| | | updateData(b) |
| | | } |
| | | } |
| | | |
| | | func initCacheData(initChan chan bool) { |
| | | initTaskSdkRule() |
| | | initChan <- true |
| | | } |
| | | |
| | | func initTaskSdkRule() { |
| | | var api dbapi.TaskSdkRuleApi |
| | | |
| | | b, rules := api.FindAllTaskSdkRules() |
| | | if b { |
| | | if rules != nil { |
| | | for _, tRule := range rules { |
| | | cMap.Set(prefixTASKSDKRULE+tRule.TaskId, tRule.SdkRules) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | func updateData(b []byte) { |
| | | newUpdateMsg := &protomsg.DbChangeMessage{} |
| | | if err := proto.Unmarshal(b, newUpdateMsg); err != nil { |
| | | fmt.Println("dbChangeMsg unmarshal err:", err) |
| | | return |
| | | } |
| | | switch newUpdateMsg.Table { |
| | | case protomsg.TableChanged_T_TaskSdkRule: |
| | | initTaskSdkRule() |
| | | default: |
| | | |
| | | } |
| | | } |
| | | |
| | | // GetTaskSdkRules rules |
| | | func GetTaskSdkRules(taskID string) []*protomsg.SdkRuleSet { |
| | | r, b := cMap.Get(prefixTASKSDKRULE + taskID) |
| | | if b { |
| | | return r.([]*protomsg.SdkRuleSet) |
| | | } |
| | | return nil |
| | | } |
New file |
| | |
| | | package main |
| | | |
| | | import ( |
| | | "context" |
| | | "sync" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkhelper.git" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/gogpu.git" |
| | | ) |
| | | |
| | | type face struct { |
| | | handle *SDKFace |
| | | |
| | | maxChannel int |
| | | ftrackChans map[string]chan protomsg.SdkMessage |
| | | ftrackChannels map[string]int |
| | | ftrackChanStats []bool |
| | | chnLock sync.Mutex |
| | | |
| | | fnLogger func(...interface{}) |
| | | |
| | | typ string |
| | | id string |
| | | shm bool |
| | | ipc2Rule string |
| | | ruleMsgMaxCacheSize int |
| | | reserved map[string]string |
| | | } |
| | | |
| | | // Create create sdk |
| | | func Create(config string, typ, id string, gpu int, shm bool, ipc2Rule string, ruleMaxSize int, fn func(...interface{}), reserved map[string]string) interface{} { |
| | | |
| | | handle := NewSDK(fn) |
| | | if handle == nil { |
| | | fn("Face SDK Create Error When New SDK") |
| | | return nil |
| | | } |
| | | cfg, err := sdkhelper.ReadConfig(config) |
| | | if err != nil { |
| | | fn("Face SDK Create Error When Read Config: ", err) |
| | | return nil |
| | | } |
| | | |
| | | // 此处与传入的配置文件param必须一一对应,否则出错 |
| | | dt, dn, da, pt, et, ti, ts, mc, gm := |
| | | "detect_thread", |
| | | "detect_num", |
| | | "detect_angle", |
| | | "property_thread", |
| | | "extract_thread", |
| | | "track_interval", |
| | | "track_sample", |
| | | "max_channel", |
| | | "gpu-memory" |
| | | |
| | | params := []string{dt, dn, da, pt, et, ti, ts, mc, gm} |
| | | |
| | | for _, v := range params { |
| | | if _, ok := cfg.Param[v]; !ok { |
| | | fn("Face SDK Create Error Because of Param Not Found: ", v) |
| | | return nil |
| | | } |
| | | } |
| | | |
| | | w, h, detThrd, detNum, detAngle, propThrd, extThrd, trckInterval, trckSmpl, maxChan, gpuM := |
| | | 1280, 720, sdkhelper.Atoi(cfg.Param[dt]), sdkhelper.Atoi(cfg.Param[dn]), sdkhelper.Atoi(cfg.Param[da]), |
| | | sdkhelper.Atoi(cfg.Param[pt]), sdkhelper.Atoi(cfg.Param[et]), sdkhelper.Atoi(cfg.Param[ti]), sdkhelper.Atoi(cfg.Param[ts]), |
| | | sdkhelper.Atoi(cfg.Param[mc]), sdkhelper.Atoi(cfg.Param[gm]) |
| | | |
| | | if detAngle > 0 { |
| | | } |
| | | |
| | | rGPU := gpu |
| | | |
| | | if rGPU == -1 { |
| | | rGPU = gogpu.ValidGPU(gpuM + 512) |
| | | } |
| | | if rGPU == -1 { |
| | | fn("Face SDK Create Error When Find GPU") |
| | | return nil |
| | | } |
| | | |
| | | if !handle.Tracker(w, h, detNum, trckInterval, trckSmpl, detThrd, rGPU) { |
| | | fn("Face SDK Create Error When Init Tracker") |
| | | return nil |
| | | } |
| | | if !handle.Extractor(extThrd, rGPU) { |
| | | fn("Face SDK Create Error When Init Extractor") |
| | | return nil |
| | | } |
| | | |
| | | if !handle.Propertizer(propThrd) { |
| | | fn("Face SDK Create Error When Init Propertizer") |
| | | return nil |
| | | } |
| | | |
| | | return &face{ |
| | | handle: handle, |
| | | |
| | | maxChannel: maxChan, |
| | | ftrackChans: make(map[string]chan protomsg.SdkMessage, maxChan), |
| | | ftrackChannels: make(map[string]int, maxChan), |
| | | ftrackChanStats: make([]bool, maxChan, maxChan), |
| | | |
| | | fnLogger: fn, |
| | | |
| | | typ: typ, |
| | | id: id, |
| | | shm: shm, |
| | | ipc2Rule: ipc2Rule, |
| | | ruleMsgMaxCacheSize: ruleMaxSize, |
| | | reserved: reserved, |
| | | } |
| | | } |
| | | |
| | | // Run run |
| | | func Run(ctx context.Context, i interface{}) { |
| | | s := i.(*face) |
| | | |
| | | const ( |
| | | postPull = `_1` |
| | | postPush = `_2` |
| | | ) |
| | | ipcRcv := sdkhelper.GetIpcAddress(s.shm, s.id+postPull) |
| | | ipcSnd := sdkhelper.GetIpcAddress(s.shm, s.id+postPush) |
| | | chRcv := make(chan []byte) |
| | | chSnd := make(chan sdkstruct.MsgSDK) |
| | | |
| | | rcver := sdkhelper.NewReciever(ipcRcv, chRcv, s.shm, s.fnLogger) |
| | | snder := sdkhelper.NewSender(ipcSnd, chSnd, s.shm, s.fnLogger) |
| | | torule := sdkhelper.NewToRule(s.ipc2Rule, s.ruleMsgMaxCacheSize, s.fnLogger) |
| | | |
| | | snder.ApplyCallbackFunc(torule.Push) |
| | | |
| | | go rcver.Run(ctx) |
| | | go snder.Run(ctx) |
| | | go torule.Run(ctx) |
| | | |
| | | go s.run(ctx, chRcv, chSnd) |
| | | } |
| | | |
| | | ////////////////////////////////////////////////////////////////// |
| | | const ( |
| | | cacheFrameNum = 3 |
| | | trackChnTimeout = time.Duration(10) |
| | | ) |
| | | |
| | | func (f *face) cleanChnStat() { |
| | | f.chnLock.Lock() |
| | | for i := 0; i < f.maxChannel; i++ { |
| | | f.ftrackChanStats[i] = false |
| | | } |
| | | f.chnLock.Unlock() |
| | | } |
| | | |
| | | func (f *face) getAvailableChn() int { |
| | | f.chnLock.Lock() |
| | | defer f.chnLock.Unlock() |
| | | |
| | | for i := 0; i < f.maxChannel; i++ { |
| | | if f.ftrackChanStats[i] == false { |
| | | f.ftrackChanStats[i] = true |
| | | return i |
| | | } |
| | | } |
| | | return -1 |
| | | } |
| | | |
| | | func (f *face) releaseChn(chn int) { |
| | | f.chnLock.Lock() |
| | | f.ftrackChanStats[chn] = false |
| | | f.chnLock.Unlock() |
| | | } |
| | | |
| | | func (f *face) run(ctx context.Context, in <-chan []byte, out chan<- sdkstruct.MsgSDK) { |
| | | |
| | | chMsg := make(chan protomsg.SdkMessage) |
| | | go sdkhelper.UnserilizeProto(ctx, in, chMsg, f.fnLogger) |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | f.handle.Free() |
| | | return |
| | | case rMsg := <-chMsg: |
| | | if !sdkhelper.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { |
| | | f.fnLogger("FACE TRACK VALIDREMOTEMESSAGE INVALID") |
| | | sdkhelper.EjectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | if _, ok := f.ftrackChans[rMsg.Cid]; ok { |
| | | f.ftrackChans[rMsg.Cid] <- rMsg |
| | | } else { |
| | | |
| | | f.ftrackChans[rMsg.Cid] = make(chan protomsg.SdkMessage, cacheFrameNum) |
| | | chn := f.getAvailableChn() |
| | | if chn < 0 { |
| | | f.fnLogger("TOO MUCH CHANNEL") |
| | | sdkhelper.EjectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | f.ftrackChannels[rMsg.Cid] = chn |
| | | |
| | | i := sdkhelper.UnpackImage(rMsg, f.typ, f.fnLogger) |
| | | if i == nil { |
| | | sdkhelper.EjectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | // conv to bgr24 and resize |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | ret := f.handle.TrackerResize(imgW, imgH, chn) |
| | | f.fnLogger("ResizeFaceTracker: cid: ", rMsg.Cid, " chan: ", chn, " wXh: ", imgW, "x", imgH, " result:", ret) |
| | | go f.detectTrackOneChn(ctx, f.ftrackChans[rMsg.Cid], out, chn) |
| | | f.ftrackChans[rMsg.Cid] <- rMsg |
| | | } |
| | | default: |
| | | time.Sleep(time.Millisecond * 100) |
| | | } |
| | | } |
| | | } |
| | | |
| | | func (f *face) detectTrackOneChn(ctx context.Context, in <-chan protomsg.SdkMessage, out chan<- sdkstruct.MsgSDK, dtchn int) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | f.fnLogger("DETECTTRACKONECHN DTCHN: ", dtchn) |
| | | var curCid string |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return |
| | | |
| | | case rMsg := <-in: |
| | | |
| | | if !sdkhelper.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { |
| | | sdkhelper.EjectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | i := sdkhelper.UnpackImage(rMsg, f.typ, f.fnLogger) |
| | | if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { |
| | | sdkhelper.EjectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | curCid = i.Cid |
| | | |
| | | // conv to bgr24 and resize |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | count, data, _ := f.handle.Run(i.Data, imgW, imgH, 3, dtchn) |
| | | |
| | | sdkhelper.EjectResult(data, rMsg, out) |
| | | var id, name string |
| | | if rMsg.Tasklab != nil { |
| | | id, name = rMsg.Tasklab.Taskid, rMsg.Tasklab.Taskname |
| | | } |
| | | f.fnLogger("CAMERAID: ", rMsg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT ", f.typ, " COUNT: ", count) |
| | | |
| | | sc++ |
| | | if sc == 25 { |
| | | f.fnLogger("CHAN:%d, FACE RUN 25 FRAME USE TIME: ", dtchn, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | if time.Since(tm) > time.Second { |
| | | f.fnLogger("CHAN: ", dtchn, " FACE RUN ", sc, " FRAME USE TIME: ", time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | case <-time.After(trackChnTimeout * time.Second): |
| | | f.fnLogger("Timeout to get image, curCid:", curCid) |
| | | if curCid != "" { |
| | | delete(f.ftrackChans, curCid) |
| | | f.releaseChn(dtchn) |
| | | } |
| | | return |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | go 1.12 |
| | | |
| | | require basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e |
| | | require ( |
| | | basic.com/dbapi.git v0.0.0-20191216030028-03153c1f1f30 |
| | | basic.com/libgowrapper/sdkhelper.git v0.0.0-20191220070838-2d836fec8448 |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c |
| | | basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48 |
| | | basic.com/pubsub/protomsg.git v0.0.0-20191219033725-b95da65535d0 |
| | | basic.com/valib/deliver.git v0.0.0-20190927081905-2d390df9ede3 // indirect |
| | | basic.com/valib/gogpu.git v0.0.0-20190711044327-62043b070865 |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28 |
| | | basic.com/valib/shm.git v0.0.0-20191029034255-156e610f9bca // indirect |
| | | github.com/ajg/form v1.5.1 // indirect |
| | | github.com/gogo/protobuf v1.3.1 |
| | | github.com/gorilla/websocket v1.4.1 // indirect |
| | | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect |
| | | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect |
| | | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect |
| | | google.golang.org/grpc v1.26.0 // indirect |
| | | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect |
| | | nanomsg.org/go-mangos v1.4.0 // indirect |
| | | ) |
| | |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e h1:FIUozkg3tMk0K6cQMOt/DvlpK/A66AMDdCKpE4qlUzc= |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e/go.mod h1:bNdkzVVGY+oQEcaYN9VlyIK/03WB3NQNQApjiPJjIag= |
| | | basic.com/dbapi.git v0.0.0-20191216030028-03153c1f1f30 h1:nesVta2Rf3LAqyFtGAqNOI+Mf9SqHa4gz1Dj38nm5bk= |
| | | basic.com/dbapi.git v0.0.0-20191216030028-03153c1f1f30/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= |
| | | basic.com/libgowrapper/sdkhelper.git v0.0.0-20191220070838-2d836fec8448 h1:fnzmik70HiNRSdeH7QHT+bqEy+eSfSSmXSZOWDff4G4= |
| | | basic.com/libgowrapper/sdkhelper.git v0.0.0-20191220070838-2d836fec8448/go.mod h1:eBHanxa92Srb5c/OmupgcAZmLC3Et5HMp9JsebHAIC4= |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c h1:maWYZw9iSQUuN1jbDxgi9IvKrCD97tiTCv8PkLArZ/I= |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c/go.mod h1:bNdkzVVGY+oQEcaYN9VlyIK/03WB3NQNQApjiPJjIag= |
| | | basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48 h1:BBA30Rgljn6MRieC4gUncETJDyna3ObyubTo9HEQ2M0= |
| | | basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48/go.mod h1:gHLJZz2ee1cGL0X0ae69fs56bAxkDgEQwDhhXZJNUcY= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20191219033725-b95da65535d0 h1:5NOX81GTsRLwbhnHWYU4g6jfcOynSWetmf9PlhK5eLI= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20191219033725-b95da65535d0/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= |
| | | basic.com/valib/deliver.git v0.0.0-20190927081905-2d390df9ede3 h1:VY23IpugB/FsU2hSnVeLjZKX5cSgNmhcSEiw6vxX+bg= |
| | | basic.com/valib/deliver.git v0.0.0-20190927081905-2d390df9ede3/go.mod h1:bkYiTUGzckyNOjAgn9rB/DOjFzwoSHJlruuWQ6hu6IY= |
| | | basic.com/valib/gogpu.git v0.0.0-20190711044327-62043b070865 h1:3XvkNdRlJDXV45ie8U0uGA9ImJZtyTT0C/h+4Rizv0Y= |
| | | basic.com/valib/gogpu.git v0.0.0-20190711044327-62043b070865/go.mod h1:yxux5RP4A6a591vWljXxGlHdERVVyWDD3TwwQjuyogw= |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28 h1:3hejanzPEBvZSSvjIqayB83/6/6SLLrX9oNZAdiYELg= |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28/go.mod h1:CQ+UJyZV8MRzwwckncdUDu6/RDTKAzSIPCxc9tFcwPs= |
| | | basic.com/valib/shm.git v0.0.0-20191029034255-156e610f9bca h1:Y2Lgpxx5Tq0nKSAaB00F4piJhljMgPpfsBGQ2qpEloE= |
| | | basic.com/valib/shm.git v0.0.0-20191029034255-156e610f9bca/go.mod h1:yYRM7bM9y0KKd4IfNt3myjsvkFVFIIWNjsvK14tNbq4= |
| | | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= |
| | | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= |
| | | github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= |
| | | github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= |
| | | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= |
| | | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= |
| | | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= |
| | | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= |
| | | github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= |
| | | github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= |
| | | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= |
| | | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= |
| | | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= |
| | | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= |
| | | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= |
| | | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= |
| | | github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= |
| | | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
| | | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= |
| | | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= |
| | | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= |
| | | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= |
| | | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= |
| | | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= |
| | | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= |
| | | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= |
| | | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
| | | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
| | | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
| | | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
| | | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= |
| | | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= |
| | | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= |
| | | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
| | | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
| | | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
| | | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
| | | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= |
| | | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
| | | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= |
| | | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
| | | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
| | | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
| | | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= |
| | | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= |
| | | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= |
| | | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= |
| | | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= |
| | | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= |
| | | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= |
| | | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= |
| | | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= |
| | | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= |
| | | google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= |
| | | google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= |
| | | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
| | | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
| | | nanomsg.org/go-mangos v1.4.0 h1:pVRLnzXePdSbhWlWdSncYszTagERhMG5zK/vXYmbEdM= |
| | | nanomsg.org/go-mangos v1.4.0/go.mod h1:MOor8xUIgwsRMPpLr9xQxe7bT7rciibScOqVyztNxHQ= |
| | |
| | | */ |
| | | import "C" |
| | | import ( |
| | | "errors" |
| | | "unsafe" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | // SDKFace sdk |
| | |
| | | } |
| | | |
| | | // NewSDK sdk |
| | | func NewSDK(fn func(...interface{})) interface{} { |
| | | func NewSDK(fn func(...interface{})) *SDKFace { |
| | | h := C.create_sdkface() |
| | | if h == nil { |
| | | return nil |
| | |
| | | } |
| | | |
| | | // Free free |
| | | func Free(i interface{}) { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Free() { |
| | | if s != nil && s.handle != nil { |
| | | C.release(s.handle) |
| | | } |
| | |
| | | } |
| | | |
| | | // Detector detector |
| | | func Detector(i interface{}, minFaces, rollAngles, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Detector(minFaces, rollAngles, threadMax, gpu int) bool { |
| | | |
| | | if s.detector { |
| | | return true |
| | | } |
| | |
| | | } |
| | | |
| | | // Extractor ext |
| | | func Extractor(i interface{}, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Extractor(threadMax, gpu int) bool { |
| | | |
| | | if s.extractor { |
| | | return true |
| | | } |
| | |
| | | } |
| | | |
| | | // Propertizer prop |
| | | func Propertizer(i interface{}, threadMax int) bool { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Propertizer(threadMax int) bool { |
| | | |
| | | if s.propertizer { |
| | | return true |
| | | } |
| | |
| | | } |
| | | |
| | | // Tracker track |
| | | func Tracker(i interface{}, w, h, maxFaces, interval, sampleSize, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Tracker(w, h, maxFaces, interval, sampleSize, threadMax, gpu int) bool { |
| | | |
| | | if s.tracker { |
| | | return s.tracker |
| | | } |
| | |
| | | } |
| | | |
| | | // Detect det |
| | | func Detect(s *SDKFace, data []byte, w, h, c int, ch int) []sdkstruct.CFacePos { |
| | | func (s *SDKFace) Detect(data []byte, w, h, c int, ch int) []sdkstruct.CFacePos { |
| | | if !s.detector { |
| | | return nil |
| | | } |
| | |
| | | } |
| | | |
| | | // Extract extract |
| | | func Extract(s *SDKFace, fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) []byte { |
| | | func (s *SDKFace) Extract(fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) []byte { |
| | | |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | |
| | | } |
| | | |
| | | // Compare face compare |
| | | func Compare(i interface{}, feat1 []byte, feat2 []byte) float32 { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) Compare(feat1 []byte, feat2 []byte) float32 { |
| | | |
| | | if s.extractor { |
| | | return 0 |
| | | } |
| | |
| | | } |
| | | |
| | | // Propertize prop |
| | | func Propertize(s *SDKFace, fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) *sdkstruct.CThftResult { |
| | | func (s *SDKFace) Propertize(fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) *sdkstruct.CThftResult { |
| | | if !s.propertizer { |
| | | return nil |
| | | } |
| | |
| | | } |
| | | |
| | | // Track track |
| | | func Track(s *SDKFace, data []byte, w, h, c int, ch int) []sdkstruct.CFaceInfo { |
| | | func (s *SDKFace) Track(data []byte, w, h, c int, ch int) []sdkstruct.CFaceInfo { |
| | | if !s.tracker { |
| | | return nil |
| | | } |
| | |
| | | } |
| | | |
| | | // TrackerResize init face tracker |
| | | func TrackerResize(i interface{}, w, h, ch int) bool { |
| | | s := i.(*SDKFace) |
| | | func (s *SDKFace) TrackerResize(w, h, ch int) bool { |
| | | |
| | | if !s.tracker { |
| | | s.printLog("->face--> TrackerResize Failed, No Tracker Init") |
| | |
| | | } |
| | | |
| | | // Run run |
| | | func Run(i interface{}, data []byte, w, h, c, dchan int) []sdkstruct.CFaceResult { |
| | | func (s *SDKFace) Run(data []byte, w, h, c, dchan int) (int, []byte, error) { |
| | | if data == nil || w <= 0 || h <= 0 { |
| | | return nil |
| | | return 0, nil, errors.New("->face--> Face Input Image Error") |
| | | } |
| | | |
| | | s := i.(*SDKFace) |
| | | |
| | | if !s.tracker || !s.extractor || !s.propertizer { |
| | | return nil |
| | | return 0, nil, errors.New("->face--> Face SDK No Init Correctly") |
| | | } |
| | | |
| | | channel := c |
| | |
| | | channel = 3 |
| | | } |
| | | |
| | | // if !TrackerResize(i, w, h, dchan) { |
| | | // return nil |
| | | // } |
| | | |
| | | var fInfo []sdkstruct.CFaceInfo |
| | | |
| | | fInfo = Track(s, data, w, h, c, dchan) |
| | | fInfo = s.Track(data, w, h, c, dchan) |
| | | if len(fInfo) == 0 { |
| | | return 0, nil, errors.New("->face--> Face Track No One") |
| | | } |
| | | |
| | | var faces []sdkstruct.CFaceResult |
| | | //将sdk返回值转换成protomsg类型 |
| | | var faces []*protomsg.ResultFaceDetect |
| | | |
| | | for _, d := range fInfo { |
| | | |
| | | //运行sd |
| | | dec := FaceInfo2FacePos(d) |
| | | prop := Propertize(s, dec, data, w, h, c, dchan) |
| | | feat := Extract(s, dec, data, w, h, c, dchan) |
| | | p := s.Propertize(dec, data, w, h, c, dchan) |
| | | feat := s.Extract(dec, data, w, h, c, dchan) |
| | | |
| | | result := sdkstruct.CFaceResult{ |
| | | Info: d, |
| | | Prop: *prop, |
| | | Feat: feat, |
| | | } |
| | | faces = append(faces, result) |
| | | /// filter rules |
| | | // sdkid := rMsg.Msg.Tasklab.Sdkinfos[rMsg.Msg.Tasklab.Index].Ipcid |
| | | // size := (d.RcFace.Right - d.RcFace.Left) * (d.RcFace.Bottom - d.RcFace.Top) |
| | | // angle := d.FAngle |
| | | // if !filter(rMsg.Msg.Tasklab.Taskid, sdkid, angle.Confidence, float32(angle.Yaw), int(size)) { |
| | | // continue |
| | | // } |
| | | /// filter rules |
| | | |
| | | prop := (*protomsg.ThftResult)(unsafe.Pointer(&p)) |
| | | fpos := tconvert2ProtoFacePos(d) |
| | | |
| | | //组成结果并序列化 |
| | | res := &protomsg.ResultFaceDetect{Pos: fpos, Result: prop, Feats: feat} |
| | | faces = append(faces, res) |
| | | |
| | | } |
| | | facePos := protomsg.ParamFacePos{Faces: faces} |
| | | d, e := proto.Marshal(&facePos) |
| | | |
| | | return faces |
| | | return len(faces), d, e |
| | | } |
| | | |
| | | func tconvert2ProtoFacePos(dec sdkstruct.CFaceInfo) *protomsg.FacePos { |
| | | |
| | | crect := dec.RcFace |
| | | rect := protomsg.Rect{Left: crect.Left, Top: crect.Top, Right: crect.Right, Bottom: crect.Bottom} |
| | | leftEye := (*protomsg.Point)(unsafe.Pointer(&dec.PtLeftEye)) |
| | | rightEye := (*protomsg.Point)(unsafe.Pointer(&dec.PtRightEye)) |
| | | mouth := (*protomsg.Point)(unsafe.Pointer(&dec.PtMouth)) |
| | | nose := (*protomsg.Point)(unsafe.Pointer(&dec.PtNose)) |
| | | angle := (*protomsg.FaceAngle)(unsafe.Pointer(&dec.FAngle)) |
| | | faceID := uint64(dec.NFaceID) |
| | | |
| | | facialData := dec.PFacialData[:512] |
| | | |
| | | // facialData := make([]byte, 512) |
| | | // copy(facialData[:], dec.PFacialData[:512]) |
| | | |
| | | return &protomsg.FacePos{ |
| | | RcFace: &rect, |
| | | PtLeftEye: leftEye, |
| | | PtRightEye: rightEye, |
| | | PtMouth: mouth, |
| | | PtNose: nose, |
| | | FAngle: angle, |
| | | Quality: dec.NQuality, |
| | | FacialData: facialData, |
| | | FaceID: faceID, |
| | | } |
| | | } |