重叠在图像上滑动窗口 [英] Overlapping Sliding windows over image

查看:858
本文介绍了重叠在图像上滑动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让一个滑动窗口以重叠的步骤在图像上滑动,这样我可以在每个窗口中运行一个分类器,并检测是否有有趣的对象。



为此,我需要确保




  • windows我提取的分类真正做整个图像,和

  • 抓取原始图片上每个滑动窗口的顶部和左侧坐标。




滑动窗口 - 如何获取窗口位置在图像上?



并基于滑动窗口的此代码:



https://github.com/keepitsimple/ocrtest/blob/master/sliding_window.py #blob_contributors_box



由于winh和winw是滑动窗口的宽度和高度,而window_size是(winh,winw),因此我执行以下操作:

  grid_h_max =(imgheight / winh)
grid_w_max =(imgwidth / winw)
win = sliding_window范围(grid_h_max)中的h的
:范围(grid_w_max)中的w的

win = windows [h,w]
grid_pos =(h,w),(winh,winw))
t,b,l,r = get_win_pixel_coords(grid_pos,window_size)

这是工作很好 - 给我滑动窗口以及每个窗口的坐标。



所以如果我的步长是10,我的第一个窗口开始(顶部,左):(0,0)我的第二个窗口应该是(0,10)。



但在上面的代码中,我的第二个窗口是(0,60)。



早些时候,我使用的代码如下:

  windows = sw .sliding_window(image1,window_size,step_size,flatten = True)
在窗口中的w:
#然后我抓住每个w并打印出来
pre>

这给了我所有的滑动窗口,包括重叠的窗口。但是在这个方法中,我不能抓取每个滑动窗口的顶部和左边的坐标。

解决方案



此代码没有导致重叠:

  grid_h_max =(imgheight / winh)
grid_w_max =(imgwidth / winw)
win = sliding_window(img,window_size,shiftSize = None,flatten = False)

将整个图像尺寸与窗口尺寸的尺寸分割显然会产生不重叠的结果。



为了获得正确的窗口数量,我只需允许sliding_window函数告诉我自己窗口的数量是垂直和水平的:

  win = sliding_window(img,window_size,shiftSize = None,flatten = False)
grid_h_max = win.shape [0]
grid_w_max = win.shape [ 1]

这又给我大约5000个窗口。


My objective is to have a sliding window slide over an image in overlapping steps so that I can run a classifier in each window and detect if an interesting object is there.

For that, I need to make sure that

  • windows I extract for classification truly do over the whole image, and
  • grab the top and left coordinates of each sliding window on the original image.

Following up from here: Sliding window - how to get window location on image?

and based on this code for sliding windows:

https://github.com/keepitsimple/ocrtest/blob/master/sliding_window.py#blob_contributors_box

I'm doing the following, given that winh and winw are the sliding window width and height, and window_size is (winh, winw):

grid_h_max =(imgheight/winh)
grid_w_max= (imgwidth / winw)
win = sliding_window(img, window_size, shiftSize=None, flatten=False) 
for h in range (grid_h_max): 
    for w in range (grid_w_max): 
        win = windows[h,w]
        grid_pos = (h,w), (winh, winw)) 
        t, b, l, r = get_win_pixel_coords(grid_pos, window_size)

This is working just fine - giving me sliding windows as well as the coordinates for each window. But I'm not getting overlapping sliding windows.

So if my stepsize is 10 and my first window starts at (top, left): (0,0), then my second window should be (0, 10).

But in the above code, my second window is (0, 60).

Earlier, I was using this code:

windows = sw.sliding_window(image1, window_size, step_size, flatten=True) 
    for w in windows:
        # and then I grabbed each w and printed it out

And this was giving me all the sliding windows, including overlapping windows. However in this method, I wasn't able to grab the top and left coordinates of each sliding window.

解决方案

Alright so I figured out what the issue was.

This code didn't cause overlaps:

grid_h_max =(imgheight/winh)
grid_w_max= (imgwidth / winw)
win = sliding_window(img, window_size, shiftSize=None, flatten=False) 

Dividing the entire image dimensions with those of the window dimensions are obviously going to give non-overlapping results.

To get the right number of windows per dimension, I simply allow the sliding_window function to tell me itself what the number of windows is, vertically and horizontally:

win = sliding_window(img, window_size, shiftSize=None, flatten=False) 
grid_h_max = win.shape[0]
grid_w_max = win.shape[1]

This gave me approximately 5000 windows again.

这篇关于重叠在图像上滑动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆