From 2c3aa09cf18bf6798a38f0334ce45d864135621e Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期三, 06 十一月 2019 16:18:36 +0800 Subject: [PATCH] 绘图比例float int问题 --- ruleserver/geoPolygon_test.go | 38 ++++++++++++++++++++++++++++++++++++++ ruleserver/readyDataForRule.go | 6 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ruleserver/geoPolygon_test.go b/ruleserver/geoPolygon_test.go new file mode 100644 index 0000000..7f6c9ee --- /dev/null +++ b/ruleserver/geoPolygon_test.go @@ -0,0 +1,38 @@ +package ruleserver + +import ( + "basic.com/valib/logger.git" + "encoding/json" + "fmt" + "ruleprocess/structure" + + "testing" +) + +func TestPgsInterPercent(t *testing.T) { + areaPoints := json2points("[{\"x\":582,\"y\":11},{\"x\":582,\"y\":525},{\"x\":943,\"y\":525},{\"x\":943,\"y\":11}]") + widthScale := float64(2688) / 960 + heigthScale := float64(1520) / 540 + rec := structure.Rect{1333, 594,204,274} + per := PgsInterPercent(areaPoints,rec,widthScale,heigthScale) + fmt.Println(widthScale,heigthScale,per) +} + +// 灏嗗瓧绗︿覆鏍煎紡鐨勫潗鏍囧簭鍒楀寲涓篜oint鏍煎紡 +func json2points(areaPoints string) []Point { + var pts []Point + if areaPoints == "[]" || areaPoints == "" { + logger.Error("=====================姝ゅ尯鍩熶负鍏ㄩ儴鍖哄煙") + pts = append(pts, Point{0, 0}) + pts = append(pts, Point{0, 540}) + pts = append(pts, Point{960, 540}) + pts = append(pts, Point{960, 0}) + } else { + err := json.Unmarshal([]byte(areaPoints), &pts) + if err != nil { + logger.Error("json.Unmarshal閿欒", err) + panic("搴忓垪鍖栧潗鏍囧紓甯革紝绋嬪簭閫�鍑�") + } + } + return pts +} \ No newline at end of file diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go index 15f781f..4ac8b2c 100644 --- a/ruleserver/readyDataForRule.go +++ b/ruleserver/readyDataForRule.go @@ -285,11 +285,11 @@ areaPoints := Json2points(a.AreaJson) logger.Info("鐪嬬湅鍥剧墖鐨剋idth鍜宧eight:",arg.ImageWidth,arg.ImageHeight) - widthScale := float64(arg.ImageWidth / 960) - heigthScale := float64(arg.ImageHeight / 540) + 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 := 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{}} -- Gitblit v1.8.0