Merge branch 'master' of http://192.168.1.14:10010/r/ruleprocess
| | |
| | | // 不是报警数据不存 |
| | | return |
| | | } |
| | | log.Println("图片上传返回值:", resp) |
| | | // log.Println("图片上传返回值:", resp) |
| | | // 查询本机信息 |
| | | flag, localConfig := dbapi.SysSetApi{}.GetServerInfo() |
| | | if !flag { |
| | |
| | | } |
| | | err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody) |
| | | if err != nil { |
| | | log.Println("es can not execute right.") |
| | | log.Println("往ES插入数据失败",err) |
| | | } else { |
| | | log.Println("__________________________________________往ES插入数据成功") |
| | | } |
| | | } |
| | | } |
| | |
| | | arg.IsStatic = false |
| | | if len(sdkinfo.Sdkdata) > 1 { |
| | | // 大于1才有数据 |
| | | fmt.Println("----------------------------------------------------",m.Cid) |
| | | yoloParam := protomsg.ParamYoloObj{} |
| | | err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) |
| | | if err != nil { |
| | |
| | | if completeFormula != "" { |
| | | log.Println("看看公式-----------:", completeFormula) |
| | | expression, _ := govaluate.NewEvaluableExpression(completeFormula) |
| | | result, err := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | if err != nil { |
| | | panic("得到的数学公式不可解析") |
| | | if strings.HasPrefix(completeFormula,"&&") || strings.HasPrefix(completeFormula,"||"){ |
| | | panic("规则有误,得到的数学公式不可解析") |
| | | } |
| | | if result.(bool) { |
| | | result,_ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | if !result.(bool) { |
| | | // 给这帧数据打上规则组标签 |
| | | //args.RuleResult = append(args.RuleResult, Result{TaskId: taskId, RuleGroupId: groupRule.GroupId}) |
| | | for k, timeEle := range TimeEleList { |
| | |
| | | for k, timeEle := range TimeEleList { |
| | | if strings.Contains(k, taskId) { |
| | | if timeEle.N != 0 { // 跟这个任务有关的定时器要全部等于0 |
| | | log.Println("———————————-------------不冤,你是被定时器打败的:") |
| | | flag = false |
| | | } |
| | | } |
| | |
| | | func filterRule(rule *protomsg.Rule, am *AreaMap) LittleRuleResult { |
| | | if rule.SdkId == "FaceDetect" || rule.SdkId == "FaceCompare" { |
| | | // 处理的是人脸算法 如果这条规则配置的是人脸算法,过滤完条件之后直接得出结果,因为肯定没有数量条件,自己拼接 |
| | | log.Println("------------------------------------------还能进这儿了不成???") |
| | | if rule.SdkId == am.sdkId && rule.PolygonId == am.areaId { // 算法和区域都得对的上 |
| | | |
| | | if rule.SdkId == "FaceCompare" { |
| | |
| | | var formula string |
| | | if rule.SdkArgAlias == "score" { |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | log.Println("当前相似度小公式:",formula) |
| | | } else if rule.SdkArgAlias == "proportion" { |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | log.Println("当前占比小公式:",formula) |
| | | } else { |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | log.Println("当前尺寸小公式:",formula) |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | now := time.Now() |
| | | index := getIndexOfWeek(now.Weekday().String()) |
| | | timeList := GetTimeById(rule.SdkArgValue, index) |
| | | log.Println("当天的时间规则:----------",timeList) |
| | | //fmt.Println("从数据库中查出的时间规则:", timeList) |
| | | // 判断图片数据的时间是否符合当前规则 在一个即为true,全不在为false |
| | | flag := "false" |
| | | for _, timeSlot := range timeList { |
| | | if rule.Operator == "satisfy" { // 满足所选的时间规则 |
| | | if rule.Operator == "satisfy" || rule.Operator == "=="{ // 满足所选的时间规则 |
| | | formula := "'" + timeSlot.Start + "'" + "<" + "'" + am.time + "'" |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | break |
| | | } |
| | | } |
| | | if rule.Operator == "unsatisfy" { // 不满足所选的时间规则 |
| | | if rule.Operator == "unsatisfy" || rule.Operator == "!="{ // 不满足所选的时间规则 |
| | | formula := timeSlot.Start + "<" + am.time |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | for _, timeEle := range TimeEleList { |
| | | if timeEle.N > 0 { |
| | | timeEle.N = timeEle.N - 1 |
| | | log.Println("打印定时器元素当前值:",timeEle.N) |
| | | log.Println("-------------------------------------打印定时器元素当前值-----------------------------------------:",timeEle.N) |
| | | } |
| | | } |
| | | case stop := <-stopChan: |
| | |
| | | import ( |
| | | "bufio" |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "image/color" |
| | | "io" |
| | | "log" |
| | | "mime/multipart" |
| | | "net/http" |
| | | "os" |
| | | "time" |
| | | |
| | | "gocv.io/x/gocv" |
| | | ) |
| | | |
| | | func CvRTSP() { |
| | |
| | | // draw the rook |
| | | //rook := gocv.NewMatWithSize(w, w, gocv.MatTypeCV8UC3) |
| | | //imgs := gocv.NewMat() |
| | | ddd, err := RetrieveROM("/home/user/workspace/ruleprocess/util/l05.jpg") |
| | | ddd, err := RetrieveROM("/home/user/workspace/ruleprocess/util/105.jpg") |
| | | if err != nil { |
| | | fmt.Println("解码有误",err) |
| | | } |
| | | bbb := bytes.NewBuffer(ddd) // 必须加一个buffer 不然没有read方法就会报错 |
| | | |
| | | |
| | | |
| | | |
| | | rook, _ := gocv.NewMatFromBytes(500, 500, gocv.MatTypeCV8UC3, bbb.Bytes()) |
| | | defer rook.Close() |
| | | green := color.RGBA{0, 255, 0, 0} |
| | |
| | | }, |
| | | } |
| | | gocv.FillPoly(&rook, points, green) |
| | | |
| | | return nil,nil |
| | | // 上传 |
| | | fdata,_ := gocv.IMEncode(".jpg",rook) |
| | | body := &bytes.Buffer{} |
| | | writer := multipart.NewWriter(body) |
| | | _, err1 := writer.CreateFormFile("file", "fasjuierf") |
| | | if err1 != nil { |
| | | return nil, err1 |
| | | } |
| | | 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)) |
| | | file := bytes.NewBuffer(fdata) |
| | | request_reader := io.MultiReader(body, file, close_buf) |
| | | //_, err = io.Copy(part, file) |
| | | //writer.WriteField(key, val) |
| | | request, err := http.NewRequest("POST", "http://192.168.1.182:6333/submit", 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(resp.Header) |
| | | 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 |
| | | } |
| | | //fdata,_ := gocv.IMEncode(".jpg",rook) |
| | | //body := &bytes.Buffer{} |
| | | //writer := multipart.NewWriter(body) |
| | | //_, err1 := writer.CreateFormFile("file", "fasjuierf") |
| | | //if err1 != nil { |
| | | // return nil, err1 |
| | | //} |
| | | //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)) |
| | | //file := bytes.NewBuffer(fdata) |
| | | //request_reader := io.MultiReader(body, file, close_buf) |
| | | ////_, err = io.Copy(part, file) |
| | | ////writer.WriteField(key, val) |
| | | //request, err := http.NewRequest("POST", "http://192.168.1.182:6333/submit", 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(resp.Header) |
| | | // 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 |
| | | //} |
| | | } |
| | | |
| | | // 把图片转成二进制流 |
| | |
| | | "testing" |
| | | ) |
| | | |
| | | func TestDrawPolygon(t *testing.T) { |
| | | func TestDrawPolygonOnImage(t *testing.T) { |
| | | resp,err := DrawPolygonOnImage() |
| | | if err != nil { |
| | | t.Error("画框或者上传有问题") |
| | | } |
| | | t.Log(resp["fileUrl"].(string)) |
| | | t.Log("------=============",resp) |
| | | } |