简介
上一篇介绍了多尺度图片滑动窗口输出,如果要在新win窗口下显示当前的滑动窗口图片,那么怎么设置呢?或者将滑动窗口的图片裁剪下来,发现使用
region = (10,0,300,100)#box = (left, top, left+width, top+height),(x0,y0,x1,y1),from W,H
cropImg = img.crop(region)
这样的命令,不成功,numpy has no crop,后来发现先拷贝一份img的数据,使用
cropImg_clone = resized.copy()
注意,其所对应的W、H
cropImg = cropImg_clone[y: (y + winH),x:(x + winW)]#H,W
代码
'''
Created on 2017年8月19日
@author: XT
'''
# import the necessary packages
import helpers
import time
import cv2
# load the image and define the window width and height
image = cv2.imread('../image/cat2.jpg')
(winW, winH) = (200, 128)
i = 0
# loop over the image pyramid
for resized in helpers.pyramid(image, scale=1.5):
# loop over the sliding window for each layer of the pyramid
for (x, y, window) in helpers.sliding_window(resized, stepSize=32, windowSize=(winW, winH)):
# if the window does not meet our desired window size, ignore it
if window.shape[0] != winH or window.shape[1] != winW:
continue
# THIS IS WHERE YOU WOULD PROCESS YOUR WINDOW, SUCH AS APPLYING A
# MACHINE LEARNING CLASSIFIER TO CLASSIFY THE CONTENTS OF THE
# WINDOW
# since we do not have a classifier, we'll just draw the window
clone = resized.copy()
cropImg_clone = resized.copy()
cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
cropImg = cropImg_clone[y: (y + winH),x:(x + winW)]#H,W
cv2.imshow("Window", clone)
cv2.imshow("cropImg", cropImg)
cv2.waitKey(1)
#write
# WinName = "Layer {}".format(i + 1)
# cv2.imwrite('./'+WinName+'.jpg',clone)
# i += 1
time.sleep(0.125)
效果
参考
【1】多尺度图片滑动窗口输出 - Alex_XT的博客 - CSDN博客
http://blog.csdn.net/u011463646/article/details/77417049