| | |
| | | } |
| | | // 往ES插数据 |
| | | func InsertToEs(msg ruleserver.ResultMsg) { |
| | | fmt.Println("往ES插数据") |
| | | log.Println("往ES插数据") |
| | | |
| | | for _, sdkinfo := range msg.Tasklab.Sdkinfos { |
| | | if sdkinfo.Sdktype == "FaceDetect" { |
| | |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err1 := proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err1 != nil { |
| | | fmt.Println("解析FACE sdk有误", err1) |
| | | log.Println("解析FACE sdk有误", err1) |
| | | continue |
| | | } |
| | | for _, face := range faceParam.Faces { |
| | |
| | | requstbody, err := json.Marshal(pervideo) |
| | | |
| | | if err != nil { |
| | | fmt.Println("json parse error ", err) |
| | | log.Println("json parse error ", err) |
| | | return |
| | | |
| | | } |
| | | err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) |
| | | if err != nil { |
| | | fmt.Println("es can not execute right.") |
| | | log.Println("es can not execute right.") |
| | | } |
| | | } |
| | | } else { |
| | |
| | | yoloObj := protomsg.ParamYoloObj{} |
| | | err1 := proto.Unmarshal(sdkinfo.Sdkdata, &yoloObj) |
| | | if err1 != nil { |
| | | fmt.Println("解析YOLO sdk有误", err1) |
| | | log.Println("解析YOLO sdk有误", err1) |
| | | //continue |
| | | } |
| | | alarmRules := []AlarmRule{} |
| | |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp,err = util.PostFormBufferData(weedfsUrl,i.Data,uuid.NewV4().String()) |
| | | log.Println("已报警并上传改帧图片到服务器") |
| | | }else { |
| | | isAlarm = "0" |
| | | //continue |
| | |
| | | // 查询本机信息 |
| | | flag,localConfig := dbapi.SysSetApi{}.GetServerInfo() |
| | | if !flag { |
| | | fmt.Println("查询本机信息失败!") |
| | | log.Println("查询本机信息失败!") |
| | | } |
| | | // 查询cameraName |
| | | camera,err := dbapi.CameraApi{}.GetCameraById(msg.Cid) |
| | | if err == nil { |
| | | fmt.Println("查询摄像机信息失败") |
| | | log.Println("查询摄像机信息失败") |
| | | } |
| | | serverIp,err := GetLocalIP() |
| | | peraction := Personaction{ |
| | |
| | | requstbody, err := json.Marshal(peraction) |
| | | |
| | | if err != nil { |
| | | fmt.Println("json parse error ", err) |
| | | log.Println("json parse error ", err) |
| | | return |
| | | |
| | | } |
| | | err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody) |
| | | if err != nil { |
| | | fmt.Println("es can not execute right.") |
| | | log.Println("es can not execute right.") |
| | | } |
| | | } else { |
| | | continue |
| | |
| | | fmt.Println("数据长度为:", len(sdkinfo.Sdkdata)) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | // 大于1才有数据 |
| | | fmt.Println("----------------------------------------------------------------------------------------------------------") |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | |
| | | if sdkinfo.Sdktype == "FaceDetect" { // 人脸检测 |
| | | fmt.Println("数据长度为:", len(sdkinfo.Sdkdata)) |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | fmt.Println("----------------------------------------------------------------------------------------------------------") |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | |
| | | score float64 // 区域内的目标的相似度 |
| | | proportion float64 // 区域内的目标的占比 |
| | | size float64 // 区域内的目标的尺寸 |
| | | liker []LikePerson |
| | | } |
| | | |
| | | type LikePerson struct { |
| | | Id string // 与之相似的底库人员的id |
| | | Score float64 // 与底库人员的相似值 |
| | | } |
| | | |
| | | // 每个区域内的图片数据集合 |
| | |
| | | // sdk输出的图片上单个目标的数据 |
| | | type PhotoMap struct { |
| | | Rects Rect // 矩形区域参数 |
| | | Score float64 // 相似度得分 |
| | | Score float64 // 相似度得分(有多大程度像一个目标。人脸,人体或车等等) |
| | | Liker []LikePerson // 如果是人脸的话尤其是比对,应存下他跟底库的人员的相似情况 yolo的话给nil就行 |
| | | } |
| | | |
| | | // 从通道中获取的sdk输出的图像数据(目前主要是yolo算法的数据) |
| | |
| | | type Result struct { |
| | | TaskId string // 任务id |
| | | RuleGroupId string // 规则组id |
| | | AlarmLevel int32 // 报警等级 |
| | | AlarmLevel int32 // 报警等级 |
| | | RuleText string // 文字版规则组 |
| | | } |
| | | |
| | |
| | | func Json2points(areaPoints string) []Point { |
| | | var pts []Point |
| | | if areaPoints == "" { |
| | | pts = append(pts,Point{0,0}) |
| | | pts = append(pts,Point{0,540}) |
| | | pts = append(pts,Point{960,540}) |
| | | pts = append(pts,Point{960,0}) |
| | | pts = append(pts, Point{0, 0}) |
| | | pts = append(pts, Point{0, 540}) |
| | | pts = append(pts, Point{960, 540}) |
| | | pts = append(pts, Point{960, 0}) |
| | | } else { |
| | | err := json.Unmarshal([]byte(areaPoints), &pts) |
| | | if err != nil { |
| | |
| | | if flag { |
| | | fmt.Println("定时器报警了") |
| | | // 过完规则后打个标签,告诉调用者本帧数据针对哪个任务哪组规则报警了 |
| | | arg.RuleResult = append(arg.RuleResult, Result{taskId, groupRule.GroupId,groupRule.AlarmLevel,groupRule.GroupText}) |
| | | arg.RuleResult = append(arg.RuleResult, Result{taskId, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText}) |
| | | return true |
| | | } else { |
| | | return false |
| | |
| | | formula = strconv.FormatFloat(arg.size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | if result.(bool) { |
| | | am.filterData = append(am.filterData, arg) // 得到符合条件的过滤数据 |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 冗余拼接 |
| | | func splice1 (am *AreaMap) string { |
| | | func splice1(am *AreaMap) string { |
| | | args := am.targetNum |
| | | formula := strconv.Itoa(args) + " " + ">" + "0" |
| | | formula := strconv.Itoa(args) + " " + ">" + "0" |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | return strconv.FormatBool(result.(bool)) |
| | | } |
| | | |
| | | // 给数据库的规则表达式代参 args: 一条子规则,区域数据 |
| | | func transferParameters(rule *protomsg.Rule, am *AreaMap) string { |
| | | if rule.PolygonId == am.areaId { // 首先规则所对应的区域id要跟区域数据的id对的上 |
| | |
| | | } else if rule.SdkId == "FaceDetect" { // 人脸检测 |
| | | if rule.Operator == "==" || rule.Operator == ">=" || rule.Operator == "<=" || rule.Operator == "<" || rule.Operator == ">" || rule.Operator == "!=" { |
| | | // 如果是不规矩的连接符统统返回false 规则也只能判断人脸的相似度,所以不存在别的连接符 |
| | | |
| | | return "false" |
| | | } else { |
| | | return "false" |
| | | } |
| | | } else { |
| | | } else if rule.SdkId == "FaceCompare"{ |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package util |
| | | |
| | | import ( |
| | | "bytes" |
| | | "fmt" |
| | | "image" |
| | | "image/jpeg" |
| | | "reflect" |
| | | ) |
| | | // 按尺寸去切图 |
| | | func subimg(dbyte []byte,x0,y0,x1,y1 int,) []byte{ |
| | | |
| | | bbb := bytes.NewBuffer(dbyte) // 必须加一个buffer 不然没有read方法就会报错 |
| | | m, _, _ := image.Decode(bbb) // 图片文件解码 |
| | | rgbImg := m.(*image.YCbCr) |
| | | subImg := rgbImg.SubImage(image.Rect(x0, y0, x1, y1)) //图片裁剪x0 y0 x1 y1 |
| | | fmt.Println(reflect.TypeOf(subImg)) |
| | | //f, _ := os.Create("./test.jpg") //创建文件 |
| | | //defer f.Close() //关闭文件 |
| | | emptyBuff := bytes.NewBuffer(nil) //开辟一个新的空buff |
| | | jpeg.Encode(emptyBuff, subImg, nil) //img写入到buff |
| | | bytes := emptyBuff.Bytes() |
| | | return bytes |
| | | //f, _ := os.Create("./test.jpg") //创建文件 |
| | | //defer f.Close() //关闭文件 |
| | | //jpeg.Encode(f, subImg, nil) //写入文件 |
| | | } |