| | |
| | | |
| | | import ( |
| | | "context" |
| | | "os" |
| | | "sync" |
| | | "time" |
| | | "unsafe" |
| | |
| | | "basic.com/valib/gogpu.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | const maxTryBeforeReboot = 10 |
| | | |
| | | type face struct { |
| | | handle *SDKFace |
| | |
| | | ipc2Rule string |
| | | ruleMsgMaxCacheSize int |
| | | reserved map[string]interface{} |
| | | |
| | | running bool |
| | | rebootUntil int |
| | | mtxRunning sync.Mutex |
| | | } |
| | | |
| | | func (f *face) maybeReboot(ctx context.Context) { |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return |
| | | default: |
| | | f.mtxRunning.Lock() |
| | | running := f.running |
| | | f.mtxRunning.Unlock() |
| | | |
| | | if running { |
| | | f.rebootUntil = 0 |
| | | |
| | | f.mtxRunning.Lock() |
| | | f.running = false |
| | | f.mtxRunning.Unlock() |
| | | |
| | | } else { |
| | | f.rebootUntil++ |
| | | f.fnLogger("Face No Running: ", f.rebootUntil) |
| | | if f.rebootUntil > maxTryBeforeReboot { |
| | | f.fnLogger("Face Too Long Running, Reboot") |
| | | os.Exit(0) |
| | | } |
| | | } |
| | | time.Sleep(time.Second) |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Create create sdk |
| | |
| | | ipc2Rule: ipc2Rule, |
| | | ruleMsgMaxCacheSize: ruleMaxSize, |
| | | reserved: reserved, |
| | | |
| | | running: true, |
| | | rebootUntil: maxTryBeforeReboot, |
| | | } |
| | | } |
| | | |
| | |
| | | go torule.Run(ctx) |
| | | |
| | | go s.run(ctx, chRcv, chSnd) |
| | | |
| | | go s.maybeReboot(ctx) |
| | | } |
| | | |
| | | ////////////////////////////////////////////////////////////////// |
| | |
| | | // conv to bgr24 and resize |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | f.fnLogger("Face~~~Track") |
| | | // f.fnLogger("Face~~~Track", dtchn) |
| | | detect := f.handle.Track(i.Data, imgW, imgH, 3, dtchn) |
| | | f.fnLogger("Face~~~Track Over") |
| | | // f.fnLogger("Face~~~Track Over", dtchn) |
| | | |
| | | var faces []*protomsg.ResultFaceDetect |
| | | |
| | |
| | | for _, d := range detect { |
| | | |
| | | //运行sd |
| | | f.fnLogger("Face~~~FaceInfo2FacePos") |
| | | // f.fnLogger("Face~~~FaceInfo2FacePos", dtchn) |
| | | dec := FaceInfo2FacePos(d) |
| | | f.fnLogger("Face~~~FaceInfo2FacePos over") |
| | | // f.fnLogger("Face~~~FaceInfo2FacePos over", dtchn) |
| | | |
| | | f.fnLogger("Face~~~Propertize") |
| | | // f.fnLogger("Face~~~Propertize", dtchn) |
| | | prop := f.handle.Propertize(dec, i.Data, imgW, imgH, 3, dtchn) |
| | | f.fnLogger("Face~~~Propertize Over") |
| | | // f.fnLogger("Face~~~Propertize Over", dtchn) |
| | | |
| | | f.fnLogger("Face~~~Extract") |
| | | f.fnLogger("Face~~~Extract", dtchn) |
| | | feat := f.handle.Extract(dec, i.Data, imgW, imgH, 3, dtchn) |
| | | f.fnLogger("Face~~~Extract Over") |
| | | f.fnLogger("Face~~~Extract Over", dtchn) |
| | | |
| | | f.fnLogger("Face~~~protomsg.ThftResult") |
| | | // f.fnLogger("Face~~~protomsg.ThftResult", dtchn) |
| | | resP := (*protomsg.ThftResult)(unsafe.Pointer(&prop)) |
| | | f.fnLogger("Face~~~protomsg.ThftResult Over") |
| | | // f.fnLogger("Face~~~protomsg.ThftResult Over", dtchn) |
| | | |
| | | f.fnLogger("Face~~~tconvert2ProtoFacePos") |
| | | // f.fnLogger("Face~~~tconvert2ProtoFacePos", dtchn) |
| | | result := tconvert2ProtoFacePos(d) |
| | | f.fnLogger("Face~~~tconvert2ProtoFacePos Over") |
| | | // f.fnLogger("Face~~~tconvert2ProtoFacePos Over", dtchn) |
| | | |
| | | //组成结果并序列化 |
| | | res := &protomsg.ResultFaceDetect{Pos: result, Result: resP, Feats: feat} |
| | |
| | | } |
| | | } |
| | | |
| | | f.fnLogger("Face~~~EjectResult") |
| | | // f.fnLogger("Face~~~EjectResult", dtchn) |
| | | common.EjectResult(data, rMsg, out) |
| | | f.fnLogger("Face~~~EjectResult Over") |
| | | // f.fnLogger("Face~~~EjectResult Over", dtchn) |
| | | f.mtxRunning.Lock() |
| | | f.running = true |
| | | f.mtxRunning.Unlock() |
| | | |
| | | var id, name string |
| | | if rMsg.Msg.Tasklab != nil { |