【问题标题】:Sliding window in python changes shapepython中的滑动窗口改变形状
【发布时间】:2019-10-06 06:09:12
【问题描述】:

我正在使用以下函数在较大的图像上滑动并拉出 (64, 64, 3) 的窗口以从 CNN 进行分类。

def find_vehicles(image_name, classifier):
    window_width, window_height = (64, 64)
    step_size = 64
    image = cv2.imread(image_name)
    image = np.array(image)
    temp = image
    image = image / 255.0

    for i in range(0, image.shape[1] - window_width, step_size):
        for j in range(0, image.shape[0] - window_height, step_size):
            window = image[i:i + window_width, j:j + window_height, :]
            print(window.shape)

但是在 25 次迭代之后,窗口大小缩小到 (55, 64, 3) 并最终缩小到 (0, 64, 3)。我究竟做错了什么?输入图像的形状为(375, 1242, 3)

【问题讨论】:

    标签: python image loops numpy


    【解决方案1】:

    这是一个愚蠢的错误。当我发布问题时,我意识到我正在以宽度 x 高度读取图像,而我应该以高度 x 宽度读取图像。改变

    window = image[i:i + window_width, j:j + window_height, :]
    

    window = image[j:j + window_height, i:i + window_width, :]
    

    解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 2021-02-27
      • 2016-03-06
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2011-10-18
      相关资源
      最近更新 更多