| | |
| | | package insertdata |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "ruleprocess/structure" |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "net" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/logger" |
| | | "strconv" |
| | | "time" |
| | | |
| | |
| | | DbTablePersons string `yaml:"dbTablePersons"` |
| | | } |
| | | |
| | | func InitInsertEs() { |
| | | weedfsUrl = "http://"+WeedFs.Ip+":"+strconv.Itoa(WeedFs.UploadPort)+"/submit" |
| | | videoPersonUrl = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType |
| | | personAction = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType |
| | | } |
| | | //func InitInsertEs() { |
| | | // weedfsUrl = "http://"+WeedFs.Ip+":"+strconv.Itoa(WeedFs.UploadPort)+"/submit" |
| | | // videoPersonUrl = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType |
| | | // personAction = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType |
| | | //} |
| | | |
| | | // 人脸的数据结构 |
| | | type PerVideoPicture struct { |
| | |
| | | IsAckAlarm int `json:"isAckAlarm"` |
| | | IsCollect int `json:"isCollect"` |
| | | IsDelete int `json:"isDelete"` |
| | | BaseInfo []*ruleserver.BaseInfo `json:"baseInfo"` |
| | | BaseInfo []*structure.BaseInfo `json:"baseInfo"` |
| | | } |
| | | |
| | | // yolo行为的数据结构 |
| | |
| | | |
| | | // 一个face对多个规则组的归置人脸的结构体 |
| | | type FaceAndRules struct { |
| | | ruleserver.Arg |
| | | rules []ruleserver.Result |
| | | structure.Arg |
| | | rules []structure.Result |
| | | } |
| | | |
| | | // 往ES插数据 |
| | |
| | | // // ChangeStatusYolo(msg) |
| | | // //} |
| | | //} |
| | | func InsertToEs(msg ruleserver.ResultMsg) { |
| | | func InsertToEs(msg structure.ResultMsg) { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("es模块儿的异常捕获:",err) |
| | | } |
| | | }() |
| | | localConfig1, err := cache.GetServerInfo() |
| | | if err != nil { |
| | | panic("配置文件不合法") |
| | | } |
| | | weedfsUrl = "http://"+localConfig1.WebPicIp+":"+strconv.Itoa(int(localConfig1.WebPicPort))+"/submit" |
| | | videoPersonUrl = "http://"+localConfig1.AlarmIp+":"+strconv.Itoa(int(localConfig1.AlarmPort))+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType |
| | | personAction = "http://"+localConfig1.AlarmIp+":"+strconv.Itoa(int(localConfig1.AlarmPort))+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType |
| | | InsertFace(msg, "") |
| | | // 如果标签中含有持续时间首次报警的timeLabel的话则不需要过人体追踪,不然就没的插入了 |
| | | fk := ruleserver.TrackOrNot(msg.RuleResult) |
| | |
| | | } |
| | | |
| | | // 往es中插入人脸数据 |
| | | func InsertFace(msg ruleserver.ResultMsg, linkId string) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 { |
| | | func InsertFace(msg structure.ResultMsg, linkId string) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 { |
| | | logger.Info("往ES插人脸数据") |
| | | faces := []*FaceAndRules{} |
| | | faces = PutFace(faces,msg) |
| | | //logger.Info("整理后的数据:",faces) |
| | | if faces != nil { |
| | | var imgMaxUrl string = "" |
| | | var picTime string = "" |
| | | for _,face := range faces { |
| | | // 上传大图 |
| | | // 解压缩并上传图片 |
| | |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | if imgMaxUrl == "" { |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | imgMaxUrl = bigPhotoUrl["fileUrl"].(string) |
| | | picTime = i.Timestamp |
| | | } |
| | | // 人脸检测,没有相似的底库人员 |
| | | localConfig, err := cache.GetServerInfo() |
| | | if err != nil { |
| | |
| | | if linkId != "" { |
| | | linksId = linkId |
| | | } |
| | | logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10)) |
| | | logger.Info("人脸的分值:",face.Score) |
| | | //logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10)) |
| | | //logger.Info("人脸的分值:",face.Score) |
| | | pervideo := PerVideoPicture{ |
| | | esDataId, |
| | | msg.Cid, |
| | | camera.Addr, |
| | | i.Timestamp, |
| | | bigPhotoUrl["fileUrl"].(string), |
| | | picTime, |
| | | imgMaxUrl, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | "人脸", |
| | | "", |
| | | alarmRules, |
| | | time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间 |
| | | strconv.FormatUint(face.Id, 10), //暂改为人脸id strconv.FormatUint(face.Id, 10) |
| | | sex, //暂改为人脸id strconv.FormatUint(face.Id, 10) |
| | | face.ThftRes.Age, |
| | | fmt.Sprintf("%.2f",face.Score), // 暂改为分值fmt.Sprintf("%.2f",face.Score) |
| | | ageDescription, // 暂改为分值fmt.Sprintf("%.2f",face.Score) |
| | | race, |
| | | face.ThftRes.Smile, |
| | | face.ThftRes.Beauty, |
| | |
| | | } |
| | | |
| | | // 归置人脸 |
| | | func PutFace(faces []*FaceAndRules,msg ruleserver.ResultMsg)[]*FaceAndRules{ |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]ruleserver.FaceResult) { |
| | | func PutFace(faces []*FaceAndRules,msg structure.ResultMsg)[]*FaceAndRules{ |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]structure.FaceResult) { |
| | | faces = hebingFace(faces, faceResult) |
| | | } |
| | | return faces |
| | |
| | | return nil |
| | | } |
| | | } |
| | | func hebingFace(faces []*FaceAndRules, faceResult ruleserver.FaceResult) []*FaceAndRules{ |
| | | func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules{ |
| | | for _, arg := range faceResult.Args { |
| | | // 拿到每一张人脸 |
| | | logger.Info("归置人脸时相似者的数量:",len(arg.Liker)) |
| | |
| | | } |
| | | } |
| | | if !flag { |
| | | faces = append(faces, &FaceAndRules{arg, []ruleserver.Result{faceResult.Result}}) |
| | | faces = append(faces, &FaceAndRules{arg, []structure.Result{faceResult.Result}}) |
| | | } |
| | | } |
| | | return faces |
| | | } |
| | | |
| | | // 往es中插入yolo数据 |
| | | func InsertYolo(msg ruleserver.ResultMsg, linkId string) { |
| | | if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 { |
| | | func InsertYolo(msg structure.ResultMsg, linkId string) { |
| | | if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]structure.Result)) > 0 { |
| | | // 先判断一下数据带的规则标签是否有可以插入的 |
| | | flag := false |
| | | for _, res := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | for _, res := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | //logger.Info("定时器打的数字标签:",res.Others.TimeLabel) |
| | | if res.Others.TimeLabel == "01" || res.Others.TimeLabel == "10" { |
| | | flag = true |
| | |
| | | var sdkNames string = "" |
| | | alarmRules := []AlarmRule{} |
| | | url := []string{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" { |
| | | // 拼出sdkname |
| | | //logger.Info("应该进来才对的") |
| | |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp1, err1 := util.DrawPolygonOnImage(msg1.Cid, i, msg1.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl) |
| | | resp1, err1 := util.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err1 != nil { |
| | | logger.Error("缓存数据画框或上传图片服务器出错", err) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | linkFlag := false |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if (yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10") && yoloResult.Others.LinkCache != nil && len(yoloResult.Others.LinkCache) > 1 { |
| | | linkId := uuid.NewV4().String() |
| | | for _, msg2 := range yoloResult.Others.LinkCache { |
| | |
| | | if len(alarmRules) > 0 { |
| | | isAlarm = 1 |
| | | //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | resp, err = util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl) |
| | | resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err != nil { |
| | | logger.Error("画框或上传图片服务器出错", err) |
| | | return |