Repository navigation
Expand file tree
/
Copy pathTutorial.py
More file actions
237 lines (217 loc) · 7.25 KB
/
Copy pathTutorial.py
File metadata and controls
237 lines (217 loc) · 7.25 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/python
# A Basic SimpleCV interactive shell tutorial
#load required libraries
from SimpleCV import *
from subprocess import call
import platform
lb = "\n" #linebreak
tb = "\t" #tab
#Command to clear the shell screen
def shellclear():
if platform.system() == "Windows":
return
call("clear")
def tutorial_image():
shellclear()
print "SimpleCV Image tutorial"
print "-----------------------"
print lb
print "using images are simple, in SimpleCV"
print "to start find a location where an actual file exist"
print "in this example we have /tmp/simplecv.jpg"
print "so to load this into memory, it's as easy as:"
print lb
print "img = Image('./SimpleCV/sampleimages/color.jpg')"
print lb
raw_input("[Press enter to continue]")
shellclear()
print "Now try it yourself at the terminal"
print "img = Image('./SimpleCV/sampleimages/color.jpg')"
print lb
in_text = ""
shouldbe = "img = Image('./SimpleCV/sampleimages/color.jpg')"
while (in_text != shouldbe):
in_text = raw_input("SimpleCV:>")
if(in_text != shouldbe):
print "sorry, that is incorrect"
print "please type:"
print shouldbe
shellclear()
print "Correct, you just loaded an image into memory"
print "Images are the basis for everything in SimpleCV"
print "they are what manipulations are performed on"
print "but that is the basis for the image tutorial"
print lb
raw_input("[Press enter to continue]")
return
def tutorial_save():
shellclear()
print "Once you have an Image Object loaded in memory you can"
print "now save it to disk. If you don't or don't know how then"
print "you can run the image tutorial"
print lb
raw_input("[Press enter to continue]")
shellclear()
print "Saving an image is very simple, pardon the pun."
print "but once it's loaded into memory, it's literally just:"
print "image.save()"
print lb
print "This will save the image back to the location it was loaded from"
print "so if you did img = Image('/tmp/test.jpg'), then it will save"
print "it back there, otherwise you can do:"
print "Image.save('/any/path/you/want')"
print lb
print "So try it now and save an image somewhere on your system"
print "img.save('/tmp/new.jpg')"
print lb
in_text = ""
shouldbe = "img.save('/tmp/new.jpg')"
while (in_text != shouldbe):
in_text = raw_input("SimpleCV:>")
if(in_text != shouldbe):
print "sorry, that is incorrect"
print "please type:"
print shouldbe
shellclear()
print "Correct, you just saved a new copy of the image to /tmp/new.jpg"
print "as you can see in SimpleCV most of the functions are intuitive"
print lb
raw_input("[Press enter to continue]")
return
def tutorial_copy():
shellclear()
print "Image Copy"
print "If you need a copy of an image, this is also very simple"
print "img = Image('./SimpleCV/sampleimages/color.jpg')"
print "clonedimage = img.copy()"
print lb
print lb
in_text = ""
shouldbe = "clone = img.copy()"
print "Please type this now:"
print shouldbe
print lb
while (in_text != shouldbe):
in_text = raw_input("SimpleCV:>")
if(in_text != shouldbe):
print "sorry, that is incorrect"
print "please type:"
print shouldbe
shellclear()
print "Correct, you just cloned an image into memory"
print "you need to be careful when using this method though"
print "as using a reference vs. a copy. For instance if you just"
print "typed: clone = img"
print "then clone is actually pointing at the same thing in memory"
print "and if you did clone.binarize() it is the same as img.binarize()"
print "so if you want a copy of an image you have to return a copy of"
print "not just point a reference to it"
print lb
raw_input("[Press enter to continue]")
return
def tutorial_slicing():
shellclear()
print "Slicing:"
print "Slicing is sort of a new paradigm to access parts of an image"
print "Typically in vision a region of interest (ROI) is given. "
print "In this case slicing is a very powerful way to access parts"
print "of an image, or basically any matrix in SimpleCV in general."
print lb
print "This is done by using:"
print "section = img[1:10,1:10]"
print lb
print "What is returned is an image object with that window."
print "the slicing basically acts like a ROI but returns an image"
print "so if you wanted to say run edge detection on a 20x20 box"
print "in the picture that started at x=5,y=10 you use:"
print "foundedges = img[5:25,10:30].edges()"
print lb
raw_input("[Press enter to continue]")
shellclear()
in_text = ""
shouldbe = "ROI = img[1:6,1:6]"
print "Please type this now:"
print shouldbe
print lb
while (in_text != shouldbe):
in_text = raw_input("SimpleCV:>")
if(in_text != shouldbe):
print "sorry, that is incorrect"
print "please type:"
print shouldbe
shellclear()
print "Correct, you just returned a 5 pixel by 5 pixel image object"
print lb
return
def tutorial_corners():
shellclear()
print "Finding corners:"
print "This will find corner Feature objects and return them as a FeatureSet"
print "the strongest corners first. The parameters give the number"
print "of corners to look for, the minimum quality of the corner feature"
print "and the minimum distance between corners. "
print lb
print "This is also very easy to do in SimpleCV, you use:"
print "foundcorners = image.findCorners()"
print lb
print "Now keep in mind parameters can be passed as a threshold as well"
print "to the function so you can use:"
print "foundcorners = image.findCorners(2)"
print lb
print "If you are unsure what parameters to pass it you can always"
print "the built in help support by typing"
print "help image.finderCorners"
print lb
print "keep in mind this help works for all of the functions available"
print "in SimpleCV"
print lb
raw_input("[Press enter to continue]")
shellclear()
in_text = ""
shouldbe = "corners = img.findCorners()"
print "Please type this now:"
print shouldbe
print lb
while (in_text != shouldbe):
in_text = raw_input("SimpleCV:>")
if(in_text != shouldbe):
print "sorry, that is incorrect"
print "please type:"
print shouldbe
shellclear()
print "Correct, you just returned a featureset object which contains"
print "feature objects. These feature objects contain data from the"
print "found corners"
print lb
return
def magic_tutorial(self,arg):
if (arg == ""):
shellclear()
print "??????????????????????????????????"
print " Welcome to the SimpleCV tutorial "
print "??????????????????????????????????"
print lb
print "At anytime on the SimpleCV:> you can type tutorial."
print "then press the tab key and it will autocomplete any tutorial"
print "that is currently available."
print lb
print "You will first learn how to load an image"
print lb
print lb
raw_input("[Press enter to continue]")
tutorial_image()
tutorial_save()
tutorial_copy()
tutorial_slicing()
tutorial_corners()
return
elif (arg == "image"):
tutorial_image()
elif (arg == "save"):
tutorial_save()
elif (arg == "copy"):
tutorial_copy()
elif (arg == "slicing"):
tutorial_slicing()
elif (arg == "corners"):
tutorial_corners()