| | |
| | | if tar.N == 0 && tar.AlarmFlag { |
| | | logger.Debug("-------------------------符合持续时间规则但并不是首次,不报警") |
| | | flagTime = "11" |
| | | o.TimeLable = flagTime |
| | | o.CacheData = tar.CacheSdkData |
| | | } |
| | | if tar.N == 0 && !tar.AlarmFlag { // 这组规则的定时器要全部等于0 暂且认为一组规则只有一个定时器 |
| | | logger.Debug("———————————-------------首次符合持续时间规则并报警") |
| | | flagTime = "10" |
| | | tar.AlarmFlag = true |
| | | o.TimeLable = flagTime |
| | | o.CacheData = tar.CacheSdkData |
| | | } |
| | | if tar.N != 0 { |
| | |
| | | logger.Info("插入定时目标信息:",len(msg.RuleResult["target"].([]structure.Result))) |
| | | for _, yoloResult := range msg.RuleResult["target"].([]structure.Result) { |
| | | // 装载目标信息` |
| | | logger.Info("报警目标个数:",len(yoloResult.AlarmObj)) |
| | | // 如果有首次报警的则本帧数据可以插入 |
| | | insertFlag := false |
| | | alarmNum := 0 |
| | | for _,obj := range yoloResult.AlarmObj { |
| | | if obj.TimeLable == "10" { |
| | | insertFlag = true |
| | | alarmNum++ |
| | | } |
| | | } |
| | | if insertFlag { |
| | | logger.Info("报警目标个数:",alarmNum) |
| | | //var target = new(Target) |
| | | //target.TargetId = strconv.FormatUint(tar.Id, 10) |
| | | //target.TargetScore = tar.Score |
| | |
| | | //os.Exit(1) |
| | | } |
| | | } |
| | | } else { |
| | | logger.Info("没有首次报警的目标,不插入") |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp1, err1 := util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl) |
| | | resp1, err1 := util.DrawPolygonOnImageForTarget(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl) |
| | | if err1 != nil { |
| | | logger.Error("缓存数据画框或上传图片服务器出错", err) |
| | | } else { |
| | |
| | | Feature []byte |
| | | ThftRes protomsg.ThftResult |
| | | Liker []*BaseInfo |
| | | TimeLable string |
| | | CacheData ResultMsg |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | func DrawPolygonOnImageForTarget(cameraId string, img protomsg.Image, results []structure.Result,url string) (maps map[string]interface{}, err0 error) { |
| | | |
| | | rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data) |
| | | //rook := gocv.IMRead("/home/user/workspace/ruleprocess/util/105.jpg",gocv.IMReadColor) |
| | | defer rook.Close() |
| | | |
| | | yellow := color.RGBA{255, 255, 0, 0} |
| | | red := color.RGBA{255, 0, 0, 0} |
| | | scale := float64(img.Width) / 960 // 画图比例 |
| | | logger.Info("width:",img.Width,"--画图比例:",scale) |
| | | // 分割区域id集合并根据id查询区域然后画框 |
| | | for _,result := range results { |
| | | polygonIds := strings.Split(result.AlarmPolygon,",") |
| | | logger.Info("区域ID:",result.AlarmPolygon,polygonIds) |
| | | for i := 0; i < len(polygonIds); i++ { |
| | | polygon := getPolygonById(polygonIds[i],cameraId) |
| | | if polygon.Polygon != "[]" && polygon.Polygon != ""{ |
| | | DrawAPolygon(&rook,polygon.Polygon,yellow,scale) |
| | | } |
| | | } |
| | | } |
| | | // 把目标框出来 |
| | | for _,result := range results { |
| | | for _,rect := range result.AlarmObj { |
| | | gocv.Rectangle(&rook, image.Rect(int(rect.Location.X), int(rect.Location.Y), int(rect.Location.X+rect.Location.Width), int(rect.Location.Y+rect.Location.Height)), red, 1) |
| | | } |
| | | } |
| | | //return nil,nil |
| | | maps,err0 = UploadFromMat(url,rook) |
| | | return |
| | | } |
| | | func DrawPolygonOnImageForFace(cameraId string, img protomsg.Image, results []structure.Result,url string) (maps map[string]interface{}, err0 error) { |
| | | |
| | | rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data) |