底库比对挂在规则库中,人脸三剑客只剩下一个人脸检测,给人脸赋特征值
| | |
| | | require ( |
| | | basic.com/dbapi.git v0.0.0-20190701055817-73bca225181f |
| | | basic.com/pubsub/cache.git v0.0.0-20190625115705-58cdde93bbe0 |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190705101637-65381a182a3c |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190706093248-8cd3a0511c78 |
| | | basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051 |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28 |
| | | github.com/Microsoft/go-winio v0.4.12 // indirect |
| | |
| | | basic.com/dbapi.git v0.0.0-20190701055817-73bca225181f/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= |
| | | basic.com/pubsub/cache.git v0.0.0-20190625115705-58cdde93bbe0 h1:gbAslJB/3DATBlr4b95cs8sMFNSqRxL7KUwXYnyvp14= |
| | | basic.com/pubsub/cache.git v0.0.0-20190625115705-58cdde93bbe0/go.mod h1:gHLJZz2ee1cGL0X0ae69fs56bAxkDgEQwDhhXZJNUcY= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190705101637-65381a182a3c h1:gVWzsRxEiQ7oqx0xHDHKbk1LF1hj32Xjp9n65K5Q3mI= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190705101637-65381a182a3c/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190706093248-8cd3a0511c78 h1:rjF01FTFUvFc5zj3PQ1MN17z+FVYZZQInhtzn+vhMSk= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190706093248-8cd3a0511c78/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= |
| | | basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051 h1:9flC2o3kasaM2Y6I+mY+mxmve/pyAY/UzGQZLT3lFHM= |
| | | basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051/go.mod h1:bkYiTUGzckyNOjAgn9rB/DOjFzwoSHJlruuWQ6hu6IY= |
| | | basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28 h1:3hejanzPEBvZSSvjIqayB83/6/6SLLrX9oNZAdiYELg= |
| | |
| | | race, |
| | | face.ThftRes.Smile, |
| | | face.ThftRes.Beauty, |
| | | "", |
| | | string(face.Feature), |
| | | []string{strings.Split(resp["fileUrl"].(string), "/")[1]}, |
| | | "暂无集群", |
| | | localConfig.ServerId, |
| | |
| | | } |
| | | logger.Info("------当前算法name",sdkinfo.SdkName,"--------------看看人脸检测中有几个目标:",len(faceParam.Faces)) |
| | | for _, info := range faceParam.Faces { |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.Quality)*100, IsYolo:false,ThftRes:*(info.Result)} |
| | | photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.Quality)*100, IsYolo:false,ThftRes:*(info.Result),Feature:info.Feats} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata,&arg) |
| | |
| | | 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 { |
| | | faceParam := protomsg.ParamFaceFeature{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | logger.Info("解析FACE sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _,faceExtCom := range faceParam.ExtComp { |
| | | binfos := protomsg.Binfos{} |
| | | err := proto.Unmarshal(faceExtCom.Comp, &binfos) |
| | | if err != nil { |
| | | logger.Info("解析人脸比对数据时出现错误", err) |
| | | continue |
| | | } |
| | | logger.Info("_________________________________________________________________解析出的人脸的相似的底库数据",binfos.Infos[0].CompareScore) |
| | | } |
| | | logger.Info("------当前算法name",sdkinfo.SdkName,"--------------看看人脸提取中有几个目标:",len(faceParam.ExtComp)) |
| | | for _, extComp := range faceParam.ExtComp { |
| | | baseinfos := protomsg.Binfos{} |
| | | err1 := proto.Unmarshal(extComp.Comp, &baseinfos) |
| | | if err1 != nil { |
| | | logger.Info("解析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 |
| | | } |
| | | } |
| | | //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 { |
| | | // faceParam := protomsg.ParamFaceFeature{} |
| | | // err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | // if err != nil { |
| | | // logger.Info("解析FACE sdk数据时出现错误", err) |
| | | // continue |
| | | // } |
| | | // for _,faceExtCom := range faceParam.ExtComp { |
| | | // binfos := protomsg.Binfos{} |
| | | // err := proto.Unmarshal(faceExtCom.Comp, &binfos) |
| | | // if err != nil { |
| | | // logger.Info("解析人脸比对数据时出现错误", err) |
| | | // continue |
| | | // } |
| | | // logger.Info("_________________________________________________________________解析出的人脸的相似的底库数据",binfos.Infos[0].CompareScore) |
| | | // } |
| | | // logger.Info("------当前算法name",sdkinfo.SdkName,"--------------看看人脸提取中有几个目标:",len(faceParam.ExtComp)) |
| | | // for _, extComp := range faceParam.ExtComp { |
| | | // baseinfos := protomsg.Binfos{} |
| | | // err1 := proto.Unmarshal(extComp.Comp, &baseinfos) |
| | | // if err1 != nil { |
| | | // logger.Info("解析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 |
| | |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "github.com/gogo/protobuf/proto" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/logger" |
| | | "sort" |
| | |
| | | "strings" |
| | | "time" |
| | | |
| | | bigCache "basic.com/pubsub/cache.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "github.com/knetic/govaluate" |
| | | ) |
| | |
| | | IsYolo bool // 是否是yolo数据 |
| | | Location Rect // 记下每个目标的位置参数,最后给结果装配人脸数据的时候用的到 |
| | | SdkName string |
| | | Feature []byte |
| | | ThftRes protomsg.ThftResult |
| | | Liker []*protomsg.Baseinfo |
| | | } |
| | |
| | | IsYolo bool // 是否是yolo数据 |
| | | SdkName string |
| | | ThftRes protomsg.ThftResult |
| | | Liker []*protomsg.Baseinfo // 如果是人脸的话尤其是比对,应存下他跟底库的人员的相似情况 yolo的话给nil就行 |
| | | Feature []byte |
| | | } |
| | | |
| | | // 每个算法对于当前帧画面自己提取的数据 |
| | |
| | | } |
| | | } |
| | | } |
| | | func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) { |
| | | compareFlag := false |
| | | // 看看是否有只配人脸比对算法但没有配对比库的规则,如果有,则比对对象为全部底库 |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972"{ |
| | | if groupRule.Rules[j].SdkArgAlias == "对比底库" { |
| | | compareFlag = true |
| | | } |
| | | } |
| | | } |
| | | if compareFlag { |
| | | logger.Info("配置了对比底库参数") |
| | | }else { |
| | | logger.Info("没有配置对比底库参数") |
| | | } |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" && groupRule.Rules[j].SdkArgAlias == "对比底库"{ |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" { // 搜索到人脸检测的sdkdata 现在关于人脸的只有他一个sdk,全找他 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | // 拿区域中每个人脸特征值去对比,填充其liker |
| | | if groupRule.Rules[j].PolygonId == areaMap.areaId { |
| | | for _,arg := range areaMap.args { |
| | | bytes := bigCache.Getdbpersonmsg(string(arg.Feature),true) |
| | | binfos := protomsg.Binfos{} |
| | | proto.Unmarshal(bytes,&binfos) |
| | | arg.Liker = binfos.Infos |
| | | logger.Info("-------------------成功给liker赋值:",arg.Liker) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string) bool { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | |
| | | } |
| | | }() |
| | | logger.Info("+++++++++++规则开始运行+++++++++++++++++当前规则--:", *groupRule) |
| | | Compare(args,groupRule) |
| | | resultSplice := []*LittleRuleResult{} |
| | | // 先过完条件规则 |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | |
| | | // 配了人脸的算法才把人脸的数据甩出来打标签 |
| | | flag11 := false |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a971" { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | flag11 = true |
| | | } |
| | | } |
| | |
| | | |
| | | func putFaceToResult(rule *protomsg.Rule, am *AreaMap) []Arg { |
| | | faces := []Arg{} |
| | | if rule.SdkId == am.sdkId && rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a971" { |
| | | if rule.SdkId == am.sdkId && rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | if len(am.filterData) > 0 { |
| | | for _, data := range am.filterData { |
| | | faces = append(faces, data) |
| | |
| | | |
| | | func putYolosToResult(rule *protomsg.Rule, am *AreaMap) []Rect { |
| | | locations := []Rect{} |
| | | if rule.SdkId == am.sdkId && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a97e" && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a971" { |
| | | if rule.SdkId == am.sdkId && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a97e" && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | if len(am.filterData) > 0 { |
| | | for _, data := range am.filterData { |
| | | locations = append(locations, data.Location) |
| | |
| | | if threshold <= obj.Score && size <= float64(obj.Rects.Width*obj.Rects.Height) && intersectionper <= PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) { |
| | | // 这步要备齐表达式里所需要的所有参数 |
| | | a.targetNum++ |
| | | arg1 := Arg{obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.SdkName, obj.ThftRes, obj.Liker} |
| | | arg1 := Arg{obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.SdkName, obj.Feature,obj.ThftRes,[]*protomsg.Baseinfo{}} |
| | | //logger.Println("放进去的arg:-------", arg1) |
| | | a.args = append(a.args, arg1) |
| | | a.filterData = append(a.filterData, arg1) |
| | |
| | | func filterRule(rule *protomsg.Rule, am *AreaMap) LittleRuleResult { |
| | | if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | // 处理的是人脸算法 如果这条规则配置的是人脸算法,过滤完条件之后直接得出结果,因为肯定没有数量条件,自己拼接 |
| | | logger.Info("规则的算法id和区域的算法id:",rule.SdkId,"===",am.sdkId) |
| | | logger.Error("规则的算法id和区域的算法id:",rule.SdkId,"===",am.sdkId) |
| | | if rule.SdkId == am.sdkId && rule.PolygonId == am.areaId { // 算法和区域都得对的上 |
| | | |
| | | if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" && rule.SdkArgAlias != "time_rule"{ |
| | | // 只需要过滤阈值,过滤完后数组长度大于0即为报警,但要考虑如何对每一张都报警呢 |
| | | argValue, err := strconv.ParseFloat(rule.SdkArgValue, 64) |
| | | if err != nil { |
| | | logger.Info("规则配置的阈值非法") |
| | | logger.Error("规则配置的阈值非法") |
| | | return LittleRuleResult{am.sdkName, rule.RuleWithPre + "" + "false", rule.Sort} |
| | | } |
| | | flag := "false" |