| | |
| | | ) |
| | | |
| | | const ( |
| | | FDetect = "FaceDetect" |
| | | FExtract = "FaceExtract" |
| | | FDetect = "FaceDetect" // ParamFacePos 检测 |
| | | FExtract = "FaceExtract" // ParamFaceFeature 提取 |
| | | FProperty = "FaceProperty" |
| | | FCompare = "FaceCompare" |
| | | FtTract = "FaceTrack" |
| | |
| | | go 1.12 |
| | | |
| | | require ( |
| | | basic.com/dbapi.git v0.0.0-20190617110911-fa5d3510c294 |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190619101540-30768d386c39 |
| | | basic.com/dbapi.git v0.0.0-20190622030047-3ea90a522ec1 |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190622023307-97ef3bf336ef |
| | | basic.com/valib/deliver.git v0.0.0-20190531095353-25d8c3b20051 |
| | | github.com/Microsoft/go-winio v0.4.12 // indirect |
| | | github.com/ajg/form v1.5.1 // indirect |
| | | github.com/gogo/protobuf v1.2.1 // indirect |
| | | github.com/golang/protobuf v1.3.1 |
| | | github.com/gorilla/websocket v1.4.0 // indirect |
| | | github.com/knetic/govaluate v3.0.0+incompatible |
| | | github.com/pierrec/lz4 v2.2.3+incompatible |
| | | github.com/satori/go.uuid v1.2.0 |
| | | github.com/tmthrgd/go-sem v0.0.0-20160607101025-0214dbf53877 // indirect |
| | | github.com/tmthrgd/go-shm v0.0.0-20170117044846-90afcfcd5ee9 // indirect |
| | | github.com/tmthrgd/shm-go v0.0.0-20170130075737-7207ca97b290 // indirect |
| | |
| | | basic.com/dbapi.git v0.0.0-20190617110911-fa5d3510c294 h1:DPtNV4iwgwx6KZ9/Zx7m5Rlhto4w3eKu38JYWhluX44= |
| | | basic.com/dbapi.git v0.0.0-20190617110911-fa5d3510c294/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190618064639-ad379d891965 h1:fo7P3P4XNZGRWgUIOMTNR3JtqmT0gObCSU7PlvizUbk= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190618064639-ad379d891965/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190619101540-30768d386c39 h1:eTlC2Li3IDLyF3uJwFnkSw0YWDQQg9UYqm97356MEJI= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190619101540-30768d386c39/go.mod h1:un5NV5VWQoblVLZfx1Rt5vyLgwR0jI92d3VJhfrJhWU= |
| | | basic.com/dbapi.git v0.0.0-20190622030047-3ea90a522ec1 h1:MAAgMzO1rd9+gYYksrtOWIB4dqQZvZEjwaZImygpSgk= |
| | | basic.com/dbapi.git v0.0.0-20190622030047-3ea90a522ec1/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190622023307-97ef3bf336ef h1:gUV9FEa23v+2AY4Rvrwh6omHBlV+qyae58GTU8NAv3Y= |
| | | basic.com/pubsub/protomsg.git v0.0.0-20190622023307-97ef3bf336ef/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= |
| | | code.cloudfoundry.org/bytefmt v0.0.0-20180906201452-2aa6f33b730c/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= |
| | | github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc= |
| | | github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= |
| | | github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= |
| | | github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= |
| | | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| | | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| | | github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= |
| | |
| | | github.com/pierrec/lz4 v2.2.3+incompatible h1:YpgKDCFg5dd0Eb+XlgrfJtH4fAqoRA1kBcKnBZ4EFSE= |
| | | github.com/pierrec/lz4 v2.2.3+incompatible/go.mod h1:g2rHQ0wsQlPM7GZ66p1EVBh+VdeJ8s60jWWxl1M9t1Q= |
| | | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
| | | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= |
| | | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= |
| | | github.com/schollz/progressbar/v2 v2.12.1/go.mod h1:fBI3onORwtNtwCWJHsrXtjE3QnJOtqIZrvr3rDaF7L0= |
| | | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
| | | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
New file |
| | |
| | | package insertdata |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io" |
| | | "io/ioutil" |
| | | "net/http" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | "bytes" |
| | | ) |
| | | |
| | | type Reps struct { |
| | | FaceFeature string `json:"faceFeature"` |
| | | ID string |
| | | } |
| | | |
| | | // 获取es 数据结构 |
| | | func GetEsDataReq(url string, parama string) ([]Reps, error) { |
| | | |
| | | var reps Reps |
| | | var repss []Reps |
| | | fmt.Println("es 查询请求路径" + url) // 配置信息 获取 |
| | | req, err := http.NewRequest("POST", url, strings.NewReader(parama)) |
| | | |
| | | if err != nil { |
| | | fmt.Println("build request error! ") |
| | | return nil, err |
| | | } |
| | | |
| | | req.Header.Add("Content-Type", "application/json") |
| | | timeout := time.Duration(100 * time.Second) |
| | | client := &http.Client{Timeout: timeout} |
| | | resp, err := client.Do(req) |
| | | |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | jsonStr := string(body) |
| | | var dat map[string]interface{} |
| | | dec := json.NewDecoder(strings.NewReader(jsonStr)) |
| | | |
| | | if err := dec.Decode(&dat); err == io.EOF { |
| | | fmt.Println(err.Error()) |
| | | return nil, err |
| | | } else if err != nil { |
| | | fmt.Println(err.Error()) |
| | | return nil, err |
| | | } |
| | | dat, ok := dat["hits"].(map[string]interface{}) |
| | | if !ok { |
| | | return nil, errors.New("data is not type of map[string]interface{}") |
| | | } |
| | | |
| | | for _, value := range dat["hits"].([]interface{}) { |
| | | source, ok := value.(map[string]interface{})["_source"].(map[string]interface{}) |
| | | if !ok { |
| | | return nil, errors.New("value is not type of map[string]interface{}") |
| | | } |
| | | reps.FaceFeature, ok = source["faceFeature"].(string) |
| | | if !ok { |
| | | fmt.Println("faceFeature is not string", source["faceFeature"]) |
| | | continue |
| | | } |
| | | reps.ID, ok = source["ID"].(string) |
| | | if !ok { |
| | | fmt.Println("ID is not string", source["ID"]) |
| | | continue |
| | | } |
| | | |
| | | repss = append(repss, reps) |
| | | } |
| | | return repss, nil |
| | | |
| | | } |
| | | |
| | | func PostAction(querynum int, queryindex int) ([]Reps, error) { |
| | | defer elapsed("page")() |
| | | number := strconv.Itoa(querynum) |
| | | point := strconv.Itoa(queryindex) |
| | | url := "http://192.168.1.182:9200/videopersons/_search" |
| | | parma := `{ |
| | | "from":` + point + `, |
| | | "query": { |
| | | "match_all": {} |
| | | }, |
| | | "sort": [ |
| | | { |
| | | "picDate": { |
| | | "order": "desc" |
| | | } |
| | | } |
| | | ], |
| | | "size":` + number + `, |
| | | "_source": [ |
| | | "faceFeature", |
| | | "ID" |
| | | ] |
| | | }` |
| | | |
| | | repss, err := GetEsDataReq(url, parma) |
| | | return repss, err |
| | | } |
| | | |
| | | /** 插入es: |
| | | *** url: http://192.168.1.203:9200/personaction/perVideoAction/c58dbddf-4580-43f3-b76a-3213ec809df2?pretty |
| | | **param: // json [json slice] |
| | | */ |
| | | |
| | | /** 添加或者删除收藏 |
| | | *** url: http://192.168.1.203:9200/videopersons/perVideoPicture/_id/_update |
| | | param: []byte |
| | | json: { |
| | | "doc": { |
| | | "collection": "1" // 1 is 收藏 0 取消收藏 |
| | | } |
| | | "detect_noop": false |
| | | } |
| | | **/ |
| | | |
| | | func EsReq(method string, url string, parama []byte) (err error) { |
| | | timeout := time.Duration(10 * time.Second) |
| | | client := http.Client{ |
| | | Timeout: timeout, |
| | | } |
| | | request, err := http.NewRequest(method, url, bytes.NewBuffer(parama)) |
| | | request.Header.Set("Content-type", "application/json") |
| | | |
| | | if err != nil { |
| | | fmt.Println("build request fail !") |
| | | return err |
| | | } |
| | | |
| | | resp, err := client.Do(request) |
| | | if err != nil{ |
| | | fmt.Println("request error: ", err) |
| | | return err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | } |
| | | |
| | | fmt.Println(string(body)) |
| | | return nil |
| | | } |
| | | |
| | | |
| | | func elapsed(what string) func() { |
| | | start := time.Now() |
| | | return func() { |
| | | fmt.Printf("%s took %v\n", what, time.Since(start)) |
| | | } |
| | | } |
New file |
| | |
| | | package insertdata |
| | | |
| | | import ( |
| | | "errors" |
| | | "fmt" |
| | | "encoding/json" |
| | | "net" |
| | | "time" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/dbapi.git" |
| | | "github.com/golang/protobuf/proto" |
| | | "ruleprocess/ruleserver" |
| | | "github.com/satori/go.uuid" |
| | | ) |
| | | |
| | | // 人脸的数据结构 |
| | | type PerVideoPicture struct { |
| | | Id string `json:"id"` |
| | | CameraId string `json:"cameraId"` |
| | | CameraAddr string `json:"cameraAddr"` |
| | | PicDate string `json:"picDate"` |
| | | PicMaxUrl string `json:"picMaxUrl"` |
| | | TaskId string `json:"taskId"` |
| | | TaskName string `json:"taskName"` |
| | | SdkName string `json:"sdkName"` |
| | | Content string `json:"content"` |
| | | LikeDate string `json:"likeDate"` |
| | | Sex int32 `json:"sex"` |
| | | Age int32 `json:"age"` |
| | | AgeDescription string `json:"ageDescription"` |
| | | Race int32 `json:"race"` |
| | | SmileLevel int32 `json:"smileLevel"` |
| | | BeautyLevel int32 `json:"beautyLevel"` |
| | | FaceFeature string `json:"faceFeature"` |
| | | PicSmUrl string `json:"picSmUrl"` |
| | | VideoUrl string `json:"videoUrl"` |
| | | AnalyServerId string `json:"analyServerId"` |
| | | AnalyServerName string `json:"analyServerName"` |
| | | AnalyServerIp string `json:"analyServerIp"` |
| | | ClusterId string `json:"clusterId"` |
| | | IsAlarm string `json:"isAlarm"` |
| | | IsAckAlarm string `json:"isAckAlarm"` |
| | | IsCollect string `json:"isCollect"` |
| | | IsDelete int `json:"isDelete"` |
| | | BaseInfo Base `json:"baseInfo"` |
| | | } |
| | | |
| | | type Base struct { |
| | | TableId string `json:"tableId"` |
| | | TableName string `json:"tableName"` |
| | | CompareScore float64 `json:"compareScore"` |
| | | PersonId string `json:"personId"` |
| | | PersonName string `json:"personName"` |
| | | PersonPicUrl string `json:"personPicUrl"` |
| | | PhoneNum string `json:"phoneNum"` |
| | | Sex string `json:"sex"` |
| | | IdCard string `json:"idCard"` |
| | | MonitorLevel string `json:"monitorLevel"` |
| | | Content string `json:"content"` |
| | | } |
| | | |
| | | // yolo行为的数据结构 |
| | | type Personaction struct { |
| | | Id string `json:"id"` |
| | | CameraId string `json:"cameraId"` |
| | | CameraName string `json:"cameraName"` |
| | | CameraAddr string `json:"cameraAddr"` |
| | | TaskId string `json:"taskId"` |
| | | TaskName string `json:"taskName"` |
| | | SdkName string `json:"sdkName"` |
| | | Content string `json:"content"` |
| | | AlarmRules []AlarmRule |
| | | AnalyServerId string `json:"analyServerId"` |
| | | AnalyServerName string `json:"analyServerName"` |
| | | AnalyServerIp string `json:"analyServerIp"` |
| | | ClusterId string `json:"clusterId"` |
| | | PicUrl string `json:"picUrl"` |
| | | PicDate string `json:"picDate"` |
| | | VideoUrl string `json:"videoUrl"` |
| | | IsAlarm string `json:"isAlarm"` |
| | | IsAckAlarm string `json:"isAckAlarm"` |
| | | IsCollect string `json:"isCollect"` |
| | | IsDelete int `json:"isDelete"` |
| | | } |
| | | |
| | | type AlarmRule struct { |
| | | GroupId string `json:"groupId"` |
| | | AlarmLevel string `json:"alarmLevel"` |
| | | RuleText string `json:"ruleText"` |
| | | } |
| | | |
| | | func InsertToEs(msg ruleserver.ResultMsg) { |
| | | fmt.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("解析sdk数据时出现错误", err1) |
| | | continue |
| | | } |
| | | for _, face := range faceParam.Faces { |
| | | pervideo := PerVideoPicture{ |
| | | uuid.NewV4().String(), |
| | | msg.Cid, |
| | | msg.Caddr, |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | "", |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | sdkinfo.SdkName, |
| | | "", |
| | | "", |
| | | face.Result.Gender, |
| | | face.Result.Age, |
| | | "", |
| | | face.Result.Race, |
| | | face.Result.Smile, |
| | | face.Result.Beauty, |
| | | "不是每个人脸算法都有", |
| | | "---", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | 0, |
| | | Base{ |
| | | "是每个人脸算法都有吗", |
| | | "", |
| | | 0, |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | "", |
| | | }, |
| | | } |
| | | requstbody, err := json.Marshal(pervideo) |
| | | |
| | | if err != nil { |
| | | fmt.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.") |
| | | } |
| | | } |
| | | } |
| | | if sdkinfo.Sdktype == "Yolo" { |
| | | yoloObj := protomsg.ParamYoloObj{} |
| | | err1 := proto.Unmarshal(sdkinfo.Sdkdata, &yoloObj) |
| | | if err1 != nil { |
| | | fmt.Println("解析sdk数据时出现错误", err1) |
| | | continue |
| | | } |
| | | alarmRules := []AlarmRule{} |
| | | for _,result := range msg.RuleResult { |
| | | alarmRules = append(alarmRules,AlarmRule{result.RuleGroupId,result.AlarmLevel,result.RuleText}) |
| | | } |
| | | isAlarm := "" |
| | | if len(alarmRules) > 0 { |
| | | isAlarm = "1" |
| | | }else { |
| | | isAlarm = "0" |
| | | } |
| | | // 查询本机信息 |
| | | flag,localConfig := dbapi.SysSetApi{}.GetServerInfo() |
| | | if !flag { |
| | | fmt.Println("查询本机信息失败!") |
| | | } |
| | | // 查询cameraName |
| | | camera,err := dbapi.CameraApi{}.GetCameraById(msg.Cid) |
| | | if err == nil { |
| | | fmt.Println("查询摄像机信息失败") |
| | | } |
| | | serverIp,err := GetLocalIP() |
| | | peraction := Personaction{ |
| | | uuid.NewV4().String(), |
| | | msg.Cid, |
| | | camera.Name, |
| | | msg.Caddr, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | sdkinfo.SdkName, |
| | | "", |
| | | alarmRules, |
| | | localConfig.ServerId, |
| | | localConfig.ServerName, |
| | | serverIp, |
| | | "", |
| | | "", |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | "", |
| | | isAlarm, |
| | | "", |
| | | "", |
| | | 0, |
| | | } |
| | | requstbody, err := json.Marshal(peraction) |
| | | |
| | | if err != nil { |
| | | fmt.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.") |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // 获取本机ip |
| | | func GetLocalIP() (ipv4 string, err error) { |
| | | var ( |
| | | addrs []net.Addr |
| | | addr net.Addr |
| | | ipNet *net.IPNet // IP地址 |
| | | isIpNet bool |
| | | ) |
| | | // 获取所有网卡 |
| | | if addrs, err = net.InterfaceAddrs(); err != nil { |
| | | return |
| | | } |
| | | // 取第一个非lo的网卡IP |
| | | for _, addr = range addrs { |
| | | // 这个网络地址是IP地址: ipv4, ipv6 |
| | | if ipNet, isIpNet = addr.(*net.IPNet); isIpNet && !ipNet.IP.IsLoopback() { |
| | | // 跳过IPV6 |
| | | if ipNet.IP.To4() != nil { |
| | | ipv4 = ipNet.IP.String() // 192.168.1.1 |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | err = errors.New("ipv4 not found") |
| | | return |
| | | } |
New file |
| | |
| | | package insertdata |
| | | |
| | | import "testing" |
| | | |
| | | func TestInsertToEs(t *testing.T){ |
| | | InsertToEs() |
| | | } |
| | |
| | | import ( |
| | | "fmt" |
| | | "ruleprocess/ruleserver" |
| | | "ruleprocess/insertdata" |
| | | |
| | | "sync" |
| | | "analysis/work" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/deliver.git" |
| | | "github.com/golang/protobuf/proto" |
| | |
| | | // 把arg里的打的标签拿出来给m再封装一层 |
| | | resultMag := ruleserver.ResultMsg{SdkMessage: m, RuleResult: arg.RuleResult} |
| | | fmt.Println("打完标签后的结果:",resultMag) |
| | | |
| | | // 将打完标签的数据插入到ES |
| | | insertdata.InsertToEs(resultMag) |
| | | } |
| | | } |
| | | } |
| | |
| | | arg.KeepRight = false |
| | | arg.IsStatic = false |
| | | fmt.Println("从mongos中拿到的数据包长度为:", len(msg)) |
| | | for _, sdkinfo := range m.Tasklab.Sdkinfos { |
| | | for _, sdkinfo := range m.Tasklab.Sdkinfos { // yolo算法 |
| | | if sdkinfo.Sdktype == "Yolo" { |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | |
| | | } |
| | | |
| | | } |
| | | if sdkinfo.Sdktype == "FaceDetect" { // 人脸检测 |
| | | faceParam := protomsg.ParamFacePos{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) |
| | | if err != nil { |
| | | fmt.Println("解析sdk数据时出现错误", err) |
| | | continue |
| | | } |
| | | for _, info := range faceParam.Faces { |
| | | photoMap := ruleserver.PhotoMap{Rects:nil, Score: float64(info.Pos.Quality)} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | } |
| | | //if sdkinfo.Sdktype == "FaceExtract" { // 人脸提取 |
| | | |
| | | //} |
| | | |
| | | } |
| | | return m |
| | | } |
| | |
| | | |
| | | // 从通道中获取的sdk输出的图像数据(目前主要是yolo算法的数据) |
| | | type ArgsFromSdk struct { |
| | | Photo []PhotoMap |
| | | CameraId string |
| | | TaskId string |
| | | KeepRight bool // 是否靠右行 算法判断的与上一帧图像的比较结果 |
| | | IsStatic bool // 是否静止 |
| | | ImageWidth int // 摄像机拍摄的图像宽 像素 |
| | | ImageHeight int // 摄像机拍摄的图像高 像素 |
| | | RuleResult []Result // 过完规则后打的标签 |
| | | Photo []PhotoMap // yolo算法结构,也可以存人脸的数据,毕竟人脸中能用规则来测的还是那些参数 |
| | | KeepRight bool // 是否靠右行 算法判断的与上一帧图像的比较结果 |
| | | IsStatic bool // 是否静止 |
| | | ImageWidth int // 摄像机拍摄的图像宽 像素 |
| | | ImageHeight int // 摄像机拍摄的图像高 像素 |
| | | RuleResult []Result // 过完规则后打的标签 |
| | | } |
| | | |
| | | // 将传递过来的参数转化为 |
| | |
| | | type Result struct { |
| | | TaskId string // 任务id |
| | | RuleGroupId string // 规则组id |
| | | AlarmLevel string // 报警等级 |
| | | RuleText string // 文字版规则组 |
| | | } |
| | | |
| | | // 包含N条规则元素的一整条规则 |
| | | type CompleteRule struct { |
| | | rule string |
| | | } |
| | | |
| | | // 摄像机区域 跟数据库映射的 |
| | | // type CameraPolygon struct { |
| | | // Id string `json:"id"` |
| | | // CameraId string `json:"camera_id"` |
| | | // Name string `json:"name"` |
| | | // Polygon string `json:"polygon"` // 坐标点区域 |
| | | // TriggerLine string `json:"trigger_line"` |
| | | // DirectionLine string `json:"direction_line"` |
| | | // } |
| | | |
| | | // 根据摄像机id拿到摄像机所有区域 |
| | | func GetPolygons(cameraId string) []protomsg.CameraPolygon { |
| | |
| | | if flag { |
| | | fmt.Println("定时器报警了") |
| | | // 过完规则后打个标签,告诉调用者本帧数据针对哪个任务哪组规则报警了 |
| | | arg.RuleResult = append(arg.RuleResult, Result{TaskId: taskId, RuleGroupId: groupRule.GroupId}) |
| | | arg.RuleResult = append(arg.RuleResult, Result{taskId, groupRule.GroupId,groupRule.AlarmLevel,groupRule.RuleText}) |
| | | return true |
| | | } else { |
| | | return false |
| | |
| | | for i := 0; i < len(ruleList); i++ { |
| | | temp := ruleList[i].Rules // temp为一组完整规则 在此需要判断规则是否是联动规则 |
| | | if len(temp) > 0 { |
| | | if strings.Contains(ruleList[i].GroupId, "link") { // groupId中含有link则为联动任务 |
| | | if strings.Contains(ruleList[i].GroupId, "link") { |
| | | // groupId中含有link则为联动任务 |
| | | linkTask(aml, arg, ruleList[i], taskId) |
| | | } else { // 独立任务的处理 |
| | | } else { |
| | | // 独立任务的处理 |
| | | singleTask(aml, arg, ruleList[i], taskId) |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 过滤规则先筛选人数 |
| | | // 过滤规则先筛选出符合条件的目标数量 |
| | | func filterRule(rule *protomsg.Rule, am *AreaMap) { |
| | | if rule.PolygonId == am.areaId { // 首先规则所对应的区域id要跟区域数据的id对的上 |
| | | if rule.SdkArgAlias == "score" || rule.SdkArgAlias == "proportion" || rule.SdkArgAlias == "size" { // 判断的是相似值,占比,尺寸等过滤条件,如果再有,还可以再加 |
| | |
| | | // 给数据库的规则表达式代参 args: 一条子规则,区域数据 |
| | | func transferParameters(rule *protomsg.Rule, am *AreaMap) string { |
| | | if rule.PolygonId == am.areaId { // 首先规则所对应的区域id要跟区域数据的id对的上 |
| | | if rule.SdkArgAlias == "targetNum" { // 如果参数是要区域内目标数量 |
| | | if rule.SdkArgAlias == "targetNum" { // 如果参数是要区域内目标数量 即yolo |
| | | //fmt.Println("得出结果阶段", "比较的规则是:", rule) |
| | | if rule.Operator == "" { |
| | | return strconv.Itoa(am.targetNum) // 如果后面不跟操作符就直接返回数量 比如要跟下一个区域比较数量的就直接返回本区域的数量 |
| | |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | return strconv.FormatBool(result.(bool)) |
| | | // 加上关于算法的判断条件,不能只有关于规则的,有的算法本身就是一个规则,如个体静止,靠右行,所以,拿到当前子规则的sdkid来判断是否是那些特殊的规则 |
| | | } else if rule.SdkId == "个体静止" { // 暂时用汉字代替啦,晚些替换成正式的id |
| | | } else if rule.SdkId == "IsStatic" { // 静止算法 |
| | | if am.isStatic { |
| | | return "true" |
| | | } else { |
| | | return "false" |
| | | } |
| | | } else if rule.SdkId == "靠右行" { // 暂时用汉字代替啦,晚些替换成正式的id |
| | | } else if rule.SdkId == "KeepRight" { // 靠右行算法 |
| | | if am.keepRight { |
| | | return "true" |
| | | } else { |
| | | return "false" |
| | | } |
| | | } else if rule.SdkId == "FaceDetect" { // 人脸检测 |
| | | if rule.Operator == "==" || rule.Operator == ">=" || rule.Operator == "<=" || rule.Operator == "<" || rule.Operator == ">" || rule.Operator == "!=" { |
| | | // 如果是不规矩的连接符统统返回false 规则也只能判断人脸的相似度,所以不存在别的连接符 |
| | | return "false" |
| | | } else { |
| | | return "false" |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | // return stopChan |
| | | // } |
| | | |
| | | // 结构体根据某字段排序 |
| | | type SubList []*RuleResult |
| | | |
| | | func (p SubList) Swap(i, j int) { p[i], p[j] = p[j], p[i] } |
New file |
| | |
| | | package util |
| | | |
| | | import ( |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io" |
| | | "log" |
| | | "mime/multipart" |
| | | "net/http" |
| | | "time" |
| | | ) |
| | | var weedfsUri = "http://192.168.1.182:9500/submit" |
| | | func PostFormData(uri string, filename, paramName string, file multipart.File) (maps map[string]interface{}, err0 error) { |
| | | body := &bytes.Buffer{} |
| | | writer := multipart.NewWriter(body) |
| | | _, err := writer.CreateFormFile(paramName, filename) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | boundary := writer.Boundary() |
| | | //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary) |
| | | close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary)) |
| | | request_reader := io.MultiReader(body, file, close_buf) |
| | | //_, err = io.Copy(part, file) |
| | | //writer.WriteField(key, val) |
| | | request, err := http.NewRequest("POST", uri, request_reader) |
| | | request.Header.Add("Content-Type", writer.FormDataContentType()) |
| | | timeout := time.Duration(5 * time.Second) //超时时间50ms |
| | | client := &http.Client{Timeout: timeout} |
| | | resp, err := client.Do(request) |
| | | if err != nil { |
| | | log.Fatal(err) |
| | | return nil, err |
| | | } |
| | | defer func() { |
| | | if r := recover(); r != nil { |
| | | fmt.Printf("panic的内容%v\n", r) |
| | | msg := "上传图片服务器异常" |
| | | if _, ok := r.(error); ok { |
| | | msg = r.(error).Error() |
| | | fmt.Println("panic--recover()得到的是error类型") |
| | | } |
| | | if _, ok := r.(string); ok { |
| | | msg = r.(string) |
| | | fmt.Println("panic--recover()得到的是string类型") |
| | | } |
| | | err0 = errors.New(msg) |
| | | } |
| | | }() |
| | | defer resp.Body.Close() |
| | | body = &bytes.Buffer{} |
| | | _, err = body.ReadFrom(resp.Body) |
| | | if err != nil { |
| | | log.Fatal(err) |
| | | } |
| | | fmt.Println(resp.StatusCode) |
| | | //fmt.Println(body) |
| | | //decoder := json.NewDecoder(strings.NewReader(body.String())) |
| | | decoder := make(map[string]interface{}) |
| | | if err := json.Unmarshal([]byte(body.String()), &decoder); err != nil { |
| | | return nil, err |
| | | } |
| | | return decoder, nil |
| | | } |