panlei
2019-10-11 a6fa76d9429b1e23db881b196b50763926994ad2
util/simpleCV.go
@@ -9,8 +9,9 @@
   "image/color"
   "os"
   "ruleprocess/cache"
   "ruleprocess/logger"
   "basic.com/valib/logger.git"
   "ruleprocess/ruleserver"
   "ruleprocess/structure"
   "strings"
)
@@ -155,34 +156,60 @@
   }
}
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}
   // 分割区域id集合并根据id查询区域然后画框
   for _,result := range results  {
      polygonIds := strings.Split(result.AlarmPolygon,"")
      polygonIds := strings.Split(result.AlarmPolygon,",")
      logger.Info("-----------------------看看报警区域id:",polygonIds)
      for i := 0; i < len(polygonIds)-1; i++ {
         polygon := getPolygonById(polygonIds[i],cameraId)
         if polygon.Polygon != "" {
            DrawAPolygon(&rook,polygon.Polygon,red)
         if polygon.Polygon != "[]" && polygon.Polygon != ""{
            logger.Debug("所画区域:",polygon.Polygon)
            DrawAPolygon(&rook,polygon.Polygon,yellow)
         }
      }
   }
   // 把目标框出来
   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)
         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(rook)
   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)-1; i++ {
         polygon := getPolygonById(polygonIds[i],cameraId)
         if polygon.Polygon != "[]" && polygon.Polygon != ""{
            logger.Debug("所画区域:",polygon.Polygon)
            DrawAPolygon(&rook,polygon.Polygon,yellow)
         }
      }
   }
   //return nil,nil
   maps,err0 = UploadFromMat(url,rook)
   return
}
@@ -214,7 +241,6 @@
   var cameraPolygons []protomsg.CameraPolygon
   cameraPolygons = cache.GetPolygonsByCameraId(cameraId)
   for _, polygon := range cameraPolygons {
      logger.Info("看看缓存中查出的区域和传进来的",polygon.Id,polygonId)
      if polygon.Id == polygonId {
         return polygon
      }
@@ -226,9 +252,9 @@
   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*1.33), int(points[index].Y*1.33)), image.Pt(int(points[0].X*1.33), int(points[0].Y*1.33)), 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*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)
      }
   }
}