| | |
| | | fmt.Println("recv error : ", err) |
| | | continue |
| | | } else { |
| | | arg := ruleserver.ArgsFromSdk{} |
| | | arg := ruleserver.SdkDatas{} |
| | | m := paramFormat(msg, &arg) |
| | | fmt.Println("解析出来的数据:", arg) |
| | | ruleserver.MainJudge(&arg) |
| | | ruleserver.Judge(arg) |
| | | // 把arg里的打的标签拿出来给m再封装一层 |
| | | resultMag := ruleserver.ResultMsg{SdkMessage: m, RuleResult: arg.RuleResult} |
| | | //fmt.Println("打完标签后的结果:",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)) |
| | |
| | | if err != nil { |
| | | panic("解析msg时出现错误") |
| | | } |
| | | arg.CameraId = m.Cid |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | 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 |
| | | args.CameraId = m.Cid |
| | | 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 { |
| | | 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 { |
| | | // 大于1才有数据 |
| | | fmt.Println("----------------------------------------------------",m.Caddr) |
| | | fmt.Println("----------------------------------------------------",m.Cid) |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | | fmt.Println("解析YOLO sdk数据时出现错误", err) |
| | | //continue |
| | | continue |
| | | } |
| | | for _, info := range yoloParam.Infos { |
| | | if info.Typ == 0 { |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob)*100} |
| | | 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" { // 人脸检测 |
| | | // fmt.Println("数据长度为:", len(sdkinfo.Sdkdata)) |
| | | // 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: ruleserver.Rect{-1, -1, -1, -1}, Score: float64(info.Pos.Quality)} |
| | | // arg.Photo = append(arg.Photo, photoMap) |
| | | // } |
| | | // } 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" { // 人脸提取 |
| | | |
| | | //} |
| | | |
| | | } |
| | | return m |
| | | } |
| | | |
| | | // 将外部传进来的rect(top,bottom,left,right)转化为自己内部的rect(left top width height) |
| | | func rectFormat(rcobj *protomsg.Rect) ruleserver.Rect { |
| | | rect := ruleserver.Rect{} |
| | | fmt.Println("看一下传入的矩形数据:", rcobj.Left, rcobj.Top, rcobj.Right, rcobj.Bottom) |
| | | 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 |
| | | } |
| | | } |