多尺度图片滑动窗口输出裁剪

简介

上一篇介绍了多尺度图片滑动窗口输出,如果要在新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

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

何以问天涯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值