forked from UCSD-TIES/DVS-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPupilRemoveTest.py
More file actions
69 lines (56 loc) · 1.9 KB
/
PupilRemoveTest.py
File metadata and controls
69 lines (56 loc) · 1.9 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
65
66
67
68
69
import cv2.cv as cv
DEBUG = True
def pupilRemove(image, region):
""" Crops the eye photo to show only the pupil
and then returns it.
Args:
tuple region - the coordinates of the pupil circle in
the form (centerX, centerY, radius)
Return:
photo - TODO: I'm not sure of the type
"""
# Converting to (topLeftX, topLeftY, width, length)
if region[0]-region[2] < 0:
topLeftX = 0
else:
topLeftX = region[0]-region[2]
if region[1]-region[2] < 0:
topLeftY = 0
else:
topLeftY = region[1]-region[2]
if region[2] < 0:
width = 0
else:
width = region[2] + region[2]
if region[2] < 0:
length = 0
else:
length = region[2]+region[2]
crop = (topLeftX, topLeftY, width, length)
if DEBUG:
print "Region passed to pupil remove: " + str(region)
print "And here's crop: " + str(crop)
print "Before crop we have type: " + str(type(image))
print image
cv.ShowImage("We're cropping", image)
cv.WaitKey(0)
cv.DestroyWindow("We're cropping")
if crop[0] < 0:
crop[0] = 0
if crop[1] < 0:
crop[1] = 0
if crop[2] < 0:
crop[2] = abs(crop[2])
else:
pupil = cv.GetSubRect(image, crop)
if DEBUG:
print "After crop we have type: " + str(type(pupil))
cv.ShowImage("Cropped", pupil)
cv.WaitKey(0)
cv.DestroyWindow("Cropped")
return pupil
return None
############ Main ##################
# Load the photo from file
# give it to pupilRemove
pupilRemove(cv.LoadImage("C:\Users\Shannon\Documents\GitHub\DVS-Python\src\pics\Red06.jpg"),(100,100,10))