From 1f8d2ef9a690e2cb9a0f26020e8ea21064f9722c Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期三, 11 十二月 2019 18:03:23 +0800 Subject: [PATCH] --- --- util/simpleCV.go | 63 ++++++++++++++++++++++--------- 1 files changed, 44 insertions(+), 19 deletions(-) diff --git a/util/simpleCV.go b/util/simpleCV.go index 9abc5bd..32bcdef 100644 --- a/util/simpleCV.go +++ b/util/simpleCV.go @@ -155,7 +155,6 @@ } } } - 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) @@ -164,23 +163,23 @@ 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锛�",polygonIds) + logger.Info("鍖哄煙ID锛�",result.AlarmPolygon,polygonIds) for i := 0; i < len(polygonIds); i++ { 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) } } } // 鎶婄洰鏍囨鍑烘潵 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)), red, 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 @@ -188,24 +187,52 @@ return } -func DrawPolygonOnImageForFace(cameraId string, img protomsg.Image, results []structure.FaceResult,url string) (maps map[string]interface{}, err0 error) { +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锛�",polygonIds) + logger.Info("鍖哄煙ID锛�",result.AlarmPolygon,polygonIds) for i := 0; i < len(polygonIds); i++ { polygon := getPolygonById(polygonIds[i],cameraId) - logger.Info("----鏌ュ埌鐨勬姤璀︽锛�",polygon) if polygon.Polygon != "[]" && polygon.Polygon != ""{ - logger.Debug("鎵�鐢诲尯鍩燂細",polygon.Polygon) - DrawAPolygon(&rook,polygon.Polygon,yellow) + 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) } } } @@ -241,23 +268,21 @@ // 鏌ュ埌鎽勫儚鏈烘墍鏈夌殑鍖哄煙骞剁敾妗� var cameraPolygons []protomsg.CameraPolygon cameraPolygons = cache.GetPolygonsByCameraId(cameraId) - logger.Info("鏍规嵁id鏌ュ埌鐨勬姤璀︽锛�",cameraPolygons) for _, polygon := range cameraPolygons { - logger.Info("鏌ュ埌鐨勫尯鍩焛d锛�",polygon.Id,"--瑕佸尮閰嶇殑鏁版嵁id锛�",polygonId) - 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*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 * 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*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 * 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