panlei
2019-10-09 49eaf6fcf782ea66cce284ca910bff7455e67e4b
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,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)
@@ -170,7 +171,8 @@
      logger.Info("-----------------------看看报警区域id:",polygonIds)
      for i := 0; i < len(polygonIds)-1; i++ {
         polygon := getPolygonById(polygonIds[i],cameraId)
         if polygon.Polygon != "[]" {
         if polygon.Polygon != "[]" && polygon.Polygon != ""{
            logger.Debug("所画区域:",polygon.Polygon)
            DrawAPolygon(&rook,polygon.Polygon,yellow)
         }
      }
@@ -186,6 +188,31 @@
   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
}
// 把图片转成二进制流
func RetrieveROM(filename string) ([]byte, error) {
   file, err := os.Open(filename)