From 5d17d528ded3c828f7f79ae57ec72429de6dd1c9 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期三, 13 十一月 2019 16:56:37 +0800
Subject: [PATCH] 去掉link
---
ruleserver/readyDataForRule.go | 82 ++++++++++++++++++----------------------
1 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go
index 445fd6f..b0fcee6 100644
--- a/ruleserver/readyDataForRule.go
+++ b/ruleserver/readyDataForRule.go
@@ -3,17 +3,19 @@
import (
"basic.com/dbapi.git"
"basic.com/pubsub/protomsg.git"
+ "basic.com/valib/logger.git"
"encoding/json"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
+ uuid "github.com/satori/go.uuid"
"math"
"nanomsg.org/go-mangos"
"nanomsg.org/go-mangos/protocol/req"
"nanomsg.org/go-mangos/transport/tcp"
"net"
"ruleprocess/cache"
- "ruleprocess/logger"
+ "ruleprocess/structure"
"strconv"
"time"
)
@@ -30,8 +32,6 @@
}
func Init() {
- //logger.Debug("鏈満淇℃伅鍜宻erver淇℃伅锛�", localConfig, serverIp, serverPort)
- //bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
go Push1()
}
@@ -62,7 +62,6 @@
taskGroup = task
}
}
- logger.Debug("褰撳墠鏁版嵁甯ц鍖归厤鐨勮鍒欑粍锛�-------------------------","鎽勫儚鏈篿d:",cameraId,"浠诲姟id",taskId)
if taskGroup == nil {
return nil
} else {
@@ -77,7 +76,7 @@
func GetPolygons(cameraId string) []protomsg.CameraPolygon {
var cameraPolygons []protomsg.CameraPolygon
cameraPolygons = cache.GetPolygonsByCameraId(cameraId)
- logger.Debug("------=======鏌ョ湅涓嬪叏閮ㄥ尯鍩燂細",cameraPolygons)
+ //logger.Debug("------=======鏌ョ湅涓嬪叏閮ㄥ尯鍩燂細",cameraPolygons)
return cameraPolygons
}
@@ -88,16 +87,16 @@
}
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
}
// 鍙栧嚭鏌愪釜鏃堕棿瑙勫垯鐨勭鍑犲ぉ鐨勮鍒欐闆嗗悎
-func GetTimeById(id string, index int) []TimeRange {
+func GetTimeById(id string, index int) []structure.TimeRange {
_, cameraTimeRule := cache.GetTimeRuleById(id)
- var timeRangeList []day
+ var timeRangeList []structure.Day
err := json.Unmarshal([]byte(cameraTimeRule.TimeRule), &timeRangeList)
if err != nil {
logger.Error("鍙栨椂闂磋鍒欐椂鍙嶅簭鍒楀寲閿欒锛�")
@@ -122,14 +121,7 @@
return 0
}
-type TimeRange struct {
- Start string `json:"start"`
- End string `json:"end"`
-}
-type day struct {
- Day int `json:"day"` // 鏍囩ず褰撳墠鏄熸湡鍑�
- TimeRange []TimeRange `json:"time_range"` // 褰撳ぉ鐨勫嚑涓椂闂存
-}
+
// 灏嗗瓧绗︿覆鏍煎紡鐨勫潗鏍囧簭鍒楀寲涓篜oint鏍煎紡
func Json2points(areaPoints string) []Point {
@@ -151,7 +143,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,
@@ -161,7 +153,6 @@
}
bytes := getCompareMsg(comArg)
- //bytes := []byte{}
var scResult protomsg.SdkCompareResult
err1 := proto.Unmarshal(bytes, &scResult)
if err1 != nil {
@@ -196,7 +187,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)
}
@@ -205,7 +196,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
@@ -219,7 +210,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澶辫触锛�")
@@ -242,9 +233,9 @@
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 {
@@ -255,14 +246,14 @@
// }
//}
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))
@@ -275,45 +266,47 @@
}
// 璁$畻鍖哄煙鍐呯殑鐩爣鏁伴噺浠ュ強灏嗙浉浼煎害銆佸崰姣斻�佸昂瀵哥瓑鎵撳寘
-func (a *AreaMap) CountAreaObjs(arg *SdkData) {
+func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) {
- a.targetNum = 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++
+ uuid := uuid.NewV4().String()
+ arg1 := structure.Arg{obj.Id,uuid,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))
+ 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)
}
}
@@ -357,7 +350,6 @@
logger.Debug("鏁版嵁鎺ㄩ�佹垚鍔燂紒鏀跺埌鍝嶅簲,鏁版嵁闀垮害涓猴細",len(msg))
return msg
}
-
func Push1(){
//var sock mangos.Socket
--
Gitblit v1.8.0