Instantly share code, notes, and snippets.

Embed
What would you like to do?
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