| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "ruleprocess/insertdata" |
| | | "ruleprocess/ruleserver" |
| | | "sync" |
| | | "ruleprocess/util" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/deliver.git" |
| | | "github.com/golang/protobuf/proto" |
| | | "sync" |
| | | ) |
| | | |
| | | func main() { |
| | |
| | | fmt.Println("recv error : ", err) |
| | | continue |
| | | } else { |
| | | arg := ruleserver.ArgsFromSdk{} |
| | | m := paramFormat(msg,&arg) |
| | | arg.MainJudge() |
| | | arg := ruleserver.SdkDatas{} |
| | | m := paramFormat(msg, &arg) |
| | | fmt.Println("解析出来的数据:", arg) |
| | | ruleserver.Judge(&arg) |
| | | // 把arg里的打的标签拿出来给m再封装一层 |
| | | resultMag := ruleserver.ResultMsg{SdkMessage: m, RuleResult: arg.RuleResult} |
| | | fmt.Println("打完标签后的结果:",resultMag) |
| | | //fmt.Println("打完标签后的结果:",resultMag) |
| | | |
| | | // 将打完标签的数据插入到ES |
| | | insertdata.InsertToEs(resultMag) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 将外部传进来的sdk数据包解成 ArgsFromSdk |
| | | func paramFormat(msg []byte,arg *ruleserver.ArgsFromSdk) protomsg.SdkMessage { |
| | | // 将外部传进来的rect(top,bottom,left,right)转化为自己内部的rect(left top width height) |
| | | func rectFormat(rcobj *protomsg.Rect) ruleserver.Rect { |
| | | rect := ruleserver.Rect{} |
| | | rect.X = float64(rcobj.Left) |
| | | rect.Y = float64(rcobj.Top) |
| | | rect.Width = float64(rcobj.Right - rcobj.Left) |
| | | rect.Height = float64(rcobj.Bottom - rcobj.Top) |
| | | return rect |
| | | } |
| | | |
| | | // 将外部传进来的sdk数据包解成 SdkDatas |
| | | func paramFormat(msg []byte, args *ruleserver.SdkDatas) protomsg.SdkMessage { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | fmt.Println("解包过程的错误", err.(string)) |
| | | } |
| | | |
| | | }() |
| | | // 反序列化数据得到sdk入参 |
| | | m := protomsg.SdkMessage{} |
| | | err := proto.Unmarshal(msg, &m) |
| | | if err != nil { |
| | | fmt.Println("解析msg时出现错误", err) |
| | | return m |
| | | panic("解析msg时出现错误") |
| | | } |
| | | arg.CameraId = m.Cid |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | |
| | | args.CameraId = m.Cid |
| | | // 把图片的二进制解压缩进行画框在压缩回去 |
| | | bdata, err := util.UnCompress(m.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(m.Data, &i) |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | // 暂时写死,sdk还没有这俩算法 |
| | | arg.KeepRight = false |
| | | arg.IsStatic = false |
| | | fmt.Println("从mongos中拿到的数据包长度为:", len(msg)) |
| | | for _, sdkinfo := range m.Tasklab.Sdkinfos { |
| | | if sdkinfo.Sdktype == "yolo" { |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | err = proto.Unmarshal(bdata, &i) |
| | | |
| | | for _, sdkinfo := range m.Tasklab.Sdkinfos { // yolo算法 |
| | | if sdkinfo.Sdktype == "Yolo" { |
| | | arg := ruleserver.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.SdkId = sdkinfo.Sdkid |
| | | arg.SdkName = sdkinfo.SdkName |
| | | arg.IsYolo = true |
| | | bdata, err := util.UnCompress(m.Data) |
| | | if err != nil { |
| | | fmt.Println("解析sdk数据时出现错误", err) |
| | | continue |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | for _, info := range yoloParam.Infos { |
| | | photoMap := ruleserver.PhotoMap{Rects:rectFormat(info.RcObj, i.Width, i.Height), Score: float64(info.Prob)} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | // 暂时写死,sdk还没有这俩算法 |
| | | arg.KeepRight = false |
| | | arg.IsStatic = false |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | // 大于1才有数据 |
| | | fmt.Println("----------------------------------------------------",m.Cid) |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | | fmt.Println("解析YOLO sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _, info := range yoloParam.Infos { |
| | | if info.Typ == 0 { |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob)*100,IsYolo:true} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata,&arg) |
| | | } else { |
| | | continue |
| | | } |
| | | |
| | | } |
| | | if sdkinfo.Sdktype == "FaceDetect" { // 人脸检测 |
| | | arg := ruleserver.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.SdkId = sdkinfo.Sdkid |
| | | arg.SdkName = sdkinfo.SdkName |
| | | arg.IsYolo = false |
| | | bdata, err := util.UnCompress(m.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | // 暂时写死,sdk还没有这俩算法 |
| | | arg.KeepRight = false |
| | | arg.IsStatic = false |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | fmt.Println("----------------------------------------------------",m.Caddr) |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | fmt.Println("解析FACE sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _, info := range faceParam.Faces { |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.Quality)*100, IsYolo:false,ThftRes:*(info.Result)} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata,&arg) |
| | | } else { |
| | | continue |
| | | } |
| | | } |
| | | if sdkinfo.Sdktype == "FaceExtract" { // 人脸提取 |
| | | arg := ruleserver.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.SdkId = sdkinfo.Sdkid |
| | | arg.SdkName = sdkinfo.SdkName |
| | | arg.IsYolo = false |
| | | bdata, err := util.UnCompress(m.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | // 暂时写死,sdk还没有这俩算法 |
| | | arg.KeepRight = false |
| | | arg.IsStatic = false |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | fmt.Println("----------------------------------------------------",m.Caddr) |
| | | faceParam := protomsg.ParamFaceFeature{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | fmt.Println("解析FACE sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _, extComp := range faceParam.ExtComp { |
| | | baseinfos := protomsg.Binfos{} |
| | | err1 := proto.Unmarshal(extComp.Comp, &baseinfos) |
| | | if err1 != nil { |
| | | fmt.Println("解析FACE sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(extComp.Pos.Pos.RcFace), Score: float64(extComp.Pos.Pos.Quality)*100, IsYolo:false,ThftRes:*(extComp.Pos.Result),Liker:baseinfos.Infos} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata,&arg) |
| | | } else { |
| | | continue |
| | | } |
| | | } |
| | | |
| | | } |
| | | return m |
| | | } |
| | | |
| | | // 将外部传进来的rect(top,bottom,left,right)转化为自己内部的rect(left top width height) |
| | | func rectFormat(rcobj *protomsg.Rect, width int32, height int32) ruleserver.Rect { |
| | | rect := ruleserver.Rect{} |
| | | rect.X = float64(rcobj.Left) |
| | | rect.Y = float64(rcobj.Top) |
| | | rect.Width = float64(width - rcobj.Left - rcobj.Right) |
| | | rect.Height = float64(height - rcobj.Top - rcobj.Bottom) |
| | | return rect |
| | | } |
| | | } |