【问题标题】:Grid an image with opencv python with respect to image size关于图像大小,使用opencv python对图像进行网格化
【发布时间】:2018-12-23 17:35:20
【问题描述】:

我正在尝试使用 cv2.line 方法在图片上设置网格。现在,我正在做一个到图像宽度的 for 循环,所以我可以在我的图像上放置几条垂直线。但是,在我运行并编译代码后,我得到一个带有蓝色图片的窗口

img = cv2.imread("target.PNG")

height, width, channels = img.shape
for x in range(0, width -1, 1):
     cv2.line(img, (x, 0), (x, height), (255, 0, 0), 1, 1)

cv2.imshow('Hehe', img)
key = cv2.waitKey(0)

目前,这仅适用于垂直线。一旦我得到这个工作,我稍后会添加水平的。它输出一个完整的蓝屏而不是网格。我尝试根据(x,y)坐标的开始和结束来玩数字。

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    您正在为整个图像绘制蓝线而不跳过任何像素,请将您的范围的步长设置为 20 左右。例如:

    img = cv2.imread("target.PNG")
    GRID_SIZE = 20
    
    height, width, channels = img.shape
    for x in range(0, width -1, GRID_SIZE):
         cv2.line(img, (x, 0), (x, height), (255, 0, 0), 1, 1)
    
    cv2.imshow('Hehe', img)
    key = cv2.waitKey(0)
    

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 2018-06-20
      • 2021-02-28
      • 2018-11-20
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多