forked from UCSD-TIES/DVS-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerticalPhoto.py
More file actions
64 lines (49 loc) · 2.1 KB
/
VerticalPhoto.py
File metadata and controls
64 lines (49 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
""" A class to perform actions on a vertical photo of a face
where the eyes are along a vertical axis
This class inherits from it's parent FacePhoto
"""
from FacePhoto import *
import cv2.cv as cv
import cv2
import numpy as np
DEBUG = False
class VerticalPhoto(FacePhoto,object):
def __init__(self, photo, path):
""" Initialize the attributes of a FacePhoto
This constructor rotates the photo so that we can process
it as we would a vertical photo then calls FacePhoto's __init__
method to populate the eyes, etc.
Args:
photo photo - a photo of a face
Return:
None
"""
# Rotate photo
# NOTE: Not sure if this will rotate the photo to be right side
# up or upside
# TODO: Find this out for sure from the hardware team
#photo = self.rotateImage(photo,270)
if DEBUG:
cv.ShowImage("Rotated Image (in VerticalPhoto init)",photo)
cv.WaitKey(0)
cv.DestroyWindow("Rotated Image (in VerticalPhoto init)")
# call FacePhoto(super)'s init
super(VerticalPhoto,self).__init__(photo,path)
def rotateImage(self, image, angle):
if DEBUG:
print "We are now rotating this photo"
image0 = image
if hasattr(image, 'shape'):
image_center = tuple(np.array(image.shape)/2)
shape = tuple(image.shape)
elif hasattr(image, 'width') and hasattr(image, 'height'):
image_center = tuple(np.array((image.width/2, image.height/2)))
shape = (image.width, image.height)
else:
raise Exception, 'Unable to acquire dimensions of image for type %s.' % (type(image),)
rot_mat = cv2.getRotationMatrix2D(image_center, angle,1.0)
image = np.asarray( image[:,:] )
rotated_image = cv2.warpAffine(image, rot_mat, shape, flags=cv2.INTER_LINEAR)
# Copy the rotated data back into the original image object.
cv.SetData(image0, rotated_image.tostring())
return image0