---
panlei
2019-10-25 f8d0f8954335b803a20d7cddbf4bc06e7810cbf5
util/simpleCV.go
@@ -11,6 +11,7 @@
   "ruleprocess/cache"
   "basic.com/valib/logger.git"
   "ruleprocess/ruleserver"
   "ruleprocess/structure"
   "strings"
)
@@ -155,7 +156,7 @@
   }
}
func DrawPolygonOnImage(cameraId string, img protomsg.Image, results []ruleserver.Result,url string) (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)
@@ -168,7 +169,7 @@
   for _,result := range results  {
      polygonIds := strings.Split(result.AlarmPolygon,",")
      logger.Info("-----------------------看看报警区域id:",polygonIds)
      for i := 0; i < len(polygonIds)-1; i++ {
      for i := 0; i < len(polygonIds); i++ {
         polygon := getPolygonById(polygonIds[i],cameraId)
         if polygon.Polygon != "[]" && polygon.Polygon != ""{
            logger.Debug("所画区域:",polygon.Polygon)
@@ -180,6 +181,32 @@
   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)
      }
   }
   //return nil,nil
   maps,err0 = UploadFromMat(url,rook)
   return
}
func DrawPolygonOnImageForFace(cameraId string, img protomsg.Image, results []structure.FaceResult,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}
   // 分割区域id集合并根据id查询区域然后画框
   for _,result := range results  {
      polygonIds := strings.Split(result.AlarmPolygon,",")
      logger.Info("-----------------------看看报警区域id:",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)
         }
      }
   }
   //return nil,nil
@@ -214,6 +241,7 @@
   // 查到摄像机所有的区域并画框
   var cameraPolygons []protomsg.CameraPolygon
   cameraPolygons = cache.GetPolygonsByCameraId(cameraId)
   logger.Info("根据id查到的报警框:",cameraPolygons)
   for _, polygon := range cameraPolygons {
      if polygon.Id == polygonId {
         return polygon