| | |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | logger "github.com/jeanphorn/log4go" |
| | | "basic.com/valib/logger.git" |
| | | "github.com/golang/protobuf/proto" |
| | | uuid "github.com/satori/go.uuid" |
| | | "ruleprocess/ruleserver" |
| | |
| | | func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) { |
| | | |
| | | a.TargetNum = 0 |
| | | threshold := 70.0 // 相似度 |
| | | threshold := 0.0 // 相似度 |
| | | intersectionper := 20.0 // 占比 |
| | | size := 0.0 // 尺寸 |
| | | |
| | |
| | | // 这步要备齐表达式里所需要的所有参数 |
| | | a.TargetNum++ |
| | | uuid := uuid.NewV4().String() |
| | | arg1 := structure.Arg{obj.Id,uuid,obj.Score, ruleserver.PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.Type, obj.Rects, obj.Car,obj.Feature, obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}} |
| | | arg1 := structure.Arg{structure.SourceArg{obj.Id,uuid,obj.Score, ruleserver.PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.Type, obj.Rects, obj.Car,obj.Feature,obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}},structure.SourceArg{}} |
| | | //logger.Println("放进去的arg:-------", arg1) |
| | | a.Args = append(a.Args, &arg1) |
| | | a.FilterData = append(a.FilterData, &arg1) |
| | |
| | | return rect |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // 将外部传进来的sdk数据包解成 SdkDatas |
| | | func ParamFormat(msg []byte, args *structure.SdkDatas) protomsg.SdkMessage { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Info("解包过程的异常捕获", err.(string)) |
| | | } |
| | | |
| | | }() |
| | | // 反序列化数据得到sdk入参 |
| | | m := protomsg.SdkMessage{} |
| | |
| | | logger.Info("接到数据,摄像机为:", m.Cid, "图片的id为:", i.Id) |
| | | //logger.Info("----------------看看有几个算法:",len(m.Tasklab.Sdkinfos)) |
| | | for _, sdkinfo := range m.Tasklab.Sdkinfos { // yolo算法 |
| | | if sdkinfo.Sdktype == "Yolo" { |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = true |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | logger.Info("-----追踪之后sdkinfo.Sdkdata的长度为:----", len(sdkinfo.Sdkdata)) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | // 大于1才有数据 |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | | logger.Info("解析YOLO sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | var yoloNum int = 0 |
| | | for _, info := range yoloParam.Infos { |
| | | if info.Typ == 0 { |
| | | //logger.Debug("-------------yolo的坐标有几个",info.RcObj) |
| | | photoMap := structure.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob) * 100, Type: "yolo",Id:strconv.Itoa(int(info.ObjID))} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | yoloNum++ |
| | | } |
| | | } |
| | | logger.Info("--------------追踪之后yolo的个数:", yoloNum) |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | continue |
| | | } |
| | | |
| | | } |
| | | if sdkinfo.Sdktype == "FaceDetect" { // 人脸检测 |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = false |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | logger.Info("解析FACE sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | logger.Info("--------------追踪之后人脸的个数:", len(faceParam.Faces)) |
| | | for _, info := range faceParam.Faces { |
| | | //logger.Info("_______________________________________________第一次看相似值:",info.Pos.FAngle.Confidence*100) |
| | | photoMap := structure.PhotoMap{Id: strconv.Itoa(int(info.Pos.FaceID)) , Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.FAngle.Confidence * 100), Type: "face", ThftRes: *(info.Result), Feature: info.Feats} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | continue |
| | | } |
| | | } |
| | | if sdkinfo.Sdktype == "Plate" { // 车牌识别 |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | logger.Info("车牌的ipcid:",sdkinfo.Ipcid) |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = false |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | plateIDResult := protomsg.PlateIDResult {} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &plateIDResult ) |
| | | if err != nil { |
| | | logger.Info("解析车牌数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _, info := range plateIDResult.Result { |
| | | logger.Info("接收车牌数据:",info.FvdConf,info.NVehicleColor1,info.NPlateFlag,info.RcCarLocation) |
| | | if info.NConfidence > 70 { |
| | | logger.Info("车牌也符合的数据",info.FvdConf,info.NVehicleColor1,info.NPlateFlag,info.RcCarLocation,info.NConfidence,) |
| | | photoMap := structure.PhotoMap{Id: info.License,Score: float64(info.FvdConf)*100,Rects: rectFormat(info.RcCarLocation), Type: "plate", Car:info} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | continue |
| | | } |
| | | switch sdkinfo.Sdktype { |
| | | case "Yolo": |
| | | extractYolo(args,m,sdkinfo,i) |
| | | case "FaceDetect": |
| | | extractFace(args,m,sdkinfo,i) |
| | | case "Plate": |
| | | extractCar(args,m,sdkinfo,i) |
| | | case "HumanTrack": |
| | | extractTrack(args,m,sdkinfo,i) |
| | | } |
| | | } |
| | | return m |
| | | } |
| | | |
| | | // 提取face |
| | | func extractFace(args *structure.SdkDatas,m protomsg.SdkMessage,sdkinfo *protomsg.SdkmsgWithTask,i protomsg.Image) { |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = false |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err := proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | logger.Info("解析FACE sdk数据时出现错误", err) |
| | | return |
| | | } |
| | | logger.Info("--------------追踪之后人脸的个数:", len(faceParam.Faces)) |
| | | for _, info := range faceParam.Faces { |
| | | //logger.Info("_______________________________________________第一次看相似值:",info.Pos.FAngle.Confidence*100) |
| | | photoMap := structure.PhotoMap{structure.SourcePhoto{Id: strconv.Itoa(int(info.Pos.FaceID)) , Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.FAngle.Confidence * 100), Type: "face", ThftRes: *(info.Result), Feature: info.Feats},structure.SourcePhoto{}} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } |
| | | } |
| | | // 提取yolo |
| | | func extractYolo(args *structure.SdkDatas,m protomsg.SdkMessage,sdkinfo *protomsg.SdkmsgWithTask,i protomsg.Image) { |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = true |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | logger.Info("-----追踪之后sdkinfo.Sdkdata的长度为:----", len(sdkinfo.Sdkdata)) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | // 大于1才有数据 |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err := proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | | logger.Info("解析YOLO sdk数据时出现错误", err) |
| | | return |
| | | } |
| | | var yoloNum int = 0 |
| | | for _, info := range yoloParam.Infos { |
| | | if info.Typ == 0 { |
| | | //logger.Debug("-------------yolo的坐标有几个",info.RcObj) |
| | | photoMap := structure.PhotoMap{structure.SourcePhoto{Rects: rectFormat(info.RcObj), Score: float64(info.Prob) * 100, Type: "yolo",Id:strconv.Itoa(int(info.ObjID))},structure.SourcePhoto{}} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | yoloNum++ |
| | | } |
| | | } |
| | | logger.Info("--------------追踪之后yolo的个数:", yoloNum) |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | return |
| | | } |
| | | } |
| | | |
| | | // 提取car |
| | | func extractCar(args *structure.SdkDatas,m protomsg.SdkMessage,sdkinfo *protomsg.SdkmsgWithTask,i protomsg.Image) { |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = false |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | plateIDResult := protomsg.PlateIDResult {} |
| | | err := proto.Unmarshal(sdkinfo.Sdkdata, &plateIDResult ) |
| | | if err != nil { |
| | | logger.Info("解析车牌数据时出现错误", err) |
| | | return |
| | | } |
| | | for _, info := range plateIDResult.Result { |
| | | logger.Info("接收车牌数据:",info.FvdConf,info.NVehicleColor1,info.NPlateFlag,info.RcCarLocation) |
| | | if info.NConfidence > 70 { |
| | | logger.Info("车牌也符合的数据",info.FvdConf,info.NVehicleColor1,info.NPlateFlag,info.RcCarLocation,info.NConfidence,) |
| | | photoMap := structure.PhotoMap{structure.SourcePhoto{Id: info.License,Score: float64(info.FvdConf)*100,Rects: rectFormat(info.RcCarLocation), Type: "plate", Car:info},structure.SourcePhoto{}} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | return |
| | | } |
| | | } |
| | | |
| | | // 提取跟踪 |
| | | func extractTrack(args *structure.SdkDatas,m protomsg.SdkMessage,sdkinfo *protomsg.SdkmsgWithTask,i protomsg.Image) { |
| | | arg := structure.SdkData{} |
| | | arg.TaskId = m.Tasklab.Taskid |
| | | arg.IpcId = sdkinfo.Ipcid |
| | | arg.IsYolo = false |
| | | arg.ImageWidth = int(i.Width) |
| | | arg.ImageHeight = int(i.Height) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | |
| | | Track := protomsg.HumanTrackResult {} |
| | | err := proto.Unmarshal(sdkinfo.Sdkdata, &Track) |
| | | if err != nil { |
| | | logger.Info("解析跟踪目标数据时出现错误", err) |
| | | return |
| | | } |
| | | for _, info := range Track.Result { |
| | | logger.Info("接收跟踪数据:",info.Id,info.Confidence,info.Feature) |
| | | photoMap := structure.PhotoMap{structure.SourcePhoto{Id: strconv.Itoa(int(info.Id)),Score: float64(info.Confidence)*100,Rects: rectFormat(info.RcHuman), Type: "track"},structure.SourcePhoto{}} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | | } else { |
| | | return |
| | | } |
| | | } |
| | | |
| | | // 把人脸放进对应的人体 |
| | | func FacePush2Body (photomap *structure.PhotoMap,sdkInfos []*protomsg.SdkmsgWithTask) { |
| | | for _,sdkinfo := range sdkInfos { |
| | | if sdkinfo.Sdktype == "FaceDetect" { |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err := proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | logger.Info("解析FACE sdk数据时出现错误", err) |
| | | return |
| | | } |
| | | logger.Info("--------------追踪之后人脸的个数:", len(faceParam.Faces)) |
| | | for _, info := range faceParam.Faces { |
| | | percent := ruleserver.PgsInterPercent(Rect2Point(photomap.Rects),rectFormat(info.Pos.RcFace), 1, 1) |
| | | if percent > 99 { |
| | | photomap.AttachObj = structure.SourcePhoto{Id:strconv.Itoa(int(info.Pos.FaceID)),Rects: rectFormat(info.Pos.RcFace),Score: float64(info.Pos.FAngle.Confidence * 100), Type: "face", ThftRes: *(info.Result), Feature: info.Feats} |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | func Rect2Point(rect structure.Rect) []structure.Point{ |
| | | // 按逆时针转化 |
| | | points := []structure.Point{} |
| | | leftTop := structure.Point{rect.X,rect.Y} |
| | | points = append(points,leftTop) |
| | | leftBottom := structure.Point{rect.X,rect.Y+rect.Height} |
| | | points = append(points,leftBottom) |
| | | rightBottom := structure.Point{rect.X+rect.Width,rect.Y+rect.Height} |
| | | points = append(points,rightBottom) |
| | | rightTop := structure.Point{rect.X+rect.Width,rect.Y} |
| | | points = append(points,rightTop) |
| | | return points |
| | | } |