From 2068b720a0f23bdf46e723d25312545c74f6d736 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期二, 19 十一月 2019 11:27:27 +0800
Subject: [PATCH] ---
---
util/simpleCV.go | 89 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 72 insertions(+), 17 deletions(-)
diff --git a/util/simpleCV.go b/util/simpleCV.go
index 7e3b87c..32bcdef 100644
--- a/util/simpleCV.go
+++ b/util/simpleCV.go
@@ -9,8 +9,9 @@
"image/color"
"os"
"ruleprocess/cache"
- "ruleprocess/logger"
+ "basic.com/valib/logger.git"
"ruleprocess/ruleserver"
+ "ruleprocess/structure"
"strings"
)
@@ -154,35 +155,89 @@
}
}
}
-
-func DrawPolygonOnImage(cameraId string, img protomsg.Image, results []ruleserver.Result) (maps map[string]interface{}, err0 error) {
+func DrawPolygonOnImageForYolo(cameraId string, img protomsg.Image, results []structure.Result,url string) (maps map[string]interface{}, err0 error) {
rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data)
//rook := gocv.IMRead("/home/user/workspace/ruleprocess/util/105.jpg",gocv.IMReadColor)
defer rook.Close()
+ yellow := color.RGBA{255, 255, 0, 0}
red := color.RGBA{255, 0, 0, 0}
- green := color.RGBA{0, 255, 0, 0}
-
+ scale := float64(img.Width) / 960 // 鐢诲浘姣斾緥
+ logger.Info("width:",img.Width,"--鐢诲浘姣斾緥锛�",scale)
// 鍒嗗壊鍖哄煙id闆嗗悎骞舵牴鎹甶d鏌ヨ鍖哄煙鐒跺悗鐢绘
for _,result := range results {
- polygonIds := strings.Split(result.AlarmPolygon,"")
- for i := 0; i < len(polygonIds)-1; i++ {
+ polygonIds := strings.Split(result.AlarmPolygon,",")
+ logger.Info("鍖哄煙ID锛�",result.AlarmPolygon,polygonIds)
+ for i := 0; i < len(polygonIds); i++ {
polygon := getPolygonById(polygonIds[i],cameraId)
- logger.Info("------------------------鐬呯瀰鏍规嵁id鎹″嚭鏉ュ尯鍩熷��",polygon.Polygon)
- if polygon.Polygon != "" {
- DrawAPolygon(&rook,polygon.Polygon,red)
+ if polygon.Polygon != "[]" && polygon.Polygon != ""{
+ DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
}
}
}
// 鎶婄洰鏍囨鍑烘潵
for _,result := range results {
- for _,rect := range result.Location {
- gocv.Rectangle(&rook, image.Rect(int(rect.X), int(rect.Y), int(rect.X+rect.Width), int(rect.Y+rect.Height)), green, 1)
+ for _,rect := range result.AlarmObj {
+ gocv.Rectangle(&rook, image.Rect(int(rect.Location.X), int(rect.Location.Y), int(rect.Location.X+rect.Location.Width), int(rect.Location.Y+rect.Location.Height)), red, 1)
}
}
//return nil,nil
- maps,err0 = UploadFromMat(rook)
+ maps,err0 = UploadFromMat(url,rook)
+ return
+}
+
+func DrawPolygonOnImageForTarget(cameraId string, img protomsg.Image, results []structure.Result,url string) (maps map[string]interface{}, err0 error) {
+
+ rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data)
+ //rook := gocv.IMRead("/home/user/workspace/ruleprocess/util/105.jpg",gocv.IMReadColor)
+ defer rook.Close()
+
+ yellow := color.RGBA{255, 255, 0, 0}
+ red := color.RGBA{255, 0, 0, 0}
+ scale := float64(img.Width) / 960 // 鐢诲浘姣斾緥
+ logger.Info("width:",img.Width,"--鐢诲浘姣斾緥锛�",scale)
+ // 鍒嗗壊鍖哄煙id闆嗗悎骞舵牴鎹甶d鏌ヨ鍖哄煙鐒跺悗鐢绘
+ for _,result := range results {
+ polygonIds := strings.Split(result.AlarmPolygon,",")
+ logger.Info("鍖哄煙ID锛�",result.AlarmPolygon,polygonIds)
+ for i := 0; i < len(polygonIds); i++ {
+ polygon := getPolygonById(polygonIds[i],cameraId)
+ if polygon.Polygon != "[]" && polygon.Polygon != ""{
+ DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
+ }
+ }
+ }
+ // 鎶婄洰鏍囨鍑烘潵
+ for _,result := range results {
+ for _,rect := range result.AlarmObj {
+ gocv.Rectangle(&rook, image.Rect(int(rect.Location.X), int(rect.Location.Y), int(rect.Location.X+rect.Location.Width), int(rect.Location.Y+rect.Location.Height)), red, 1)
+ }
+ }
+ //return nil,nil
+ maps,err0 = UploadFromMat(url,rook)
+ return
+}
+func DrawPolygonOnImageForFace(cameraId string, img protomsg.Image, results []structure.Result,url string) (maps map[string]interface{}, err0 error) {
+
+ rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data)
+ //rook := gocv.IMRead("/home/user/workspace/ruleprocess/util/105.jpg",gocv.IMReadColor)
+ defer rook.Close()
+
+ yellow := color.RGBA{255, 255, 0, 0}
+ scale := float64(img.Width) / 960 // 鐢诲浘姣斾緥
+ // 鍒嗗壊鍖哄煙id闆嗗悎骞舵牴鎹甶d鏌ヨ鍖哄煙鐒跺悗鐢绘
+ for _,result := range results {
+ polygonIds := strings.Split(result.AlarmPolygon,",")
+ for i := 0; i < len(polygonIds); i++ {
+ polygon := getPolygonById(polygonIds[i],cameraId)
+ if polygon.Polygon != "[]" && polygon.Polygon != ""{
+ DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
+ }
+ }
+ }
+ //return nil,nil
+ maps,err0 = UploadFromMat(url,rook)
return
}
@@ -214,20 +269,20 @@
var cameraPolygons []protomsg.CameraPolygon
cameraPolygons = cache.GetPolygonsByCameraId(cameraId)
for _, polygon := range cameraPolygons {
- if polygon.Id == polygonId {
+ if strings.Contains(polygonId,polygon.Id) {
return polygon
}
}
return protomsg.CameraPolygon{}
}
// 鍦ㄥ浘涓婄敾涓�涓
-func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA) {
+func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA,scale float64) {
points := ruleserver.Json2points(polygonString)
for index := 0; index < len(points); index++ {
if index == len(points)-1 { // 闂悎鍥惧舰
- gocv.Line(rook, image.Pt(int(points[index].X), int(points[index].Y)), image.Pt(int(points[0].X), int(points[0].Y)), color, 2)
+ gocv.Line(rook, image.Pt(int(points[index].X * scale), int(points[index].Y * scale)), image.Pt(int(points[0].X * scale), int(points[0].Y * scale)), color, 2)
} else {
- gocv.Line(rook, image.Pt(int(points[index].X), int(points[index].Y)), image.Pt(int(points[index+1].X), int(points[index+1].Y)), color, 2)
+ gocv.Line(rook, image.Pt(int(points[index].X * scale), int(points[index].Y * scale)), image.Pt(int(points[index+1].X * scale), int(points[index+1].Y * scale)), color, 2)
}
}
}
--
Gitblit v1.8.0