Skip to content

Instantly share code, notes, and snippets.

@warmspringwinds
Last active August 29, 2015 14:22
Show Gist options
  • Save warmspringwinds/bc2b9ddbf2c030ba83d4 to your computer and use it in GitHub Desktop.
Save warmspringwinds/bc2b9ddbf2c030ba83d4 to your computer and use it in GitHub Desktop.
Cascade and sliding window
import skimage.io as io
from skimage.transform import pyramid_gaussian, rescale
from skimage.util import view_as_windows
from opencv_trainfile_test import detect_face
from matplotlib import pyplot as plt
import matplotlib.patches as patches
current_img = io.imread('roi.jpg')
scale_amount = 4
scale_factor = 0.5
# pyr = tuple(pyramid_gaussian(current_img, 1.1))
# current_img = pyr[1]
for pyramid_num in xrange(scale_amount):
current_img = rescale(current_img, scale_factor, order=1)
detected = []
views = view_as_windows(current_img, (24, 24))
max_stage = 0
print 'scale present'
io.imshow(current_img)
io.show()
print current_img.shape
for row in xrange(views.shape[0]):
for col in xrange(views.shape[1]):
if detect_face(views[row, col]):
detected.append([row, col])
# io.imshow(views[row, col])
# io.show()
plt.imshow(current_img)
img_desc= plt.gca()
plt.set_cmap('gray')
for patch in detected:
img_desc.add_patch(
patches.Rectangle(
(patch[1], patch[0]),
24,
24,
fill=False,
color='c'
)
)
plt.savefig('{}.png'.format(pyramid_num), format='png')
plt.close('all')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment