From 09a9fede090bec95c3083c8b29d0632dbc0d6245 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期四, 07 十一月 2019 17:24:23 +0800 Subject: [PATCH] 单协程 --- ruleserver/readyDataForRule.go | 115 ++++++++++++++++++++++++++------------------------------- 1 files changed, 53 insertions(+), 62 deletions(-) diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go index e4430c7..07ff10a 100644 --- a/ruleserver/readyDataForRule.go +++ b/ruleserver/readyDataForRule.go @@ -2,14 +2,11 @@ import ( "basic.com/dbapi.git" - bigCache "basic.com/pubsub/cache.git" "basic.com/pubsub/protomsg.git" "encoding/json" "errors" "fmt" - "github.com/go-yaml/yaml" "github.com/golang/protobuf/proto" - "io/ioutil" "math" "nanomsg.org/go-mangos" "nanomsg.org/go-mangos/protocol/req" @@ -17,6 +14,7 @@ "net" "ruleprocess/cache" "ruleprocess/logger" + "ruleprocess/structure" "strconv" "time" ) @@ -33,24 +31,8 @@ } func Init() { - data, err := ioutil.ReadFile("./config/conf.yml") - if err != nil { - fmt.Println("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err) - logger.Error("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err) - } - c := conf{} - //鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷 - yaml.Unmarshal(data, &c) - logger.Debug("閰嶇疆鏂囦欢鐨勫�间负锛�", c) - serverIp = c.ServerIp - serverPort = c.ServerPort - dbTablePersons = c.DbTablePersons - localConfig, err1 := cache.GetServerInfo() - if err1 != nil { - logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�") - } - logger.Debug("鏈満淇℃伅鍜宻erver淇℃伅锛�", localConfig, serverIp, serverPort) - bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId) + //logger.Debug("鏈満淇℃伅鍜宻erver淇℃伅锛�", localConfig, serverIp, serverPort) + //bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId) go Push1() } @@ -81,11 +63,15 @@ taskGroup = task } } - logger.Debug("褰撳墠鏁版嵁甯ц鍖归厤鐨勮鍒欑粍锛�-------------------------","鎽勫儚鏈篿d:",cameraId,"浠诲姟id",taskId) - for _,ruleGroup := range taskGroup.GroupRules{ - logger.Info(ruleGroup.GroupText) + //logger.Debug("褰撳墠鏁版嵁甯ц鍖归厤鐨勮鍒欑粍锛�-------------------------","鎽勫儚鏈篿d:",cameraId,"浠诲姟id",taskId) + if taskGroup == nil { + return nil + } else { + for _,ruleGroup := range taskGroup.GroupRules{ + logger.Info(ruleGroup.GroupText) + } + return taskGroup } - return taskGroup } // 鏍规嵁鎽勫儚鏈篿d鎷垮埌鎽勫儚鏈烘墍鏈夊尯鍩� @@ -103,10 +89,10 @@ } func Decimal(value float32) float64 { value1, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", float64(value)), 64) - logger.Info("鍒濇淇濈暀涓や綅鎴恠tr:",value1) + //logger.Info("鍒濇淇濈暀涓や綅鎴恠tr:",value1) n10 := math.Pow10(4) value2 := math.Trunc((value1+0.5/n10)*n10) / n10 - logger.Info("鍒濇淇濈暀涓や綅鎴恠tr::::",value2) + //logger.Info("鍒濇淇濈暀涓や綅鎴恠tr::::",value2) return value2 } // 鍙栧嚭鏌愪釜鏃堕棿瑙勫垯鐨勭鍑犲ぉ鐨勮鍒欐闆嗗悎 @@ -166,7 +152,7 @@ } // 缁欑洰鏍囧~鍏卨iker -func (arg *Arg) fillLiker(tableId []string, compareThreshold float32) { +func fillLiker(tableId []string, compareThreshold float32,arg *structure.Arg) { //bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold) comArg := &protomsg.CompareArgs{ TableIds:tableId, @@ -211,7 +197,7 @@ logger.Error("鏍规嵁id鏌ヨ搴曞簱淇℃伅鍑洪敊锛�", err, "--杩斿洖鍊奸暱搴︿负锛�", len(table)) } logger.Debug("鐪嬬湅杩欎釜base鐨勫姣斿�兼槸澶氬皯锛�", Decimal(m[baseinfo.Id].CompareScore)) - base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved} + base := structure.BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved} //os.Exit(1) arg.Liker = append(arg.Liker, &base) } @@ -220,7 +206,7 @@ } // 浜鸿劯姣斿 -func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) { +func Compare(args *structure.SdkDatas, groupRule *protomsg.GroupRule) { compareFlag := 0 var tableIds []string var threshold float32 = 50 // 榛樿闃堝�间负50 @@ -234,7 +220,7 @@ if groupRule.Rules[j].SdkArgAlias == "compareBase" && groupRule.Rules[j].SdkArgValue == "" { // 閰嶇殑鍙傛暟鏄瘮瀵瑰叏閮ㄥ簳搴� compareFlag = 1 } - if groupRule.Rules[j].SdkArgAlias == "threshold" { + if groupRule.Rules[j].SdkArgAlias == "cmpThreshold" { v2, err := strconv.ParseFloat(groupRule.Rules[j].SdkArgValue, 32) if err != nil { logger.Error("string杞琭loat32澶辫触锛�") @@ -257,27 +243,27 @@ logger.Info("============================================杩涜浜鸿劯瀵规瘮") for _, areaMap := range sdkData.AreaMapList { // 鎷垮尯鍩熶腑姣忎釜浜鸿劯鐗瑰緛鍊煎幓瀵规瘮锛屽~鍏呭叾liker - if groupRule.Rules[j].PolygonId == areaMap.areaId { + if groupRule.Rules[j].PolygonId == areaMap.AreaId { //logger.Info("--------------鐪嬬湅compareFlag鐨勫�煎拰tableId鍜宎reaMap.args鐨勯暱搴︼細",compareFlag,tableIds,len(areaMap.args)) - for _, arg := range areaMap.args { + for _, arg := range areaMap.Args { arg.Liker = arg.Liker[0:0] - logger.Info("娓呯┖涔嬪悗鐪嬬湅涔嬪墠鎵撶殑浜鸿劯鏍囩鍙樹簡娌★細") - if args.RuleResult["face"] != nil && len(args.RuleResult["face"].([]FaceResult)) > 0 { - for _, faceResult := range args.RuleResult["face"].([]FaceResult) { - for _,arg := range faceResult.Args { - logger.Info("浜哄憳鍒嗗�兼槸锛�",arg.Score,"liker鐨勬暟閲忎负",arg.Liker) - } - } - } + //logger.Info("娓呯┖涔嬪悗鐪嬬湅涔嬪墠鎵撶殑浜鸿劯鏍囩鍙樹簡娌★細") + //if args.RuleResult["face"] != nil && len(args.RuleResult["face"].([]FaceResult)) > 0 { + // for _, faceResult := range args.RuleResult["face"].([]FaceResult) { + // for _,arg := range faceResult.Args { + // logger.Info("浜哄憳鍒嗗�兼槸锛�",arg.Score,"liker鐨勬暟閲忎负",arg.Liker) + // } + // } + //} if compareFlag == 1 { - arg.fillLiker(nil, threshold) + fillLiker(nil, threshold, arg) } if compareFlag == 2 { - arg.fillLiker(tableIds, threshold) + fillLiker(tableIds, threshold, arg) } //logger.Info("-------------------鎴愬姛缁檒iker璧嬪��,闀垮害涓猴細", len(arg.Liker)) } - areaMap.filterData = areaMap.args + areaMap.FilterData = areaMap.Args //logger.Info("=======绗竴娆$湅args锛�",(areaMap.filterData)) } //logger.Info("-------------------------------浜鸿劯瀵规瘮涔嬪悗鐨勭洰鏍囨暟閲�",len(areaMap.args)) @@ -290,45 +276,49 @@ } // 璁$畻鍖哄煙鍐呯殑鐩爣鏁伴噺浠ュ強灏嗙浉浼煎害銆佸崰姣斻�佸昂瀵哥瓑鎵撳寘 -func (a *AreaMap) CountAreaObjs(arg *SdkData) { +func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) { - a.targetNum = 0 - threshold := 0.0 // 鐩镐技搴� + a.TargetNum = 0 + threshold := 80.0 // 鐩镐技搴� intersectionper := 0.2 // 鍗犳瘮 size := 0.0 // 灏哄 - areaPoints := Json2points(a.areaJson) - widthScale := float64(arg.ImageWidth / 960) - heigthScale := float64(arg.ImageHeight / 540) + areaPoints := Json2points(a.AreaJson) + logger.Info("鐪嬬湅鍥剧墖鐨剋idth鍜宧eight:",arg.ImageWidth,arg.ImageHeight) + widthScale := float64(arg.ImageWidth) / 960 + heigthScale := float64(arg.ImageHeight) / 540 for _, obj := range arg.Photo { //logger.Info("------------------鐪嬬湅sdkData:", arg.SdkName, "鐨凱hoto鏁版嵁----------------", obj, "----椤轰究鐪嬬湅鍗犳瘮-----锛�", PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale)) - if threshold <= obj.Score && size <= float64(obj.Rects.Width*obj.Rects.Height) && intersectionper <= PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) { + if obj.Score >= threshold && float64(obj.Rects.Width*obj.Rects.Height) >= size && PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) >= intersectionper { // 杩欐瑕佸榻愯〃杈惧紡閲屾墍闇�瑕佺殑鎵�鏈夊弬鏁� - a.targetNum++ - arg1 := Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*BaseInfo{}} + a.TargetNum++ + arg1 := structure.Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*structure.BaseInfo{}} //logger.Println("鏀捐繘鍘荤殑arg锛�-------", arg1) - a.args = append(a.args, &arg1) - a.filterData = append(a.filterData, &arg1) + a.Args = append(a.Args, &arg1) + a.FilterData = append(a.FilterData, &arg1) } } - logger.Info("鍖哄煙鏄細",areaPoints,"鍖哄煙鍐呯洰鏍囨暟閲忎负锛�",a.targetNum,"---",len(a.filterData)) - a.time = time.Unix(time.Now().Unix(), 0).String()[11:16] - a.keepRight = arg.KeepRight - a.isStatic = arg.IsStatic + logger.Info("鍖哄煙鏄細",areaPoints,"鍖哄煙鍐呯洰鏍囨暟閲忎负锛�",a.TargetNum,"---",len(a.FilterData)) + //for _,tar := range a.FilterData { + // logger.Info("鍏蜂綋鐩爣鐨勫潗鏍囦负",tar.Id,tar.Location) + //} + a.Time = time.Unix(time.Now().Unix(), 0).String()[11:16] + a.KeepRight = arg.KeepRight + a.IsStatic = arg.IsStatic //logger.Println("--------------------鐪嬬湅鍖哄煙鏁版嵁锛�",*a) } // 鎶妔dk浠庢暟鎹抚涓婃彁鍙栫殑鎸夌収鍖哄煙鍒嗙被褰掔疆 -func SdkDataFormat(cameraId string, arg *SdkData, cameraPolygons []protomsg.CameraPolygon) { +func SdkDataFormat(cameraId string, arg *structure.SdkData, cameraPolygons []protomsg.CameraPolygon) { logger.Info("==================================鏈瑂dkData涓В鍑烘潵鐨勭洰鏍囨暟鎹�=======================================") for _, photo := range arg.Photo { logger.Info("--------瑙f瀽鍑烘潵鐨勬暟鎹�---", cameraId, arg.IpcId, photo.Rects, photo.Score) } for _, polygon := range cameraPolygons { //logger.Println("++++++鍦ㄨ繖鍎跨湅涓�涓嬪尯鍩熷晩:", polygon.Polygon) - areaMap := AreaMap{cameraId: cameraId, areaId: polygon.Id, areaJson: polygon.Polygon, triggerLine: polygon.TriggerLine, directionLine: polygon.DirectionLine} + areaMap := structure.AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine} // 涓烘瘡涓憚鍍忔満鍖哄煙濉厖鏁版嵁 - areaMap.CountAreaObjs(arg) + CountAreaObjs(&areaMap,arg) arg.AreaMapList = append(arg.AreaMapList, &areaMap) } } @@ -399,6 +389,7 @@ // case <-ctx.Done(): // return case data := <- sender: + logger.Info("姣斿杩涚▼鍏ュ弬锛�",data.TableIds,data.CompareThreshold) bytes,err1 := proto.Marshal(data) logger.Info("鏁版嵁闀垮害涓猴細",len(bytes)) if err1 != nil { -- Gitblit v1.8.0