【问题标题】:I can't understand this shape from the python code我无法从 python 代码中理解这个形状
【发布时间】:2019-03-24 02:55:47
【问题描述】:

我是 python 新手。我在谷歌上搜索 python 代码来检测路牌,我找到了一些代码,但我不明白代码的含义。

elif dominant_color[0] > 80:
            zone_0 = square[square.shape[0]*3//8:square.shape[0]
                            * 5//8, square.shape[1]*1//8:square.shape[1]*3//8]
            cv2.imshow('Zone0', zone_0)
            zone_0_color = warnadominan(zone_0, 1)

            zone_1 = square[square.shape[0]*1//8:square.shape[0]
                            * 3//8, square.shape[1]*3//8:square.shape[1]*5//8]
            cv2.imshow('Zone1', zone_1)
            zone_1_color = warnadominan(zone_1, 1)

            zone_2 = square[square.shape[0]*3//8:square.shape[0]
                            * 5//8, square.shape[1]*5//8:square.shape[1]*7//8]
            cv2.imshow('Zone2', zone_2)
            zone_2_color = warnadominan(zone_2, 1)

提前致谢

【问题讨论】:

  • 正方形。 shape 是一个元组,数组的维度。
  • 如果将形状的两个元素分配给变量,代码会更清晰,例如h, w = square.shape,然后使用像 square[h*3//8:h*5//8, w*1//8:w*3//8] 这样的索引表达式,它选择中间一半的行和四分之一的列(大约)。

标签: python-3.x numpy opencv


【解决方案1】:
Assuming square has shape (8, 8)

我认为这张图可能会有所帮助:

编辑:代码正在尝试提取图像中显示的区域

【讨论】:

    猜你喜欢
    • 2018-09-10
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多