panlei
2019-10-28 5312ebfc1a3dce594e3fe100743652de0634f9c1
用contain方法通过判断并修正绘图比例
1个文件已修改
16 ■■■■■ 已修改文件
util/simpleCV.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
util/simpleCV.go
@@ -164,7 +164,8 @@
    yellow := color.RGBA{255, 255, 0, 0}
    red := color.RGBA{255, 0, 0, 0}
    scale := img.Width / 960 // 画图比例
    logger.Info("width:",img.Width,"--画图比例:",scale)
    // 分割区域id集合并根据id查询区域然后画框
    for _,result := range results  {
        polygonIds := strings.Split(result.AlarmPolygon,",")
@@ -173,7 +174,7 @@
            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)
            }
        }
    }
@@ -195,7 +196,7 @@
    defer rook.Close()
    yellow := color.RGBA{255, 255, 0, 0}
    scale := img.Width / 960 // 画图比例
    // 分割区域id集合并根据id查询区域然后画框
    for _,result := range results  {
        polygonIds := strings.Split(result.AlarmPolygon,",")
@@ -205,7 +206,7 @@
            logger.Info("----查到的报警框:",polygon)
            if polygon.Polygon != "[]" && polygon.Polygon != ""{
                logger.Debug("所画区域:",polygon.Polygon)
                DrawAPolygon(&rook,polygon.Polygon,yellow)
                DrawAPolygon(&rook,polygon.Polygon,yellow,scale)
            }
        }
    }
@@ -252,13 +253,14 @@
    return protomsg.CameraPolygon{}
}
// 在图上画一个框
func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA) {
func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA,scale int32) {
    points := ruleserver.Json2points(polygonString)
    logger.Info("int32转为float64:",float64(scale))
    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 * float64(scale)), int(points[index].Y * float64(scale))), image.Pt(int(points[0].X * float64(scale)), int(points[0].Y * float64(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 * float64(scale)), int(points[index].Y * float64(scale))), image.Pt(int(points[index+1].X * float64(scale)), int(points[index+1].Y * float64(scale))), color, 2)
        }
    }
}