17个文件已删除
7个文件已添加
11个文件已修改
| | |
| | | |
| | | require ( |
| | | basic.com/dbapi.git v0.0.0-20190803074805-04f05c8ca762 |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e |
| | | basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48 |
| | | basic.com/pubsub/protomsg.git v0.0.0-20191121033547-7af037c469a7 |
| | | basic.com/ruleForSdk.git v0.0.0-20190808095604-936797ef5da3 |
| | |
| | | basic.com/valib/godraw.git v0.0.0-20191122082247-26e9987cd183 |
| | | basic.com/valib/gogpu.git v0.0.0-20190711044327-62043b070865 |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28 |
| | | basic.com/valib/gosdk.git v0.0.0-20191120115744-308defe0578c |
| | | basic.com/valib/gosdk.git v0.0.0-20191127014622-8e01cb7623bf |
| | | basic.com/valib/shm.git v0.0.0-20190829074754-ad2e00879627 // indirect |
| | | github.com/ajg/form v1.5.1 // indirect |
| | | github.com/amoghe/distillog v0.0.0-20180726233512-ae382b35b717 |
| | |
| | | "golang.org/x/sys/unix" |
| | | |
| | | "basic.com/valib/gogpu.git" |
| | | "basic.com/valib/gosdk.git" |
| | | // "net/http" |
| | | // _ "net/http/pprof" |
| | | ) |
| | |
| | | gpu int |
| | | shm bool |
| | | ruleIPC string |
| | | soFile string |
| | | ) |
| | | |
| | | const ( |
| | |
| | | flag.StringVar(&id, "id", util.FakeSdkID, "sdk id as ipc label") |
| | | flag.IntVar(&gpu, "gpu", -1, "gpu index") |
| | | flag.BoolVar(&shm, "shm", false, "use shm for performance") |
| | | |
| | | flag.StringVar(&soFile, "so-file", "./", "libcffmpeg.so path") |
| | | |
| | | // 人脸识别参数 |
| | | flag.IntVar(&util.SFI.DetectThrd, util.FaceDetectThread, util.SFI.DetectThrd, "face detect max thread count") |
| | |
| | | |
| | | util.FillParams(util.RuleIPC, util.ToRuleIPC) |
| | | |
| | | util.SetParams("-so-file=" + soFile) |
| | | util.SetParams("-gpu=" + strconv.Itoa(gpu)) |
| | | if logit { |
| | | util.SetParams("-logit") |
| | |
| | | |
| | | cancel() |
| | | |
| | | gosdk.Free() |
| | | logo.Close() |
| | | } |
New file |
| | |
| | | #!/bin/sh |
| | | |
| | | cur_dir=`pwd` |
| | | src=$cur_dir"/libgowrapper" |
| | | |
| | | runtime_dir=$cur_dir"/runtime" |
| | | |
| | | # runtime_dir not exist, then create |
| | | if [ ! -d $runtime_dir ];then |
| | | mkdir $runtime_dir |
| | | echo "~~~CREATE RUNTIME LIBRARY DIRECTORY" |
| | | else |
| | | rm -fr $runtime_dir/* |
| | | fi |
| | | |
| | | cd $src |
| | | |
| | | for value in `ls`; do |
| | | if [ ! -d $src"/"$value ];then |
| | | continue |
| | | fi |
| | | # build so file |
| | | cd $src"/"$value |
| | | go build -buildmode=plugin -o lib$value.so -a |
| | | if [ $? != 0 ]; then |
| | | echo "!!!CREATE lib$value.so FAILED, WATCH IT" |
| | | continue |
| | | fi |
| | | |
| | | # move to runtime_dir |
| | | cp -fr lib$value.so $runtime_dir |
| | | # move sdk to runtime_dir |
| | | if [ -d `pwd`/sdk/lib ]; then |
| | | cp -fr `pwd`/sdk/lib/* $runtime_dir |
| | | fi |
| | | |
| | | if [ -d `pwd`/thirdparty/lib ]; then |
| | | cp -fr `pwd`/thirdparty/lib/* $runtime_dir |
| | | fi |
| | | |
| | | echo "~~~WATCH lib$value.so In $runtime_dir IF CORRECT" |
| | | |
| | | cd $src |
| | | done |
| | |
| | | ) |
| | | |
| | | func prepare(name string, gpu int) (string, bool) { |
| | | |
| | | return initSDK(name, gpu) |
| | | } |
| | | |
| | |
| | | } else if sdkType == work.FCompare { |
| | | e = sdk.NewEFExtract(100) |
| | | } else if sdkType == work.PlateID { |
| | | e = sdk.NewPlateIDDetector(util.SCI.LicenseServerPath, util.SCI.Model, util.SCI.MaxImageWidth, util.SCI.MaxImageHeight) |
| | | e = sdk.NewVehicleDetector(util.SCI.LicenseServerPath, util.SCI.Model, util.SCI.MaxImageWidth, util.SCI.MaxImageHeight) |
| | | } |
| | | |
| | | if ret { |
| | |
| | | os.Exit(130) |
| | | return nil, false |
| | | } |
| | | |
| | | thrds := threads |
| | | if thrds > sdk.MaxFaceDetectThreadNum { |
| | | thrds = sdk.MaxFaceDetectThreadNum |
New file |
| | |
| | | libgfortran.so.3 |
| | |
| | | logo.Infoln("ANALYSIS CREATE SHM") |
| | | } else { |
| | | if d != nil { |
| | | logo.Infoln("~~~~~~shm recv image:", len(d)) |
| | | logo.Infoln("~~~shm recv image:", len(d)) |
| | | dataChan <- d |
| | | } |
| | | } |
| | |
| | | if msg, err := i.Recv(); err != nil { |
| | | // logo.Errorln("recv error : ", err, " url: ", r.ipcURL) |
| | | } else { |
| | | logo.Infoln("~~~~~~mangos recv image:", len(msg)) |
| | | logo.Infoln("~~~mangos recv image:", len(msg)) |
| | | dataChan <- msg |
| | | } |
| | | } |
| | |
| | | package work |
| | | |
| | | import ( |
| | | "analysis/goconv" |
| | | "analysis/logo" |
| | | |
| | | "context" |
| | |
| | | |
| | | if int(i.Msg.Tasklab.Index+1) == len(i.Msg.Tasklab.Sdkinfos) { |
| | | if s.fn != nil { |
| | | imgInfo := unpackImage(i, "sender") |
| | | if imgInfo.Data == nil { |
| | | continue |
| | | } |
| | | imgProto := protomsg.Image{ |
| | | Data: goconv.YUV2BGR(imgInfo.Data, int(imgInfo.Width), int(imgInfo.Height)), |
| | | Width: int32(imgInfo.Width), |
| | | Height: int32(imgInfo.Height), |
| | | Timestamp: imgInfo.Timestamp, |
| | | Id: imgInfo.Id, |
| | | Cid: imgInfo.Cid, |
| | | } |
| | | var sendData []byte |
| | | if b, err := proto.Marshal(&imgProto); err == nil { |
| | | i.Msg.Data = b |
| | | sendData, err = proto.Marshal(&i.Msg) |
| | | if err != nil { |
| | | continue |
| | | } |
| | | } |
| | | |
| | | sFlag := true |
| | | for _, v := range i.Msg.Tasklab.Sdkinfos { |
| | | if len(v.Sdkdata) < 2 { |
| | |
| | | break |
| | | } |
| | | } |
| | | s.fn(sendData, sFlag) |
| | | s.fn(d, sFlag) |
| | | |
| | | } |
| | | } |
| | |
| | | */ |
| | | import "C" |
| | | import ( |
| | | "analysis/goconv" |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | | "fmt" |
| | | "time" |
| | | "unsafe" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/gosdk.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | func tconvert2ProtoFacePos(dec gosdk.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, |
| | | } |
| | | } |
| | | |
| | | const ( |
| | | CacheFrameNum = 3 |
| | | TrackChnTimeout = time.Duration(10) |
| | | cacheFrameNum = 3 |
| | | trackChnTimeout = time.Duration(10) |
| | | ) |
| | | |
| | | func (e *EFDetect) cleanChnStat() { |
| | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | e.fnFree(e.handle) |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | |
| | | e.ftrackChans[rMsg.Msg.Cid] <- rMsg |
| | | } else { |
| | | |
| | | e.ftrackChans[rMsg.Msg.Cid] = make(chan work.MsgRS, CacheFrameNum) |
| | | e.ftrackChans[rMsg.Msg.Cid] = make(chan work.MsgRS, cacheFrameNum) |
| | | chn := e.getAvailableChn() |
| | | if chn < 0 { |
| | | logo.Infof("TOO MUCH CHANNEL") |
| | |
| | | } |
| | | // conv to bgr24 and resize |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | ret := gosdk.ResizeFaceTracker(e.ftrackChannels[rMsg.Msg.Cid], imgW, imgH) |
| | | ret := e.fnTrackerResize(e.handle, e.ftrackChannels[rMsg.Msg.Cid], imgW, imgH) |
| | | logo.Infof("ResizeFaceTracker: cid:%s, chan:%d, wXh:%d x %d ,result:%d\n", |
| | | rMsg.Msg.Cid, e.ftrackChannels[rMsg.Msg.Cid], imgW, imgH, ret) |
| | | go e.detectTrackOneChn(ctx, e.ftrackChans[rMsg.Msg.Cid], out, typ, e.ftrackChannels[rMsg.Msg.Cid]) |
| | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | goconv.Free() |
| | | return |
| | | |
| | | case rMsg := <-in: |
| | | |
| | | if !validRemoteMessage(rMsg, typ) { |
| | |
| | | |
| | | // conv to bgr24 and resize |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | bgrData := goconv.YUV2BGR(i.Data, imgW, imgH) |
| | | if bgrData == nil { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | img := gosdk.SDKImage{Data: bgrData, Width: imgW, Height: imgH} |
| | | |
| | | detect := gosdk.FaceTrackSimple(img, dtchn) |
| | | fRes := e.fnRun(e.handle, i.Data, imgW, imgH, 3, dtchn) |
| | | |
| | | var faces []*protomsg.ResultFaceDetect |
| | | |
| | | //将sdk返回值转换成protomsg类型 |
| | | for _, d := range detect { |
| | | for _, r := range fRes { |
| | | |
| | | d := r.Info |
| | | /// 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) |
| | |
| | | } |
| | | /// filter rules |
| | | |
| | | //运行sd |
| | | dec := gosdk.FaceInfo2FacePos(d) |
| | | prop := gosdk.FaceProperty(dec, img, dtchn) |
| | | feat := gosdk.FaceExtract(dec, img, dtchn) |
| | | |
| | | resP := (*protomsg.ThftResult)(unsafe.Pointer(&prop)) |
| | | |
| | | result := tconvert2ProtoFacePos(d) |
| | | feat := r.Feat |
| | | prop := (*protomsg.ThftResult)(unsafe.Pointer(&r.Prop)) |
| | | fpos := tconvert2ProtoFacePos(d) |
| | | |
| | | //组成结果并序列化 |
| | | res := &protomsg.ResultFaceDetect{Pos: result, Result: resP, Feats: feat} |
| | | res := &protomsg.ResultFaceDetect{Pos: fpos, Result: prop, Feats: feat} |
| | | faces = append(faces, res) |
| | | |
| | | } |
| | | |
| | | var err error |
| | | var data []byte |
| | | if len(faces) > 0 { |
| | | |
| | | // logo.Infoln("CID: ", rMsg.Msg.Cid, " TASK: ", rMsg.Msg.Tasklab.Taskid, " FACE TRACK OBJS: ", len(faces)) |
| | | |
| | | facePos := protomsg.ParamFacePos{Faces: faces} |
| | | data, err = proto.Marshal(&facePos) |
| | | if err != nil { |
| | | logo.Errorln("fdetect marshal proto face pos error", err) |
| | | fmt.Println("fdetect marshal proto face pos error", err) |
| | | data = nil |
| | | } |
| | | } |
| | |
| | | if rMsg.Msg.Tasklab != nil { |
| | | id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname |
| | | } |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT FACE COUNT: ", len(faces)) |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT FACE COUNT: ", len(fRes)) |
| | | |
| | | sc++ |
| | | if sc == 25 { |
| | | logo.Infoln("chan:%d, FACE RUN 25 FRAME USE TIME: ", dtchn, time.Since(tm)) |
| | | logo.Infoln("CHAN:%d, FACE RUN 25 FRAME USE TIME: ", dtchn, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | if time.Since(tm) > time.Second { |
| | | logo.Infof("cahn:%d, FACE RUN %d FRAME USE TIME: %v", dtchn, sc, time.Since(tm)) |
| | | logo.Infof("CHAN:%d, FACE RUN %d FRAME USE TIME: %v", dtchn, sc, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | case <-time.After(TrackChnTimeout * time.Second): |
| | | case <-time.After(trackChnTimeout * time.Second): |
| | | logo.Errorln("Timeout to get image, curCid:", curCid) |
| | | if curCid != "" { |
| | | delete(e.ftrackChans, curCid) |
| | |
| | | } |
| | | } |
| | | |
| | | //func (e *EFDetect) detectTrack(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | // tm := time.Now() |
| | | // sc := 0 |
| | | // |
| | | // for { |
| | | // select { |
| | | // case <-ctx.Done(): |
| | | // goconv.Free() |
| | | // return |
| | | // default: |
| | | // rMsg := <-in |
| | | // validMsg := validRemoteMessage(rMsg, typ) |
| | | // |
| | | // i := unpackImage(rMsg, typ) |
| | | // if i == nil { |
| | | // ejectResult(nil, rMsg, out) |
| | | // continue |
| | | // } |
| | | // |
| | | // // conv to bgr24 and resize |
| | | // imgW, imgH := int(i.Width), int(i.Height) |
| | | // resizeW, resizeH := util.SFI.TrackPicWidth, util.SFI.TrackPicHeight |
| | | // fx := (float64)(resizeW) / (float64)(imgW) |
| | | // fy := (float64)(resizeH) / (float64)(imgH) |
| | | // |
| | | // origData, resizeData := goconv.YUV2BGRandResize(i.Data, goconv.PIX_FMT_NV12, imgW, imgH, fx, fy) |
| | | // if origData == nil { |
| | | // ejectResult(nil, rMsg, out) |
| | | // continue |
| | | // } |
| | | // // resize to track |
| | | // if imgW < resizeW && imgH < resizeH { |
| | | // resizeData = origData |
| | | // resizeW, resizeH = imgW, imgH |
| | | // } |
| | | // // resize to track |
| | | // |
| | | // img := gosdk.SDKImage{Data: origData, Width: imgW, Height: imgH} |
| | | // imgTrack := gosdk.SDKImage{Data: resizeData, Width: resizeW, Height: resizeH} |
| | | // if !validMsg { |
| | | // ejectResult(nil, rMsg, out) |
| | | // continue |
| | | // } |
| | | // //运行sdk |
| | | // c, ok, _ := e.q.Get() |
| | | // if !ok { |
| | | // logo.Errorln("fdetect there is no idle thread") |
| | | // ejectResult(nil, rMsg, out) |
| | | // continue |
| | | // } |
| | | // detect := gosdk.FaceTrackSimple(imgTrack, c.(int)) |
| | | // e.q.Put(c) |
| | | // |
| | | // // if len(detect) > 0 { |
| | | // // logo.Infof("FACE DETECT FROM CAMERA %s IMAGE-ID %d, TASKID %s, %d FACES COUNT\n", rMsg.Msg.Cid, i.Id, rMsg.Msg.Tasklab.Taskid, len(detect)) |
| | | // // } |
| | | // |
| | | // var faces []*protomsg.ResultFaceDetect |
| | | // |
| | | // //将sdk返回值转换成protomsg类型 |
| | | // for _, d := range detect { |
| | | // |
| | | // /// 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 |
| | | // |
| | | // if fx < 1.0 || fy < 1.0 { |
| | | // d.RcFace.Left = (int32)((float64)(d.RcFace.Left) / fx) |
| | | // d.RcFace.Top = (int32)((float64)(d.RcFace.Top) / fy) |
| | | // d.RcFace.Right = (int32)((float64)(d.RcFace.Right) / fx) |
| | | // d.RcFace.Bottom = (int32)((float64)(d.RcFace.Bottom) / fy) |
| | | // d.PtLeftEye.X = (int32)((float64)(d.PtLeftEye.X) / fx) |
| | | // d.PtLeftEye.Y = (int32)((float64)(d.PtLeftEye.Y) / fy) |
| | | // d.PtRightEye.X = (int32)((float64)(d.PtRightEye.X) / fx) |
| | | // d.PtRightEye.Y = (int32)((float64)(d.PtRightEye.Y) / fy) |
| | | // d.PtMouth.X = (int32)((float64)(d.PtMouth.X) / fx) |
| | | // d.PtMouth.Y = (int32)((float64)(d.PtMouth.Y) / fy) |
| | | // d.PtNose.X = (int32)((float64)(d.PtNose.X) / fx) |
| | | // d.PtNose.Y = (int32)((float64)(d.PtNose.Y) / fy) |
| | | // |
| | | // faceData := d.PFacialData[:8192] |
| | | // data := C.CBytes(faceData) |
| | | // defer C.free(data) |
| | | // resizeP := C.resize(&data, C.float(fx), C.float(fy)) |
| | | // fd := C.GoBytes(resizeP, 8192) |
| | | // d.PFacialData = *(*[8192]uint8)(unsafe.Pointer(&fd[0])) |
| | | // |
| | | // } |
| | | // |
| | | // //运行sd |
| | | // dec := gosdk.FaceInfo2FacePos(d) |
| | | // |
| | | // c, ok, _ := e.qprop.Get() |
| | | // if !ok { |
| | | // logo.Errorln("fproperty there is no idle thread") |
| | | // continue |
| | | // } |
| | | // prop := gosdk.FaceProperty(dec, imgTrack, c.(int)) |
| | | // e.qprop.Put(c) |
| | | // |
| | | // c, ok, _ = e.qext.Get() |
| | | // if !ok { |
| | | // logo.Errorln("fextract there is no idle thread") |
| | | // continue |
| | | // } |
| | | // feat := gosdk.FaceExtract(dec, imgTrack, c.(int)) |
| | | // e.qext.Put(c) |
| | | // |
| | | // resP := (*protomsg.ThftResult)(unsafe.Pointer(&prop)) |
| | | // |
| | | // result := tconvert2ProtoFacePos(d) |
| | | // |
| | | // //组成结果并序列化 |
| | | // res := &protomsg.ResultFaceDetect{Pos: result, Result: resP, Feats: feat} |
| | | // faces = append(faces, res) |
| | | // |
| | | // } |
| | | // |
| | | // var err error |
| | | // var data []byte |
| | | // if len(faces) > 0 { |
| | | // |
| | | // // logo.Infoln("CID: ", rMsg.Msg.Cid, " TASK: ", rMsg.Msg.Tasklab.Taskid, " FACE TRACK OBJS: ", len(faces)) |
| | | // |
| | | // facePos := protomsg.ParamFacePos{Faces: faces} |
| | | // data, err = proto.Marshal(&facePos) |
| | | // if err != nil { |
| | | // logo.Errorln("fdetect marshal proto face pos error", err) |
| | | // data = nil |
| | | // } |
| | | // } |
| | | // |
| | | // // logo.Infoln("CURRENT INDEX: ",rMsg.Msg.Tasklab.Index) |
| | | // rMsg.BGRImg = &img |
| | | // ejectResult(data, rMsg, out) |
| | | // |
| | | // sc++ |
| | | // if sc == 25 { |
| | | // logo.Infoln("FACE RUN 25 FRAME USE TIME: ", time.Since(tm)) |
| | | // sc = 0 |
| | | // tm = time.Now() |
| | | // } |
| | | // |
| | | // if time.Since(tm) > time.Second { |
| | | // logo.Infof("FACE RUN %d FRAME USE TIME: %v", sc, time.Since(tm)) |
| | | // sc = 0 |
| | | // tm = time.Now() |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | //} |
| | | 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, |
| | | } |
| | | } |
| | |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | | "plugin" |
| | | "sync" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | |
| | | "basic.com/valib/gogpu.git" |
| | | "basic.com/valib/gosdk.git" |
| | | ) |
| | | |
| | | type faceInfo struct { |
| | | pos gosdk.CFacePos |
| | | id uint64 |
| | | life int |
| | | } |
| | | |
| | | type fTrackInfo struct { |
| | | lastTrackInfos []faceInfo |
| | | lastTrackID uint64 |
| | | } |
| | | |
| | | const MaxFaceDetectThreadNum = 32 |
| | | |
| | |
| | | iGPU int |
| | | |
| | | // track |
| | | faceAngle int |
| | | dftfacenum int |
| | | dftinterval int |
| | | sampleSize int |
| | | |
| | | // external track |
| | | tracker map[string]*fTrackInfo |
| | | faceAngle int |
| | | faceNum int |
| | | interval int |
| | | sampleSize int |
| | | |
| | | ftrackChans map[string]chan work.MsgRS |
| | | ftrackChannels map[string]int |
| | | ftrackChanStats []bool |
| | | chnLock sync.Mutex |
| | | |
| | | handle interface{} |
| | | fnInit func() interface{} |
| | | fnFree func(interface{}) |
| | | fnRun func(interface{}, []byte, int, int, int, int) []sdkstruct.CFaceResult |
| | | fnTrackerResize func(interface{}, int, int, int) bool |
| | | fnExtractor func(interface{}, int, int) bool |
| | | fnPropertizer func(interface{}, int) bool |
| | | fnTracker func(interface{}, int, int, int, int, int, int, int) bool |
| | | } |
| | | |
| | | // NewEFDetectWithTrack with track |
| | | func NewEFDetectWithTrack(gi, thrds, faceNum, faceAngle, interval, samp int) *EFDetect { |
| | | soFile := "libface.so" |
| | | |
| | | plug, err := plugin.Open(soFile) |
| | | if err != nil { |
| | | logo.Errorln("Open: ", soFile, " error: ", err) |
| | | return nil |
| | | } |
| | | |
| | | fnInit, _ := LoadFunc(plug, soFile, "NewSDK") |
| | | fnFree, _ := LoadFunc(plug, soFile, "Free") |
| | | fnRun, _ := LoadFunc(plug, soFile, "Run") |
| | | fnTrackerResize, _ := LoadFunc(plug, soFile, "TrackerResize") |
| | | fnExtractor, _ := LoadFunc(plug, soFile, "Extractor") |
| | | fnPropertizer, _ := LoadFunc(plug, soFile, "Propertizer") |
| | | fnTracker, _ := LoadFunc(plug, soFile, "Tracker") |
| | | |
| | | return &EFDetect{ |
| | | threads: thrds, |
| | | faceAngle: faceAngle, |
| | | ftrackChans: make(map[string]chan work.MsgRS, MaxFaceDetectThreadNum), |
| | | ftrackChannels: make(map[string]int, MaxFaceDetectThreadNum), |
| | | ftrackChanStats: make([]bool, MaxFaceDetectThreadNum, MaxFaceDetectThreadNum), |
| | | dftfacenum: faceNum, |
| | | dftinterval: interval, |
| | | faceNum: faceNum, |
| | | interval: interval, |
| | | iGPU: gi, |
| | | sampleSize: samp, |
| | | |
| | | handle: nil, |
| | | fnInit: fnInit.(func() interface{}), |
| | | fnFree: fnFree.(func(interface{})), |
| | | fnRun: fnRun.(func(interface{}, []byte, int, int, int, int) []sdkstruct.CFaceResult), |
| | | fnTrackerResize: fnTrackerResize.(func(interface{}, int, int, int) bool), |
| | | fnExtractor: fnExtractor.(func(interface{}, int, int) bool), |
| | | fnPropertizer: fnPropertizer.(func(interface{}, int) bool), |
| | | fnTracker: fnTracker.(func(interface{}, int, int, int, int, int, int, int) bool), |
| | | } |
| | | } |
| | | |
| | |
| | | gpu = gogpu.ValidGPU(2048) |
| | | } |
| | | |
| | | gosdk.InitFaceTracker(e.threads, gpu, 1280, 720, e.dftfacenum, e.dftinterval, e.sampleSize) // i not work |
| | | logo.Infoln("ftrack use gpu: ", gpu) |
| | | e.handle = e.fnInit() |
| | | |
| | | gosdk.InitFaceProperty(e.threads) |
| | | gosdk.InitFaceExtractor(e.threads, gpu) |
| | | logo.Infoln("fextract use gpu: ", gpu) |
| | | if !e.fnTracker(e.handle, 1280, 720, e.faceNum, e.interval, e.sampleSize, e.threads, gpu) { |
| | | logo.Errorln("FACE TRACKER CREATE ERROR") |
| | | } |
| | | logo.Infoln("Face Tracker Use GPU: ", gpu) |
| | | |
| | | if !e.fnPropertizer(e.handle, e.threads) { |
| | | logo.Errorln("FACE PROPERTIZER CREATE ERROR") |
| | | } |
| | | |
| | | if !e.fnExtractor(e.handle, e.threads, gpu) { |
| | | logo.Errorln("FACE EXTRACTOR CREATE ERROR") |
| | | } |
| | | |
| | | logo.Infoln("Face Extractor Use GPU: ", gpu) |
| | | } |
| | | |
| | | // Run impl interface |
| | |
| | | |
| | | // Init impl interface |
| | | func (e *EFExtract) Init() bool { |
| | | // i := gogpu.IdleGPU(100) |
| | | // if i < 0 { |
| | | // logo.Errorln("there is no gpu resource to run faceextract") |
| | | // return false |
| | | // } |
| | | // gosdk.InitFaceExtractor(10, -1) // i not work |
| | | |
| | | return true |
| | | } |
| | |
| | | // Run impl interface |
| | | func (e *EFExtract) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | |
| | | // if typ == work.FCompare { |
| | | // runCompare(ctx, in, out, typ) |
| | | // return |
| | | // } |
| | | loop: |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | break loop |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | | // if !validRemoteMessage(rMsg, typ) { |
| | | // continue |
| | | // } |
| | | // i := unpackImage(rMsg, typ) |
| | | // if i == nil { |
| | | // continue |
| | | // } |
| | | |
| | | // var dataF []byte |
| | | // for _, v := range rMsg.Msg.Tasklab.Sdkinfos { |
| | | // if v.Sdktype == work.FDetect { |
| | | // dataF = v.Sdkdata |
| | | // break |
| | | // } |
| | | // } |
| | | // if dataF == nil { |
| | | // continue |
| | | // } |
| | | // var err error |
| | | // // 反序列化数据得到sdk入参 |
| | | // param := protomsg.ParamFacePos{} |
| | | // // dataF := rMsg.Msg.Tasklab.Sdkinfos[rMsg.Msg.Tasklab.Index].Sdkdata |
| | | // err = proto.Unmarshal(dataF, ¶m) |
| | | // if err != nil { |
| | | // ejectResult(nil, rMsg, out) |
| | | // continue |
| | | // } |
| | | |
| | | // var data []byte |
| | | // if param.Faces != nil { |
| | | // var extComp []*protomsg.ResultFaceExtCom |
| | | // for _, v := range param.Faces { |
| | | // feat := v.Feats |
| | | |
| | | // var res []byte |
| | | // res = cache.Getdbpersonmsg(string(feat), true) |
| | | // f := &protomsg.ResultFaceExtCom{Feats: feat, Comp: res, Pos: v} |
| | | // extComp = append(extComp, f) |
| | | // } |
| | | |
| | | // faceExtComp := protomsg.ParamFaceFeature{ExtComp: extComp} |
| | | // data, err = proto.Marshal(&faceExtComp) |
| | | // if err != nil { |
| | | // logo.Errorln("fextract marshal proto face extract error", err) |
| | | // continue |
| | | // } |
| | | // } |
| | | |
| | | ejectResult(nil, rMsg, out) |
| | | } |
New file |
| | |
| | | package sdk |
| | | |
| | | import ( |
| | | "analysis/logo" |
| | | "plugin" |
| | | ) |
| | | |
| | | // LoadFunc load |
| | | func LoadFunc(plug *plugin.Plugin, soFile, fnName string) (plugin.Symbol, error) { |
| | | fn, err := plug.Lookup(fnName) |
| | | if err != nil { |
| | | logo.Errorln("Loopup Func: ", fnName, " From: ", soFile, " Error: ", err) |
| | | } |
| | | return fn, err |
| | | } |
New file |
| | |
| | | package sdk |
| | | |
| | | import ( |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | | "fmt" |
| | | "plugin" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | // VehicleDetector plate id |
| | | type VehicleDetector struct { |
| | | licSrvPath string |
| | | modelPath string |
| | | |
| | | handle interface{} |
| | | fnInit func() interface{} |
| | | fnFree func(interface{}) |
| | | fnRun func(interface{}, []byte, int, int, int, int, int, int, int) []sdkstruct.CVehicleITSResult |
| | | } |
| | | |
| | | // NewVehicleDetector plate |
| | | func NewVehicleDetector(licSrv, model string, w, h int) *VehicleDetector { |
| | | soFile := "libvehicle.so" |
| | | |
| | | plug, err := plugin.Open(soFile) |
| | | if err != nil { |
| | | logo.Errorln("Open: ", soFile, " error: ", err) |
| | | return nil |
| | | } |
| | | |
| | | fnInit, _ := LoadFunc(plug, soFile, "NewSDK") |
| | | fnFree, _ := LoadFunc(plug, soFile, "Free") |
| | | fnRun, _ := LoadFunc(plug, soFile, "Run") |
| | | |
| | | return &VehicleDetector{ |
| | | licSrvPath: licSrv, |
| | | modelPath: model, |
| | | |
| | | handle: nil, |
| | | fnInit: fnInit.(func() interface{}), |
| | | fnFree: fnFree.(func(interface{})), |
| | | fnRun: fnRun.(func(interface{}, []byte, int, int, int, int, int, int, int) []sdkstruct.CVehicleITSResult), |
| | | } |
| | | } |
| | | |
| | | // Init impl |
| | | func (d *VehicleDetector) Init() bool { |
| | | h := d.fnInit() |
| | | if h == nil { |
| | | logo.Errorln("INIT VEHICLE SDK ERROR") |
| | | return false |
| | | } |
| | | d.handle = h |
| | | |
| | | logo.Infoln("RUN VEHICLE SDK") |
| | | |
| | | return true |
| | | } |
| | | |
| | | // Run impl |
| | | func (d *VehicleDetector) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | d.fnFree(d.handle) |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | | if !validRemoteMessage(rMsg, typ) { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | i := unpackImage(rMsg, typ) |
| | | if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | vehicle := d.fnRun(d.handle, i.Data, imgW, imgH, 3, 0, 0, imgW, imgH) |
| | | plateids := convert2ProtoPlateIDResultVehicle(vehicle) |
| | | |
| | | plateresult := protomsg.PlateIDResult{Result: plateids} |
| | | data, err := proto.Marshal(&plateresult) |
| | | if err != nil { |
| | | fmt.Println("PLATE ID DETECTOR MARSHAL PROTO PLATE IDS ERROR", err) |
| | | data = nil |
| | | } |
| | | |
| | | ejectResult(data, rMsg, out) |
| | | |
| | | var id, name string |
| | | if rMsg.Msg.Tasklab != nil { |
| | | id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname |
| | | } |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT VEHICLE PLATE ID COUNT: ", len(vehicle)) |
| | | |
| | | sc++ |
| | | if sc == 25 { |
| | | logo.Infoln("PLATE ID DETECTOR RUN 25 FRAME USE TIME: ", time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | if time.Since(tm) > time.Second { |
| | | logo.Infof("PLATE ID DETECTOR RUN %d FRAME USE TIME: %v", sc, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | func convert2ProtoPlateIDResultVehicle(obj []sdkstruct.CVehicleITSResult) []*protomsg.PlateIDVehicle { |
| | | ret := []*protomsg.PlateIDVehicle{} |
| | | |
| | | for _, v := range obj { |
| | | |
| | | rcPlateID := &protomsg.Rect{ |
| | | Left: v.RcLocation.Left, |
| | | Right: v.RcLocation.Right, |
| | | Top: v.RcLocation.Top, |
| | | Bottom: v.RcLocation.Bottom, |
| | | } |
| | | rcCar := &protomsg.Rect{ |
| | | Left: v.RcCarLocation.Left, |
| | | Right: v.RcCarLocation.Right, |
| | | Top: v.RcCarLocation.Top, |
| | | Bottom: v.RcCarLocation.Bottom, |
| | | } |
| | | |
| | | lic := string(v.License[:]) |
| | | end := len(lic) |
| | | for i := len(lic) - 1; i >= 0; i-- { |
| | | if lic[i] != '\000' { |
| | | end = i + 1 |
| | | break |
| | | } |
| | | } |
| | | if end > 0 { |
| | | lic = lic[:end] |
| | | } |
| | | |
| | | obj := &protomsg.PlateIDVehicle{ |
| | | NPlateFlag: v.NPlateFlag, |
| | | NColor: v.NColor, |
| | | NType: v.NType, |
| | | License: lic, |
| | | NConfidence: v.NConfidence, |
| | | NCharNum: v.NCharNum, |
| | | NCharConfidence: v.NCharConfidence[:], |
| | | RcLocation: rcPlateID, |
| | | RcCarLocation: rcCar, |
| | | VehicleType: string(v.VehicleType[:]), |
| | | VehicleBrand: string(v.VehicleBrand[:]), |
| | | VehicleSub: string(v.VehicleSub[:]), |
| | | VehicleType1: string(v.VehicleType1[:]), |
| | | FvdConf: v.FVDConf, |
| | | FConfdence: v.FConfdence, |
| | | NVehicleSubModel: v.NVehicleSubModel, |
| | | NVehicleBright: v.NVehicleBright, |
| | | NVehicleColor1: v.NVehicleColor1, |
| | | NVehicleColor2: v.NVehicleColor2, |
| | | } |
| | | |
| | | ret = append(ret, obj) |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | // hr := convert2ProtoHumanTrackResult(res) |
| | | // result := protomsg.HumanTrackResult{Result: hr[0]} |
| | | // data, err := proto.Marshal(&result) |
| | | // if err != nil { |
| | | // fmt.Println("HUMAN TRACKER MARSHAL PROTO PLATE IDS ERROR", err) |
| | | // data = nil |
| | | // } |
| | | |
| | | // func convert2ProtoHumanTrackResult(obj []sdkstruct.FgResult) [][]*protomsg.HumanTrack { |
| | | // ret := [][]*protomsg.HumanTrack{} |
| | | // for _, v := range obj { |
| | | // res := []*protomsg.HumanTrack{} |
| | | // for i := 0; i < int(v.FgNum); i++ { |
| | | // r := v.Fginfo[i] |
| | | |
| | | // rect := protomsg.Rect{ |
| | | // Left: r.Left, |
| | | // Right: r.Right, |
| | | // Top: r.Top, |
| | | // Bottom: r.Bottom, |
| | | // } |
| | | // pr := &protomsg.HumanTrack{ |
| | | // RcHuman: &rect, |
| | | // Confidence: r.Confidence, |
| | | // X: r.X, |
| | | // Y: r.Y, |
| | | // Id: r.ID, |
| | | // Feature: r.Feature[:], |
| | | // } |
| | | // res = append(res, pr) |
| | | // } |
| | | // ret = append(ret, res) |
| | | // } |
| | | // return ret |
| | | // } |
| | |
| | | "analysis/work" |
| | | "container/list" |
| | | "context" |
| | | "fmt" |
| | | "plugin" |
| | | "sync" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/gogpu.git" |
| | | |
| | | "basic.com/valib/gosdk.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | type trackInfo struct { |
| | | lastTrackObjs []gosdk.CObjTrackInfo |
| | | lastTrackID uint64 |
| | | } |
| | | |
| | | // YoloDetect yolo detect |
| | | type YoloDetect struct { |
| | | yolo *gosdk.YoloHandle |
| | | iGPU int |
| | | cfg string |
| | | weights string |
| | | name string |
| | | |
| | | tracker map[string]*trackInfo |
| | | |
| | | cache *list.List |
| | | cv *sync.Cond |
| | | cond bool |
| | | |
| | | handle interface{} |
| | | fnInit func(string, string, string, int) interface{} |
| | | fnFree func(interface{}) |
| | | fnRun func(interface{}, string, []byte, int, int, int, float32, int) ([]sdkstruct.CObjTrackInfo, []sdkstruct.CObjTrackInfo) |
| | | } |
| | | |
| | | // NewYDetectWithTrack with track |
| | | func NewYDetectWithTrack(gi int, cfg, weights, name string) *YoloDetect { |
| | | soFile := "libyolo.so" |
| | | |
| | | plug, err := plugin.Open(soFile) |
| | | if err != nil { |
| | | logo.Errorln("Open: ", soFile, " error: ", err) |
| | | return nil |
| | | } |
| | | |
| | | fnInit, _ := LoadFunc(plug, soFile, "NewSDK") |
| | | fnFree, _ := LoadFunc(plug, soFile, "Free") |
| | | fnRun, _ := LoadFunc(plug, soFile, "Run") |
| | | |
| | | return &YoloDetect{ |
| | | iGPU: gi, |
| | | cfg: cfg, |
| | |
| | | cache: list.New(), |
| | | cv: sync.NewCond(&sync.Mutex{}), |
| | | cond: false, |
| | | |
| | | handle: nil, |
| | | fnInit: fnInit.(func(string, string, string, int) interface{}), |
| | | fnFree: fnFree.(func(interface{})), |
| | | fnRun: fnRun.(func(interface{}, string, []byte, int, int, int, float32, int) ([]sdkstruct.CObjTrackInfo, []sdkstruct.CObjTrackInfo)), |
| | | } |
| | | } |
| | | |
| | |
| | | if gpu == -1 { |
| | | gpu = gogpu.ValidGPU(2048) |
| | | } |
| | | yolo := gosdk.InitYolo(y.cfg, y.weights, y.name, gpu) |
| | | logo.Infoln("yolo use gpu: ", gpu) |
| | | h := y.fnInit(y.cfg, y.weights, y.name, gpu) |
| | | logo.Infoln("YOLO USE GPU: ", gpu) |
| | | |
| | | if yolo == nil { |
| | | if h == nil { |
| | | logo.Errorln("CREATE YOLO DETECTOR ERROR") |
| | | return false |
| | | } |
| | | |
| | | y.yolo = yolo |
| | | y.handle = h |
| | | return true |
| | | } |
| | | |
| | | // Run impl interface |
| | | func (y *YoloDetect) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | y.detectTrack(ctx, in, out, typ) |
| | | go y.work(ctx, out, typ) |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | y.fnFree(y.handle) |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | | if !validRemoteMessage(rMsg, typ) { |
| | | logo.Errorln("yolo validremotemessage invalid") |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | y.push(rMsg) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | func (y *YoloDetect) track(rMsg work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | |
| | | ///////////////////////////////////////////// |
| | | i := unpackImage(rMsg, typ) |
| | | if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { |
| | | logo.Errorln("yolo image error: ", i) |
| | | ejectResult(nil, rMsg, out) |
| | | |
| | | return |
| | | } |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | whole, recent := y.fnRun(y.handle, rMsg.Msg.Cid, i.Data, imgW, imgH, 3, 0.4, 0) |
| | | if len(recent) > 0 { |
| | | } |
| | | |
| | | infos := convert2ProtoYoloTrack(whole, 1.0, 1.0) |
| | | p := protomsg.ParamYoloObj{Infos: infos} |
| | | |
| | | data, err := proto.Marshal(&p) |
| | | if err != nil { |
| | | fmt.Println("ydetect track marshal proto yolo obj error", err) |
| | | data = nil |
| | | } |
| | | |
| | | ejectResult(data, rMsg, out) |
| | | |
| | | var id, name string |
| | | if rMsg.Msg.Tasklab != nil { |
| | | id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname |
| | | } |
| | | |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT YOLO COUNT: ", len(whole)) |
| | | } |
| | | |
| | | func convert2ProtoYoloTrack(obj []sdkstruct.CObjTrackInfo, fx, fy float64) []*protomsg.ObjInfo { |
| | | ret := []*protomsg.ObjInfo{} |
| | | |
| | | for _, v := range obj { |
| | | if fx < 1.0 || fy < 1.0 { |
| | | v.ObjInfo.RcObj.Left = (int32)((float64)(v.ObjInfo.RcObj.Left) / fx) |
| | | v.ObjInfo.RcObj.Right = (int32)((float64)(v.ObjInfo.RcObj.Right) / fx) |
| | | v.ObjInfo.RcObj.Top = (int32)((float64)(v.ObjInfo.RcObj.Top) / fy) |
| | | v.ObjInfo.RcObj.Bottom = (int32)((float64)(v.ObjInfo.RcObj.Bottom) / fy) |
| | | } |
| | | |
| | | rect := protomsg.Rect{ |
| | | Left: v.ObjInfo.RcObj.Left, |
| | | Right: v.ObjInfo.RcObj.Right, |
| | | Top: v.ObjInfo.RcObj.Top, |
| | | Bottom: v.ObjInfo.RcObj.Bottom, |
| | | } |
| | | obj := protomsg.ObjInfo{ |
| | | RcObj: &rect, |
| | | Typ: v.ObjInfo.Typ, |
| | | Prob: v.ObjInfo.Prob, |
| | | ObjID: v.ID, |
| | | } |
| | | |
| | | ret = append(ret, &obj) |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | func (y *YoloDetect) work(ctx context.Context, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return |
| | | default: |
| | | |
| | | y.cv.L.Lock() |
| | | |
| | | for !y.cond { |
| | | y.cv.Wait() |
| | | } |
| | | |
| | | rMsg := y.cache.Front().Value.(work.MsgRS) |
| | | |
| | | y.track(rMsg, out, typ) |
| | | y.cache.Remove(y.cache.Front()) |
| | | y.cond = false |
| | | y.cv.L.Unlock() |
| | | |
| | | sc++ |
| | | if sc == 25 { |
| | | logo.Infoln("YOLO RUN 25 FRAME USE TIME: ", time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | if time.Since(tm) > time.Second { |
| | | logo.Infof("YOLO RUN %d FRAME USE TIME: %v", sc, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | func (y *YoloDetect) push(data work.MsgRS) { |
| | | y.cv.L.Lock() |
| | | y.cache.PushBack(data) |
| | | if y.cache.Len() > 12 { |
| | | for i := 0; i < y.cache.Len(); { |
| | | y.cache.Remove(y.cache.Front()) |
| | | i = i + 2 |
| | | } |
| | | } |
| | | // logo.Infof("push to cache count : %d\n", t.cache.Len()) |
| | | y.cond = true |
| | | y.cv.Signal() |
| | | y.cv.L.Unlock() |
| | | } |