From 5312ebfc1a3dce594e3fe100743652de0634f9c1 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期一, 28 十月 2019 14:39:56 +0800
Subject: [PATCH] 用contain方法通过判断并修正绘图比例
---
util/simpleCV.go | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/util/simpleCV.go b/util/simpleCV.go
index e17796d..68200f3 100644
--- a/util/simpleCV.go
+++ b/util/simpleCV.go
@@ -164,7 +164,8 @@
yellow := color.RGBA{255, 255, 0, 0}
red := color.RGBA{255, 0, 0, 0}
-
+ scale := img.Width / 960 // 鐢诲浘姣斾緥
+ logger.Info("width:",img.Width,"--鐢诲浘姣斾緥锛�",scale)
// 鍒嗗壊鍖哄煙id闆嗗悎骞舵牴鎹甶d鏌ヨ鍖哄煙鐒跺悗鐢绘
for _,result := range results {
polygonIds := strings.Split(result.AlarmPolygon,",")
@@ -173,7 +174,7 @@
polygon := getPolygonById(polygonIds[i],cameraId)
if polygon.Polygon != "[]" && polygon.Polygon != ""{
logger.Debug("鎵�鐢诲尯鍩燂細",polygon.Polygon)
- DrawAPolygon(&rook,polygon.Polygon,yellow)
+ DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
}
}
}
@@ -195,7 +196,7 @@
defer rook.Close()
yellow := color.RGBA{255, 255, 0, 0}
-
+ scale := img.Width / 960 // 鐢诲浘姣斾緥
// 鍒嗗壊鍖哄煙id闆嗗悎骞舵牴鎹甶d鏌ヨ鍖哄煙鐒跺悗鐢绘
for _,result := range results {
polygonIds := strings.Split(result.AlarmPolygon,",")
@@ -205,7 +206,7 @@
logger.Info("----鏌ュ埌鐨勬姤璀︽锛�",polygon)
if polygon.Polygon != "[]" && polygon.Polygon != ""{
logger.Debug("鎵�鐢诲尯鍩燂細",polygon.Polygon)
- DrawAPolygon(&rook,polygon.Polygon,yellow)
+ DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
}
}
}
@@ -252,13 +253,14 @@
return protomsg.CameraPolygon{}
}
// 鍦ㄥ浘涓婄敾涓�涓
-func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA) {
+func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA,scale int32) {
points := ruleserver.Json2points(polygonString)
+ logger.Info("int32杞负float64锛�",float64(scale))
for index := 0; index < len(points); index++ {
if index == len(points)-1 { // 闂悎鍥惧舰
- gocv.Line(rook, image.Pt(int(points[index].X*1.33), int(points[index].Y*1.33)), image.Pt(int(points[0].X*1.33), int(points[0].Y*1.33)), color, 2)
+ gocv.Line(rook, image.Pt(int(points[index].X * float64(scale)), int(points[index].Y * float64(scale))), image.Pt(int(points[0].X * float64(scale)), int(points[0].Y * float64(scale))), color, 2)
} else {
- gocv.Line(rook, image.Pt(int(points[index].X*1.33), int(points[index].Y*1.33)), image.Pt(int(points[index+1].X*1.33), int(points[index+1].Y*1.33)), color, 2)
+ gocv.Line(rook, image.Pt(int(points[index].X * float64(scale)), int(points[index].Y * float64(scale))), image.Pt(int(points[index+1].X * float64(scale)), int(points[index+1].Y * float64(scale))), color, 2)
}
}
}
--
Gitblit v1.8.0