panlei
2019-10-28 c79d961e01f8dee60df488f87312f8bf97e2967c
绘图比例使用float64而不是int32
1个文件已修改
11 ■■■■ 已修改文件
util/simpleCV.go 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
util/simpleCV.go
@@ -164,7 +164,7 @@
    yellow := color.RGBA{255, 255, 0, 0}
    red := color.RGBA{255, 0, 0, 0}
    scale := img.Width / 960 // 画图比例
    scale := float64(img.Width) / 960 // 画图比例
    logger.Info("width:",img.Width,"--画图比例:",scale)
    // 分割区域id集合并根据id查询区域然后画框
    for _,result := range results  {
@@ -196,7 +196,7 @@
    defer rook.Close()
    yellow := color.RGBA{255, 255, 0, 0}
    scale := img.Width / 960 // 画图比例
    scale := float64(img.Width) / 960 // 画图比例
    // 分割区域id集合并根据id查询区域然后画框
    for _,result := range results  {
        polygonIds := strings.Split(result.AlarmPolygon,",")
@@ -253,14 +253,13 @@
    return protomsg.CameraPolygon{}
}
// 在图上画一个框
func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA,scale int32) {
func DrawAPolygon(rook *gocv.Mat,polygonString string, color color.RGBA,scale float64) {
    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 * float64(scale)), int(points[index].Y * float64(scale))), image.Pt(int(points[0].X * float64(scale)), int(points[0].Y * float64(scale))), 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 * 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)
            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)
        }
    }
}