├── .idea
└── vcs.xml
├── 1.jpg
├── 2.jpg
├── A-star-feasibility-clearance.py
├── A-star.py
├── AfterMedianBlurring
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── Afterthresholding
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── BinaryImages
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── Clearance
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── DetectionOfObstacles
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── DetectionofContours
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── README.md
├── WIN_20151203_18_30_01_Pro.jpg
├── a.txt
├── beforeplanningwithclearance
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── beforeplanningwithoutclearance
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── camera_caliberation.py
├── create_spline.py
├── feasibility-clearance.py
├── feasibility_clearance.py
├── images
├── WIN_20151203_18_22_30_Pro.jpg
├── WIN_20151203_18_22_59_Pro.jpg
├── WIN_20151203_18_23_11_Pro.jpg
├── WIN_20151203_18_23_30_Pro.jpg
├── WIN_20151203_18_23_37_Pro.jpg
├── WIN_20151203_18_23_46_Pro.jpg
├── WIN_20151203_18_24_13_Pro.jpg
├── WIN_20151203_18_24_59_Pro.jpg
├── WIN_20151203_18_25_06_Pro.jpg
├── WIN_20151203_18_25_10_Pro.jpg
├── WIN_20151203_18_25_14_Pro.jpg
├── WIN_20151203_18_25_20_Pro.jpg
├── WIN_20151203_18_25_36_Pro.jpg
├── WIN_20151203_18_26_48_Pro.jpg
├── WIN_20151203_18_26_52_Pro.jpg
├── WIN_20151203_18_26_55_Pro.jpg
├── WIN_20151203_18_26_58_Pro.jpg
├── WIN_20151203_18_27_02_Pro.jpg
├── WIN_20151203_18_27_10_Pro.jpg
├── WIN_20151203_18_27_19_Pro.jpg
├── WIN_20151203_18_28_49_Pro.jpg
├── WIN_20151203_18_28_52_Pro.jpg
├── WIN_20151203_18_28_55_Pro.jpg
├── WIN_20151203_18_28_57_Pro.jpg
├── WIN_20151203_18_29_19_Pro.jpg
├── WIN_20151203_18_29_29_Pro.jpg
├── WIN_20151203_18_29_43_Pro.jpg
└── WIN_20151203_18_30_01_Pro.jpg
├── obstacle_detection.py
├── obstacle_detection2.py
├── output
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── speech.py
├── test.py
├── test2.py
├── test3.py
├── test4.py
├── test5.py
└── withoutClearance
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/1.jpg
--------------------------------------------------------------------------------
/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/2.jpg
--------------------------------------------------------------------------------
/A-star-feasibility-clearance.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 | import math
6 | import time
7 | import Queue as Q
8 | import matplotlib.pyplot as plt
9 | import scipy as sp
10 | from scipy.interpolate import interp1d
11 |
12 | '''
13 | function definition from A-star
14 | start
15 | '''
16 |
17 | class pixel1(object):
18 | def __init__(self, penalty, pointx, pointy, parent, h): # parent is that pixel from which this current pixel is generated
19 | self.penalty = penalty
20 | self.pointx = int(pointx)
21 | self.pointy = int(pointy)
22 | self.parent = parent
23 | self.h = h #heuristic
24 |
25 | def __cmp__(self, other): # comparable which will return self.penalty -1 and ny > -1 and nx < ex and ny < ey:
47 | return True
48 | else:
49 | return False
50 |
51 | def bfs(arr, sx, sy, dx, dy, final_contours): # sx, sy :- source coordinates dx, dy :- destination coordinates
52 | q = Q.PriorityQueue()
53 | temp1 = True
54 | temp2 = True
55 |
56 | for cnt in final_contours:
57 | if cv2.pointPolygonTest(cnt, (sx, sy), False) > -1:
58 | temp1 = False
59 |
60 | for cnt in final_contours:
61 | if cv2.pointPolygonTest(cnt, (dx, dy), False) > -1:
62 | temp2 = False
63 |
64 | if temp1 == False or temp2 == False:
65 | return []
66 |
67 | actions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]]
68 | solution = []
69 | ex, ey, ez = arr.shape
70 | #visit = [[False for x in range(ey)] for x in range(ex)]
71 | dist = [[10000 for x in range(ey)] for x in range(ex)]
72 | distplusHeuristic = [[10000 for x in range(ey)] for x in range(ex)]
73 |
74 | q.put(pixel1(0, sx, sy, None, heuristic(sx, sy, dx, dy)))
75 | dist[sx][sy] = 0
76 | distplusHeuristic[sx][sy] = dist[sx][sy]+heuristic(sx, sy, dx, dy)
77 | s = time.clock()
78 | cnt = 0
79 | cntq = 0
80 | while not q.empty():
81 | p = q.get()
82 | x = int(p.pointx)
83 | y = int(p.pointy)
84 | pen = p.penalty
85 | h = p.h
86 | cnt = cnt+1
87 | if dist[x][y] < pen:
88 | continue
89 | if x == dx and y == dy:
90 | while p is not None:
91 | solution.append([p.pointx, p.pointy])
92 | p = p.parent
93 | print 'time : ', time.clock()-s
94 | print cnt, cntq
95 | return solution
96 |
97 | for i in range(len(actions)):
98 | nx = int(actions[i][0] + x)
99 | ny = int(actions[i][1] + y)
100 | if check_boundaries(ex, ey, nx, ny) == True:
101 | #if arr.item(nx, ny, 0) == 0 and arr.item(nx, ny, 1) == 0 and arr.item(nx, ny, 2) == 0:
102 | pen = dist[x][y]
103 | pen_new = cost(x, y, nx, ny, pen, 255-arr[nx][ny][0])
104 | h_new = heuristic(nx, ny, dx, dy)
105 | if dist[nx][ny] > pen_new :
106 | dist[nx][ny] = pen_new
107 | nx = int(nx)
108 | ny = int(ny)
109 | if distplusHeuristic[nx][ny] > dist[nx][ny]+h_new :
110 | distplusHeuristic[nx][ny] = dist[nx][ny] + h_new
111 | cntq = cntq+1
112 | q.put(pixel1(pen_new, nx, ny, p, h_new))
113 | print 'time : ', time.clock()-s
114 | return []
115 |
116 | '''
117 | function definition from A-star
118 | end
119 | '''
120 |
121 | '''
122 | function definition from Clearance-feasibility
123 | start
124 | '''
125 |
126 | class pixel(object):
127 | def __init__(self, penalty, pointx, pointy): # parent is that pixel from which this current pixel is generated
128 | self.penalty = penalty
129 | self.pointx = int(pointx)
130 | self.pointy = int(pointy)
131 |
132 | def __cmp__(self, other): # comparable which will return self.penalty -1 and ny > -1 and nx < ex and ny < ey:
142 | return True
143 | else:
144 | return False
145 |
146 | def fill_clearance(arr,cmax, final_contours): # sx, sy :- source coordinates dx, dy :- destination coordinates
147 | q = Q.PriorityQueue()
148 |
149 | actions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]]
150 | ex, ey, ez = arr.shape
151 | #print ex, ey, ez
152 | min_cost = [[100000 for x in range(ey)] for x in range(ex)]
153 | for cnt in final_contours:
154 | for pts in cnt:
155 | q.put(pixel(0, pts[0, 1], pts[0, 0]))
156 | cnt = 0
157 | cntq = 0
158 | while not q.empty():
159 | p = q.get()
160 | x = int(p.pointx)
161 | y = int(p.pointy)
162 | pen = p.penalty
163 | if p.penalty > cmax:
164 | continue
165 | if min_cost[x][y] <= p.penalty:
166 | continue
167 | min_cost[x][y] = p.penalty
168 |
169 | for i in range(len(actions)):
170 | nx = int(actions[i][0] + x)
171 | ny = int(actions[i][1] + y)
172 | if check_boundaries(ex, ey, nx, ny) == True:
173 | if arr.item(nx, ny, 0) == 0 and arr.item(nx, ny, 1) == 0 and arr.item(nx, ny, 2) == 0:
174 | if min_cost[nx][ny] > penalty(x, y, nx, ny, pen):
175 | q.put(pixel(penalty(x,y,nx,ny,pen), nx, ny))
176 | return min_cost
177 | '''
178 | function definition from Clearance-feasibility
179 | end
180 | '''
181 |
182 |
183 | def smooth(path):
184 |
185 | weight_data=0.001
186 | weight_smooth=0.5
187 | max_error=0.01
188 | newpath = copy.deepcopy(path)
189 |
190 | while True:
191 | error = 0.0
192 |
193 | for i in xrange(len(newpath)):
194 | if i == 0 or i == (len(newpath) - 1):
195 | continue
196 | temp = newpath[i][0]
197 | temp2 = newpath[i][1]
198 |
199 | newpath[i][0] += weight_data * (path[i][0] - newpath[i][0]) + weight_smooth * (
200 | newpath[i + 1][0] + newpath[i - 1][0] - 2 * newpath[i][0])
201 | newpath[i][1] += weight_data * (path[i][1] - newpath[i][1]) + weight_smooth * (
202 | newpath[i + 1][1] + newpath[i - 1][1] - 2 * newpath[i][1])
203 |
204 | error += abs(float(newpath[i][0] - temp)) + abs(float(newpath[i][1] - temp2))
205 |
206 | if error <= max_error:
207 | break
208 |
209 | for i in xrange(len(newpath)):
210 | path[i][0] = int(newpath[i][0])
211 | path[i][1] = int(newpath[i][1])
212 |
213 | return path
214 |
215 |
216 | def main():
217 | counter = 1
218 | for im in images:
219 |
220 | img = cv2.imread(im)
221 |
222 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
223 | img2 = cv2.medianBlur(cimg,13)
224 |
225 | ret,thresh1 = cv2.threshold(cimg,100,120,cv2.THRESH_BINARY)
226 | t2 = copy.copy(thresh1)
227 |
228 | x, y = thresh1.shape
229 | arr = np.zeros((x, y, 3), np.uint8)
230 | final_contours= []
231 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
232 | for i in range(len(contours)):
233 | cnt = contours[i]
234 | if cv2.contourArea(cnt) > 1000 and cv2.contourArea(cnt) < 15000 :
235 | cv2.drawContours(img, [cnt],-1, [0, 255, 255])
236 | cv2.fillConvexPoly(arr, cnt, [255, 255, 255])
237 | final_contours.append(cnt)
238 | cmax = 50
239 | start = time.clock()
240 | output = 'beforeplanningwithoutclearance/' + `counter`
241 | output += ".jpg"
242 | cv2.imwrite(output, arr)
243 |
244 | min_cost = fill_clearance(arr,cmax, final_contours)
245 |
246 |
247 |
248 | print 'time: ', time.clock()-start
249 | '''
250 | for i in xrange(x):
251 | for j in xrange(y):
252 | if min_cost[i][j] == 100000:
253 | min_cost[i][j] = 0;
254 | '''
255 |
256 | for i in xrange(x):
257 | for j in xrange(y):
258 | pix_val = int(255-5*min_cost[i][j])
259 | if(min_cost[i][j] > 10000):
260 | pix_val = 0
261 | arr[i, j] = (pix_val, pix_val, pix_val)
262 | for cnt in final_contours:
263 | cv2.fillConvexPoly(arr, cnt, [255, 255, 255])
264 |
265 | output = 'beforeplanningwithclearance/' + `counter`
266 | output += ".jpg"
267 | cv2.imwrite(output, arr)
268 |
269 | '''
270 | Code from A-star.py
271 | '''
272 | sx = 20 # raw_input("Enter source and destination Coordinates")
273 | sy = 20 # raw_input()
274 | dx = 500 # raw_input()
275 | dy = 1000 # raw_input()
276 |
277 | # s = time.clock()
278 | output = "Clearance/"+`counter`
279 | output += ".jpg"
280 | cv2.imwrite(output, arr)
281 |
282 | solution = bfs(arr, sx, sy, dx, dy, final_contours)
283 | # print 'time: ', time.clock()-s
284 | if len(solution) == 0:
285 | print 'No solution from source to destination'
286 | else:
287 | solution = smooth(solution)
288 | for i in range(len(solution)):
289 |
290 | start = (solution[i][1], solution[i][0])
291 | cv2.circle(arr,start, 1, [255, 0, 255])
292 | cv2.circle(img, start, 1, [255, 0, 255])
293 |
294 | with open("a.txt", 'w') as fp:
295 | for i in range(len(solution)):
296 | fp.write(`solution[i][1]` + ' ' + `solution[i][0]` + '\n')
297 |
298 | cv2.circle(arr, (sy, sx), 2, [0, 255, 0])
299 | cv2.circle(arr, (dy, dx), 2, [0, 255, 0])
300 | cv2.circle(img, (sy, sx), 2, [0, 255, 0])
301 | cv2.circle(img, (dy, dx), 2, [0, 255, 0])
302 |
303 | output = "output/"+`counter`
304 | output += ".jpg"
305 | cv2.imwrite(output, img)
306 | counter += 1
307 |
308 | cv2.imshow('image', img)
309 | cv2.imshow('arr', arr)
310 | cv2.waitKey(0)
311 | cv2.destroyAllWindows()
312 |
313 | main()
--------------------------------------------------------------------------------
/A-star.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 | import math
6 | import Queue as Q
7 | import time
8 | import matplotlib.pyplot as plt
9 | import scipy as sp
10 | from scipy.interpolate import interp1d
11 |
12 | class pixel(object):
13 | def __init__(self, penalty, pointx, pointy, parent, h): # parent is that pixel from which this current pixel is generated
14 | self.penalty = penalty
15 | self.pointx = int(pointx)
16 | self.pointy = int(pointy)
17 | self.parent = parent
18 | self.h = h #heuristic
19 |
20 | def __cmp__(self, other): # comparable which will return self.penalty -1 and ny > -1 and nx < ex and ny < ey:
40 | return True
41 | else:
42 | return False
43 |
44 | def bfs(arr, sx, sy, dx, dy, final_contours): # sx, sy :- source coordinates dx, dy :- destination coordinates
45 | q = Q.PriorityQueue()
46 | temp1 = True
47 | temp2 = True
48 |
49 | for cnt in final_contours:
50 | if cv2.pointPolygonTest(cnt, (sx, sy), False) > -1:
51 | temp1 = False
52 |
53 | for cnt in final_contours:
54 | if cv2.pointPolygonTest(cnt, (dx, dy), False) > -1:
55 | temp2 = False
56 |
57 | if temp1 == False or temp2 == False:
58 | return []
59 |
60 | actions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]]
61 | solution = []
62 | ex, ey, ez = arr.shape
63 | #visit = [[False for x in range(ey)] for x in range(ex)]
64 | dist = [[10000 for x in range(ey)] for x in range(ex)]
65 | distplusHeuristic = [[10000 for x in range(ey)] for x in range(ex)]
66 |
67 | q.put(pixel(0, sx, sy, None, heuristic(sx, sy, dx, dy)))
68 | dist[sx][sy] = 0
69 | distplusHeuristic[sx][sy] = dist[sx][sy]+heuristic(sx, sy, dx, dy)
70 | s = time.clock()
71 | cnt = 0
72 | cntq = 0
73 | while not q.empty():
74 | p = q.get()
75 | x = int(p.pointx)
76 | y = int(p.pointy)
77 | pen = p.penalty
78 | h = p.h
79 | cnt = cnt+1
80 | if dist[x][y] < pen:
81 | continue
82 | if x == dx and y == dy:
83 | while p is not None:
84 | solution.append([p.pointx, p.pointy])
85 | p = p.parent
86 | print 'time : ', time.clock()-s
87 | print cnt, cntq
88 | return solution
89 |
90 | for i in range(len(actions)):
91 | nx = int(actions[i][0] + x)
92 | ny = int(actions[i][1] + y)
93 | if check_boundaries(ex, ey, nx, ny) == True:
94 | if arr.item(nx, ny, 0) == 0 and arr.item(nx, ny, 1) == 0 and arr.item(nx, ny, 2) == 0:
95 | pen = dist[x][y]
96 | pen_new = penalty(x, y, nx, ny, pen)
97 | h_new = heuristic(nx, ny, dx, dy)
98 | if dist[nx][ny] > pen_new :
99 | dist[nx][ny] = pen_new
100 | nx = int(nx)
101 | ny = int(ny)
102 | if distplusHeuristic[nx][ny] > dist[nx][ny]+h_new :
103 | distplusHeuristic[nx][ny] = dist[nx][ny] + h_new
104 | cntq = cntq+1
105 | q.put(pixel(pen_new, nx, ny, p, h_new))
106 | print 'time : ', time.clock()-s
107 | return []
108 |
109 | def main():
110 | counter = 1
111 | for im in images:
112 | img = cv2.imread(im)
113 |
114 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
115 | output = 'BinaryImages/' + `counter`
116 | output += ".jpg"
117 | cv2.imwrite(output, cimg)
118 | img2 = cv2.medianBlur(cimg,13)
119 | output = 'AfterMedianBlurring/' + `counter`
120 | output += ".jpg"
121 | cv2.imwrite(output, img2)
122 |
123 | ret,thresh1 = cv2.threshold(cimg,100,120,cv2.THRESH_BINARY)
124 | output = 'Afterthresholding/' + `counter`
125 | output += ".jpg"
126 | cv2.imwrite(output, thresh1)
127 | t2 = copy.copy(thresh1)
128 |
129 | x, y = thresh1.shape
130 | print x, y
131 | arr = np.zeros((x, y, 3), np.uint8)
132 | final_contours= []
133 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
134 | arr2 = np.zeros((x,y,3), np.uint8)
135 | for i in range(len(contours)):
136 | cnt = contours[i]
137 | cv2.drawContours(arr2, [cnt],-1, [255, 255, 255])
138 | output = 'DetectionOfContours/' + `counter`
139 | output += ".jpg"
140 | cv2.imwrite(output, arr2)
141 |
142 |
143 | for i in range(len(contours)):
144 | cnt = contours[i]
145 | if cv2.contourArea(cnt) > 1000 and cv2.contourArea(cnt) < 15000:
146 | cv2.drawContours(img, [cnt],-1, [0, 255, 255])
147 | cv2.fillConvexPoly(arr, cnt, [255, 255, 255])
148 | final_contours.append(cnt)
149 |
150 | output = 'DetectionOfObstacles/' + `counter`
151 | output += ".jpg"
152 | cv2.imwrite(output, arr)
153 |
154 | output = 'beforeplanningwithoutclearance/' + `counter`
155 | output += ".jpg"
156 | cv2.imwrite(output, arr)
157 | sx = 20 # raw_input("Enter source and destination Coordinates")
158 | sy = 20 # raw_input()
159 | dx = 500 # raw_input()
160 | dy = 1000 # raw_input()
161 |
162 | # s = time.clock()
163 | solution = bfs(arr, sx, sy, dx, dy, final_contours)
164 | # print 'time: ', time.clock()-s
165 | if len(solution) == 0:
166 | print 'No solution from source to destination'
167 | else:
168 | for i in range(len(solution)):
169 | start = (solution[i][1], solution[i][0])
170 | cv2.circle(arr,start, 1, [255, 0, 255])
171 | cv2.circle(img, start, 1, [255, 255, 255])
172 | output = "withoutClearance/"+`counter`
173 | output += ".jpg"
174 | cv2.imwrite(output, img)
175 | counter += 1
176 | cv2.circle(arr, (sy, sx), 2, [0, 255, 0])
177 | cv2.circle(arr, (dy, dx), 2, [0, 255, 0])
178 | cv2.circle(img, (sy, sx), 2, [0, 255, 0])
179 | cv2.circle(img, (dy, dx), 2, [0, 255, 0])
180 | cv2.imshow('image', img)
181 | cv2.imshow('arr', arr)
182 | cv2.waitKey(0)
183 | cv2.destroyAllWindows()
184 |
185 | main()
--------------------------------------------------------------------------------
/AfterMedianBlurring/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/1.jpg
--------------------------------------------------------------------------------
/AfterMedianBlurring/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/2.jpg
--------------------------------------------------------------------------------
/AfterMedianBlurring/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/3.jpg
--------------------------------------------------------------------------------
/AfterMedianBlurring/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/4.jpg
--------------------------------------------------------------------------------
/AfterMedianBlurring/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/5.jpg
--------------------------------------------------------------------------------
/AfterMedianBlurring/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/AfterMedianBlurring/6.jpg
--------------------------------------------------------------------------------
/Afterthresholding/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/1.jpg
--------------------------------------------------------------------------------
/Afterthresholding/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/2.jpg
--------------------------------------------------------------------------------
/Afterthresholding/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/3.jpg
--------------------------------------------------------------------------------
/Afterthresholding/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/4.jpg
--------------------------------------------------------------------------------
/Afterthresholding/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/5.jpg
--------------------------------------------------------------------------------
/Afterthresholding/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Afterthresholding/6.jpg
--------------------------------------------------------------------------------
/BinaryImages/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/1.jpg
--------------------------------------------------------------------------------
/BinaryImages/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/2.jpg
--------------------------------------------------------------------------------
/BinaryImages/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/3.jpg
--------------------------------------------------------------------------------
/BinaryImages/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/4.jpg
--------------------------------------------------------------------------------
/BinaryImages/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/5.jpg
--------------------------------------------------------------------------------
/BinaryImages/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/BinaryImages/6.jpg
--------------------------------------------------------------------------------
/Clearance/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/1.jpg
--------------------------------------------------------------------------------
/Clearance/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/2.jpg
--------------------------------------------------------------------------------
/Clearance/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/3.jpg
--------------------------------------------------------------------------------
/Clearance/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/4.jpg
--------------------------------------------------------------------------------
/Clearance/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/5.jpg
--------------------------------------------------------------------------------
/Clearance/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/Clearance/6.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/1.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/2.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/3.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/4.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/5.jpg
--------------------------------------------------------------------------------
/DetectionOfObstacles/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionOfObstacles/6.jpg
--------------------------------------------------------------------------------
/DetectionofContours/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/1.jpg
--------------------------------------------------------------------------------
/DetectionofContours/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/2.jpg
--------------------------------------------------------------------------------
/DetectionofContours/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/3.jpg
--------------------------------------------------------------------------------
/DetectionofContours/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/4.jpg
--------------------------------------------------------------------------------
/DetectionofContours/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/5.jpg
--------------------------------------------------------------------------------
/DetectionofContours/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/DetectionofContours/6.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A-star-planning
2 |
3 | Prerequisites
4 | - Python
5 | - OpenCV
6 | - Numpy
7 | - Matplotlib
8 |
9 | This is extended implementation of A-star algorithm.
10 |
11 | For basic knowledge of A-star , one can refer following links : https://en.wikipedia.org/wiki/A*_search_algorithm
12 |
13 | Now, we are trying to guide a robot which has dimensions, so such robot should avoid obstacles. It would be better if that robot searches a path which is minimum at delta distance from obstacles.
14 |
15 | Input Images
16 |
17 | 
18 |
19 | 
20 |
21 |
22 | A* without applying clearance:
23 |
24 | 
25 |
26 | 
27 |
28 |
29 | For this we preprocess our input images to create clearances for robot.
30 |
31 | 
32 |
33 | 
34 |
35 |
36 |
37 | Now on the basis of these clearnace values, we deviced our cost function as normal distribution of this clearance value.
38 |
39 | After applying A* on these images , we get following output:
40 |
41 | Output Images:
42 |
43 | 
44 |
45 | 
46 |
47 |
48 | As you can see there is change in path followed by A-star. It avoids the obstacle to give shortest-optimal path.
49 |
--------------------------------------------------------------------------------
/WIN_20151203_18_30_01_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/WIN_20151203_18_30_01_Pro.jpg
--------------------------------------------------------------------------------
/a.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/a.txt
--------------------------------------------------------------------------------
/beforeplanningwithclearance/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/1.jpg
--------------------------------------------------------------------------------
/beforeplanningwithclearance/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/2.jpg
--------------------------------------------------------------------------------
/beforeplanningwithclearance/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/3.jpg
--------------------------------------------------------------------------------
/beforeplanningwithclearance/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/4.jpg
--------------------------------------------------------------------------------
/beforeplanningwithclearance/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/5.jpg
--------------------------------------------------------------------------------
/beforeplanningwithclearance/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithclearance/6.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/1.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/2.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/3.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/4.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/5.jpg
--------------------------------------------------------------------------------
/beforeplanningwithoutclearance/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/beforeplanningwithoutclearance/6.jpg
--------------------------------------------------------------------------------
/camera_caliberation.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import cv2
3 | import glob
4 |
5 | # termination criteria
6 | criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
7 |
8 | # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
9 | objp = np.zeros((6*7,3), np.float32)
10 | objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
11 |
12 | # Arrays to store object points and image points from all the images.
13 | objpoints = [] # 3d point in real world space
14 | imgpoints = [] # 2d points in image plane.
15 |
16 | images = glob.glob('*.jpg')
17 |
18 | #cap = cv2.VideoCapture(1)
19 | for im in images:
20 | print im
21 | img = cv2.imread(im)
22 |
23 | # _, img = cap.read()
24 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
25 |
26 | cv2.imshow('image', gray)
27 |
28 | cv2.waitKey(500)
29 |
30 | # Find the chess board corners
31 | ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
32 |
33 | # If found, add object points, image points (after refining them)
34 | if ret == True:
35 | objpoints.append(objp)
36 |
37 | corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
38 | imgpoints.append(corners2)
39 |
40 | # Draw and display the corners
41 | img = cv2.drawChessboardCorners(img, (7,6), corners2,ret)
42 | cv2.imshow('img',img)
43 | cv2.waitKey(500)
44 |
45 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/create_spline.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plt
2 | import scipy as sp
3 | from scipy.interpolate import interp1d
4 | import numpy as np
5 | x = []
6 | y = []
7 |
8 | with open('a.txt', 'r') as fp:
9 | for line in fp:
10 | a, b = line.split()
11 | x.append(int(a))
12 | y.append(int(b))
13 |
14 | print x
15 | print y
16 | points = zip(x, y)
17 |
18 | points = sorted(points, key=lambda point:points[0])
19 |
20 | x, y = zip(*points)
21 |
22 | print x
23 | print y
24 |
25 | length = 100
26 | new_x = np.linspace(min(x), max(x), length)
27 | new_y = interp1d(x, y, kind='cubic')(new_x)
28 | print new_x
29 | print new_y
30 |
31 | plt.plot(x, y, 'o', new_x, new_y, '-')
32 | plt.show()
--------------------------------------------------------------------------------
/feasibility-clearance.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 | import math
6 | import time
7 | import Queue as Q
8 |
9 | class pixel(object):
10 | def __init__(self, penalty, pointx, pointy): # parent is that pixel from which this current pixel is generated
11 | self.penalty = penalty
12 | self.pointx = int(pointx)
13 | self.pointy = int(pointy)
14 |
15 | def __cmp__(self, other): # comparable which will return self.penalty -1 and ny > -1 and nx < ex and ny < ey:
25 | return True
26 | else:
27 | return False
28 |
29 | def fill_clearance(arr,cmax, final_contours): # sx, sy :- source coordinates dx, dy :- destination coordinates
30 | q = Q.PriorityQueue()
31 |
32 | actions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]]
33 | ex, ey, ez = arr.shape
34 | #print ex, ey, ez
35 | min_cost = [[100000 for x in range(ey)] for x in range(ex)]
36 | for cnt in final_contours:
37 | for pts in cnt:
38 | q.put(pixel(0, pts[0, 1], pts[0, 0]))
39 | cnt = 0
40 | cntq = 0
41 | while not q.empty():
42 | p = q.get()
43 | x = int(p.pointx)
44 | y = int(p.pointy)
45 | pen = p.penalty
46 | if p.penalty > cmax:
47 | continue
48 | if min_cost[x][y] <= p.penalty:
49 | continue
50 | min_cost[x][y] = p.penalty
51 |
52 | for i in range(len(actions)):
53 | nx = int(actions[i][0] + x)
54 | ny = int(actions[i][1] + y)
55 | if check_boundaries(ex, ey, nx, ny) == True:
56 | if arr.item(nx, ny, 0) == 0 and arr.item(nx, ny, 1) == 0 and arr.item(nx, ny, 2) == 0:
57 | if min_cost[nx][ny] > penalty(x, y, nx, ny, pen):
58 | q.put(pixel(penalty(x,y,nx,ny,pen), nx, ny))
59 | return min_cost
60 |
61 | def main():
62 | for im in images:
63 |
64 | img = cv2.imread(im)
65 |
66 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
67 | img2 = cv2.medianBlur(cimg,13)
68 |
69 | ret,thresh1 = cv2.threshold(cimg,40,255,cv2.THRESH_BINARY)
70 | t2 = copy.copy(thresh1)
71 |
72 | x, y = thresh1.shape
73 | arr = np.zeros((x, y, 3), np.uint8)
74 | final_contours= []
75 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
76 | for i in range(len(contours)):
77 | cnt = contours[i]
78 | if cv2.contourArea(cnt) > 300 and cv2.contourArea(cnt) < 5000 :
79 | cv2.drawContours(img, [cnt],-1, [0, 255, 255])
80 | cv2.fillConvexPoly(arr, cnt, [255, 255, 255])
81 | final_contours.append(cnt)
82 | cmax = 50
83 | start = time.clock()
84 | min_cost = fill_clearance(arr,cmax, final_contours)
85 | print 'time: ', time.clock()-start
86 | for i in xrange(x):
87 | for j in xrange(y):
88 | pix_val = int(5*min_cost[i][j])
89 | if(min_cost[i][j] > 10000):
90 | pix_val = 0
91 | arr[i, j] = (pix_val, pix_val, 0)
92 | for cnt in final_contours:
93 | cv2.fillConvexPoly(arr, cnt, [255, 255, 255])
94 |
95 | cv2.imshow('image', img)
96 | cv2.imshow('arr', arr)
97 | cv2.waitKey(0)
98 | cv2.destroyAllWindows()
99 |
100 | main()
--------------------------------------------------------------------------------
/feasibility_clearance.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 | import math
6 | import time
7 |
8 | def distance (one, point) :
9 | dist = math.hypot(point[0] - one[0], point[1] - one[1])
10 | return dist
11 |
12 | def distFromContour (one, two, point):
13 | y = two[1]-one[1]
14 | x = two[0]-one[0]
15 | vec = np.array([x,y,0])
16 | p1 = np.array([point[0]-one[0],point[1]-one[1],0])
17 | p2 = np.array([point[0]-two[0],point[1]-two[1],0])
18 | pro1 = np.dot(vec,p1)
19 | pro2 = np.dot(vec,p2)
20 | if pro1 > 0 and pro2 > 0 :
21 | return min(distance(one,point),distance(two,point))
22 | elif pro1 < 0 and pro2 < 0:
23 | return min(distance(one,point),distance(two,point))
24 | elif pro1 <= 0 or pro2 <= 0:
25 | result = (point[0]*y - point[1]*x + one[1]*x - one[0]*y)/((x**2 + y**2)**0.5)
26 | if result < 0 :
27 | result *= -1
28 | return result
29 |
30 |
31 | images = glob.glob('*.jpg')
32 |
33 | for im in images:
34 | img = cv2.imread(im)
35 |
36 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
37 | img2 = cv2.medianBlur(cimg,13)
38 |
39 | ret,thresh1 = cv2.threshold(cimg,40,255,cv2.THRESH_BINARY)
40 | t2 = copy.copy(thresh1)
41 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
42 | #cv2.drawContours(img, contours, -1, (0,255,0), 3)
43 |
44 | x, y = thresh1.shape
45 | final_contours = []
46 | # print x, y
47 | for i in range(len(contours)):
48 | cnt = contours[i]
49 | if cv2.contourArea(cnt) > 300 and cv2.contourArea(cnt) < 5000:
50 | final_contours.append(cnt)
51 | arr = np.zeros((x, y, 3), np.uint8)
52 | # print arr.shape
53 | # finalarr = [[10000 for p in range(y)] for p in range(x)]
54 | finalimg = np.zeros((x, y, 3), np.uint8)
55 | # print finalimg.shape
56 | # print len(finalarr)
57 | max_dist = 0
58 | s = time.clock()
59 | for j in xrange(x):
60 | for k in xrange(y):
61 | dist = 1000
62 | for i in range(len(final_contours)):
63 | cnt = final_contours[i]
64 | hull = cv2.convexHull(cnt, clockwise=True, returnPoints= True)
65 | #print len(hull)
66 | cv2.fillConvexPoly(arr, hull, [255, 255, 255])
67 | for i in range(len(hull)):
68 | # print hull[i]
69 | start = tuple(hull[i, 0])
70 | end = tuple(hull[(i+1) % len(hull), 0])
71 | cv2.line(img, start, end, [0, 255, 0], 1)
72 |
73 | val = distFromContour(start,end,[k,j])
74 | if val < dist:
75 | dist = val
76 | if dist > max_dist:
77 | max_dist = dist
78 | print max_dist
79 | if arr[j][k][0] != 255:
80 | finalimg[j][k] = (round(dist * 0.8), round(dist * 0.8), round(dist * 0.8))
81 | print 'time: ', time.clock()-s
82 |
83 | print max_dist
84 | cv2.imshow('image',img)
85 | cv2.imshow('image2', arr)
86 | # image = np.zeros((x, y,3), np.uint8)
87 |
88 | cv2.imshow('imag',finalimg)
89 | cv2.waitKey(0)
90 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/images/WIN_20151203_18_22_30_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_22_30_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_22_59_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_22_59_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_23_11_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_23_11_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_23_30_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_23_30_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_23_37_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_23_37_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_23_46_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_23_46_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_24_13_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_24_13_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_24_59_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_24_59_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_25_06_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_25_06_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_25_10_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_25_10_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_25_14_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_25_14_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_25_20_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_25_20_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_25_36_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_25_36_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_26_48_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_26_48_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_26_52_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_26_52_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_26_55_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_26_55_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_26_58_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_26_58_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_27_02_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_27_02_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_27_10_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_27_10_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_27_19_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_27_19_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_28_49_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_28_49_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_28_52_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_28_52_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_28_55_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_28_55_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_28_57_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_28_57_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_29_19_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_29_19_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_29_29_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_29_29_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_29_43_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_29_43_Pro.jpg
--------------------------------------------------------------------------------
/images/WIN_20151203_18_30_01_Pro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/images/WIN_20151203_18_30_01_Pro.jpg
--------------------------------------------------------------------------------
/obstacle_detection.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 |
6 | def crossProduct(one, two, point):
7 | y = two[1]-one[1]
8 | x = two[0]-one[0]
9 | vec = np.array([x,y,0])
10 | p = np.array([point[0]-one[0],point[1]-one[1],0])
11 | pro = np.cross(vec,p)
12 | if pro[2] < 0 :
13 | return -1
14 | elif pro[2] == 0:
15 | return -1
16 | else :
17 | return 1
18 |
19 | images = glob.glob('*.jpg')
20 |
21 | for im in images:
22 | img = cv2.imread(im)
23 |
24 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
25 | img2 = cv2.medianBlur(cimg,13)
26 |
27 | ret,thresh1 = cv2.threshold(cimg,40,255,cv2.THRESH_BINARY)
28 | t2 = copy.copy(thresh1)
29 | th3 = cv2.adaptiveThreshold(img2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
30 | cv2.THRESH_BINARY,11,2)
31 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
32 | #cv2.drawContours(img, contours, -1, (0,255,0), 3)
33 |
34 | x, y , z = img.shape
35 |
36 | print x, y, z
37 |
38 | arr = np.zeros((x, y, z), np.uint8)
39 | final_contours = []
40 | for i in range(len(contours)):
41 | cnt = contours[i]
42 | if cv2.contourArea(cnt) > 1000 and cv2.contourArea(cnt) < 7000:
43 | final_contours.append(cnt)
44 | hull = cv2.convexHull(cnt, clockwise=True, returnPoints= True)
45 | #defects = cv2.convexityDefects(cnt, hull)
46 | #for i in range(defects.shape[0]):
47 | # s,e,f,d = defects[i,0]
48 | # start = tuple(cnt[s][0])
49 | # end = tuple(cnt[e][0])
50 | for i in range(len(hull)):
51 | print hull[i]
52 | start = tuple(hull[i, 0])
53 | end = tuple(hull[(i+1) % len(hull), 0])
54 | cv2.line(img, start, end, [0, 255, 0], 1)
55 |
56 | # cv2.imshow('image',img)
57 | # cv2.waitKey(0)
58 |
59 | for j in range(y):
60 | for k in range(x):
61 | pnt = [k, j]
62 | # print pnt
63 | for i in xrange(len(final_contours)):
64 | cnt = final_contours[i]
65 | hull = cv2.convexHull(cnt,clockwise=True ,returnPoints = True)
66 | # defects = cv2.convexityDefects(cnt,hull)
67 | # s,e,f,d = defects[0,0]
68 | start = tuple(hull[0, 0])
69 | end = tuple(hull[1, 0])
70 | sign = crossProduct(start, end, pnt)
71 |
72 | flag = False
73 | for i in range(len(hull)):
74 | # s,e,f,d = defects[i,0]
75 | start = tuple(hull[i, 0])
76 | end = tuple(hull[(i+1) % len(hull), 0])
77 | sign1 = crossProduct(start, end, pnt)
78 | # cv2.line(img,start,end,[0,255,0],1)
79 | if sign1 != sign:
80 | flag = True
81 | break
82 |
83 | if flag == False:
84 | arr[j, k] = (255, 255, 255)
85 | continue;
86 |
87 | # d = crossProduct(a,b,p)
88 | # print d
89 |
90 | cv2.imshow('image',img)
91 | cv2.imshow('image2', arr)
92 |
93 | cv2.waitKey(0)
94 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/obstacle_detection2.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 |
6 | def crossProduct(one, two, point):
7 | y = two[1]-one[1]
8 | x = two[0]-one[0]
9 | vec = np.array([x,y,0])
10 | p = np.array([point[0]-one[0],point[1]-one[1],0])
11 | pro = np.cross(vec,p)
12 | if pro[2] < 0 :
13 | return -1
14 | elif pro[2] == 0:
15 | return -1
16 | else :
17 | return 1
18 |
19 | images = glob.glob('*.jpg')
20 |
21 | for im in images:
22 | img = cv2.imread(im)
23 |
24 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
25 | img2 = cv2.medianBlur(cimg,13)
26 |
27 | ret,thresh1 = cv2.threshold(cimg,40,255,cv2.THRESH_BINARY)
28 | t2 = copy.copy(thresh1)
29 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
30 | #cv2.drawContours(img, contours, -1, (0,255,0), 3)
31 |
32 | x, y = thresh1.shape
33 |
34 | # print x, y
35 |
36 | arr = np.zeros((x, y, 3), np.uint8)
37 | final_contours = []
38 | for i in range(len(contours)):
39 | cnt = contours[i]
40 | if cv2.contourArea(cnt) > 1000 and cv2.contourArea(cnt) < 7000:
41 | final_contours.append(cnt)
42 | hull = cv2.convexHull(cnt, clockwise=True, returnPoints= True)
43 | print hull
44 | break
45 | for i in range(len(hull)):
46 | # print hull[i]
47 | start = tuple(hull[i, 0])
48 | end = tuple(hull[(i+1) % len(hull), 0])
49 | cv2.line(img, start, end, [0, 255, 0], 1)
50 | cv2.fillConvexPoly(arr, hull, [255, 255, 255])
51 |
52 |
53 | cv2.imshow('image',img)
54 | cv2.imshow('image2', arr)
55 |
56 | cv2.waitKey(0)
57 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/output/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/1.jpg
--------------------------------------------------------------------------------
/output/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/2.jpg
--------------------------------------------------------------------------------
/output/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/3.jpg
--------------------------------------------------------------------------------
/output/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/4.jpg
--------------------------------------------------------------------------------
/output/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/5.jpg
--------------------------------------------------------------------------------
/output/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/output/6.jpg
--------------------------------------------------------------------------------
/speech.py:
--------------------------------------------------------------------------------
1 | import string
2 | import speech
3 |
4 | while True:
5 | print "Talk:"
6 | phrase = speech.input()
7 | speech.say("You said %s" % phrase)
8 | print "You said {0}".format(phrase)
9 | #if phrase == "turn off":
10 | if phrase.lower() == "goodbye":
11 | break
--------------------------------------------------------------------------------
/test.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 |
4 |
5 | cap = cv2.VideoCapture(1)
6 |
7 | def nothing(x):
8 | pass
9 | # Creating a window for later use
10 | cv2.namedWindow('result')
11 |
12 | # Starting with 100's to prevent error while masking
13 | h,s,v = 100,100,100
14 |
15 | # Creating track bar
16 | cv2.createTrackbar('h', 'result',0,179,nothing)
17 | cv2.createTrackbar('s', 'result',0,255,nothing)
18 | cv2.createTrackbar('v', 'result',0,255,nothing)
19 |
20 | while(1):
21 |
22 | _, frame = cap.read()
23 |
24 | #converting to HSV
25 | hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
26 |
27 | # get info from track bar and appy to result
28 | h = cv2.getTrackbarPos('h','result')
29 | s = cv2.getTrackbarPos('s','result')
30 | v = cv2.getTrackbarPos('v','result')
31 |
32 | # Normal masking algorithm
33 | lower_blue = np.array([h,s,v])
34 | upper_blue = np.array([h+20,s+140,255])
35 |
36 | mask = cv2.inRange(hsv,lower_blue, upper_blue)
37 |
38 | result = cv2.bitwise_and(frame,frame,mask = mask)
39 |
40 | cv2.imshow('result',result)
41 | k = cv2.waitKey(5) & 0xFF
42 | if k == 27:
43 | break
44 |
45 | cap.release()
46 |
47 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/test2.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import time
5 | from datetime import datetime
6 |
7 |
8 |
9 | cap = cv2.VideoCapture(1)
10 |
11 | def nothing(x):
12 | pass
13 | # Creating a window for later use
14 | cv2.namedWindow('AFTER HSV FILTERING')
15 |
16 | # Starting with 100's to prevent error while masking
17 | h,s,v = 110,40,0
18 |
19 | # Creating track bar
20 | cv2.createTrackbar('h', 'AFTER HSV FILTERING',0,179,nothing)
21 | cv2.createTrackbar('s', 'AFTER HSV FILTERING',0,255,nothing)
22 | cv2.createTrackbar('v', 'AFTER HSV FILTERING',0,255,nothing)
23 |
24 | while(1):
25 | # time.sleep(0.2)
26 | _, frame = cap.read()
27 | frame1 = copy.copy(frame)
28 |
29 | #converting to HSV
30 | hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
31 |
32 | # get info from track bar and appy to result
33 | h = cv2.getTrackbarPos('h','AFTER HSV FILTERING')
34 | s = cv2.getTrackbarPos('s','AFTER HSV FILTERING')
35 | v = cv2.getTrackbarPos('v','AFTER HSV FILTERING')
36 |
37 | # Normal masking algorithm
38 | lower_blue = np.array([h,s,v])
39 | upper_blue = np.array([h + 20,s + 140,255])
40 |
41 | mask = cv2.inRange(hsv,lower_blue, upper_blue)
42 |
43 | result = cv2.bitwise_and(frame,frame,mask = mask)
44 | blur = cv2.blur(result,(5,5))
45 |
46 | bw = cv2.cvtColor(blur,cv2.COLOR_HSV2BGR)
47 | bw2 = cv2.cvtColor(bw,cv2.COLOR_BGR2GRAY)
48 |
49 | th3 = cv2.adaptiveThreshold(bw2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
50 | cv2.THRESH_BINARY,11,2)
51 | #edges = cv2.Canny(th3,100,200)
52 | th4 = copy.copy(th3)
53 |
54 |
55 |
56 | image, contours, hierarchy = cv2.findContours(th4,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
57 | print len(contours)
58 | cv2.imshow('AFTER HSV FILTERING',blur)
59 | cv2.imshow('REAL IMAGE',image)
60 | cv2.imshow('FINAL IMAGE AFTER THRESHOLDING',th3)
61 | #cnt = contours[4]
62 | # perimeter = 0
63 | #j = 0;
64 | #for i in xrange(len(contours)):
65 | # if(perimeter < cv2.arcLength(contours[i], True)):
66 | # perimeter = cv2.arcLength(contours[i], True)
67 | # j = i;
68 | epsilon = 0.1*cv2.arcLength(contours,True)
69 | approx = cv2.approxPolyDP(contours,epsilon,True)
70 | cv2.drawContours(frame1, epsilon, -1, (0, 255, 0), 3)
71 | cv2.imshow('Countours', frame1)
72 |
73 | k = cv2.waitKey(5) & 0xFF
74 | if k == 27:
75 | break
76 |
77 | cap.release()
78 |
79 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/test3.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import time
5 |
6 |
7 |
8 | cap = cv2.VideoCapture(0)
9 | h1 = 10
10 | s1 = 140
11 | v1 = 0
12 | def nothing(x):
13 | pass
14 | # Creating a window for later use
15 | cv2.namedWindow('AFTER HSV FILTERING')
16 |
17 | # Starting with 100's to prevent error while masking
18 | h,s,v = 100,100,100
19 |
20 | # Creating track bar
21 | cv2.createTrackbar('h', 'AFTER HSV FILTERING',0,179-h1,nothing)
22 | cv2.createTrackbar('s', 'AFTER HSV FILTERING',0,255-s1,nothing)
23 | cv2.createTrackbar('v', 'AFTER HSV FILTERING',0,255-v1,nothing)
24 |
25 |
26 | while(1):
27 | time.sleep(0.1)
28 | _, frame = cap.read()
29 |
30 | #converting to HSV
31 | hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
32 |
33 | # get info from track bar and appy to result
34 | h = cv2.getTrackbarPos('h','AFTER HSV FILTERING')
35 | s = cv2.getTrackbarPos('s','AFTER HSV FILTERING')
36 | v = cv2.getTrackbarPos('v','AFTER HSV FILTERING')
37 |
38 | # Normal masking algorithm
39 | lower_blue = np.array([h,s,v])
40 | upper_blue = np.array([h + h1,s + s1,255])
41 |
42 | mask = cv2.inRange(hsv,lower_blue, upper_blue)
43 |
44 | result = cv2.bitwise_and(frame,frame,mask = mask)
45 | #cv2.imshow('mask', mask)
46 | #k = cv2.waitKey(0)
47 | blur = cv2.blur(result,(5,5))
48 |
49 | bw = cv2.cvtColor(blur,cv2.COLOR_HSV2BGR)
50 | bw2 = cv2.cvtColor(bw,cv2.COLOR_BGR2GRAY)
51 | ret,th3 = cv2.threshold(bw2,30,255,cv2.THRESH_BINARY)
52 | #th3 = cv2.adaptiveThreshold(bw2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
53 | #cv2.THRESH_BINARY,11,2)
54 | edges = cv2.Canny(th3,100,200)
55 | th4 = copy.copy(th3)
56 |
57 | perimeter = 0
58 | j = 0
59 | image, contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
60 | # print len(contours)
61 | # if(len(contours) > 5):
62 | # continue
63 | cnt = np.array([])
64 | for i in range(len(contours)):
65 | if(perimeter < cv2.contourArea(contours[i])):
66 | perimeter = cv2.contourArea(contours[i])
67 | j = i;
68 | cnt = contours[j]
69 | if(len(cnt) == 0):
70 | continue
71 | cv2.drawContours(frame, cnt, -1, (0,255,0), 3)
72 | #ellipse = cv2.fitEllipse(cnt)
73 | #frame = cv2.ellipse(frame,ellipse,(0,0,255),2)
74 |
75 | #(x,y),(MA,ma),angle = cv2.fitEllipse(cnt)
76 | #print angle
77 |
78 | hull = cv2.convexHull(cnt,returnPoints = False)
79 | defects = cv2.convexityDefects(cnt,hull)
80 | d1 = 0
81 | p1 = []
82 |
83 | s,e,f,d = defects[0,0]
84 | start = tuple(cnt[s][0])
85 | cv2.circle(frame, start, 5, [255, 0, 0], -1)
86 | for i in range(defects.shape[0]):
87 | s,e,f,d = defects[i,0]
88 | start = tuple(cnt[s][0])
89 | end = tuple(cnt[e][0])
90 | far = tuple(cnt[f][0])
91 | dist = d
92 | if dist > d1:
93 | d1 = dist
94 | p1 = far
95 | cv2.line(frame,start,end,[0,0,0],2)
96 |
97 | if len(p1)> 0:
98 | cv2.circle(frame, p1, 5, [0, 255, 255], -1)
99 |
100 | #draw end points
101 |
102 | leftmost = tuple(cnt[cnt[:,:,0].argmin()][0])
103 | rightmost = tuple(cnt[cnt[:,:,0].argmax()][0])
104 | topmost = tuple(cnt[cnt[:,:,1].argmin()][0])
105 | bottommost = tuple(cnt[cnt[:,:,1].argmax()][0])
106 | cv2.circle(frame, leftmost, 5, [0,0, 255], -1)
107 | cv2.circle(frame, rightmost, 5, [0, 0, 255], -1)
108 | cv2.circle(frame, bottommost, 5, [0, 0, 255], -1)
109 | cv2.circle(frame, topmost, 5, [0, 0, 255], -1)
110 | #cv2.circle(frame, p2, 5, [0, 255, 255], -1)
111 | cv2.imshow('AFTER HSV FILTERING',blur)
112 | cv2.imshow('REAL IMAGE',frame)
113 | cv2.imshow('FINAL IMAGE AFTER THRESHOLDING',bw2)
114 | k = cv2.waitKey(5) & 0xFF
115 | if k == 27:
116 | break
117 |
118 | cap.release()
119 |
120 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/test4.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import time
5 | import math
6 |
7 | cap = cv2.VideoCapture(1)
8 | h1 = 10
9 | s1 = 140
10 | v1 = 0
11 | def nothing(x):
12 | pass
13 | # Creating a window for later use
14 | cv2.namedWindow('AFTER HSV FILTERING')
15 |
16 | h,s,v = 103,40,50
17 |
18 | while(1):
19 | time.sleep(0.5)
20 | _, frame = cap.read()
21 |
22 | #converting to HSV
23 | hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
24 |
25 | # Normal masking algorithm
26 | lower_blue = np.array([h,s,v])
27 | upper_blue = np.array([h + h1,s + s1,255])
28 |
29 | mask = cv2.inRange(hsv,lower_blue, upper_blue)
30 |
31 | result = cv2.bitwise_and(frame,frame,mask = mask)
32 | blur = cv2.blur(result,(5,5))
33 |
34 | bw = cv2.cvtColor(blur,cv2.COLOR_HSV2BGR)
35 | bw2 = cv2.cvtColor(bw,cv2.COLOR_BGR2GRAY)
36 | ret,th3 = cv2.threshold(bw2,30,255,cv2.THRESH_BINARY)
37 |
38 | edges = cv2.Canny(th3,100,200)
39 | th4 = copy.copy(th3)
40 |
41 | perimeter = 0
42 | j = 0
43 | image, contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
44 |
45 | cnt = np.array([])
46 | for i in range(len(contours)):
47 | if(perimeter < cv2.contourArea(contours[i])):
48 | perimeter = cv2.contourArea(contours[i])
49 | j = i;
50 | cnt = contours[j]
51 |
52 | (x,y),(MA,ma),angle = cv2.fitEllipse(cnt)
53 |
54 |
55 | hull = cv2.convexHull(cnt)
56 | avgx, avgy= 0,0
57 | for pts in hull:
58 | avgx += pts.item(0)
59 | avgy += pts.item(1)
60 | avgx /= len(hull)
61 | avgy /= len(hull)
62 |
63 | M = cv2.moments(cnt)
64 | cx = int(M['m10']/M['m00'])
65 | cy = int(M['m01']/M['m00'])
66 | t = (cx, cy)
67 | a = (avgx, avgy)
68 | cv2.circle(frame, t, 5, [0, 0, 255], -1)
69 | cv2.circle(frame, a, 5, [255, 0, 0], -1)
70 | cv2.drawContours(frame, cnt, -1, (0,255,0), 3)
71 |
72 | cv2.imshow('AFTER HSV FILTERING',blur)
73 | cv2.imshow('REAL IMAGE',frame)
74 | cv2.imshow('FINAL IMAGE AFTER THRESHOLDING',bw2)
75 | k = cv2.waitKey(5) & 0xFF
76 | if k == 27:
77 | break
78 |
79 | cap.release()
80 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/test5.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import copy
4 | import glob
5 |
6 | images = glob.glob('*.jpg')
7 |
8 | for im in images:
9 | img = cv2.imread(im)
10 |
11 | cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
12 | img2 = cv2.medianBlur(cimg,13)
13 |
14 | ret,thresh1 = cv2.threshold(cimg,100,120,cv2.THRESH_BINARY)
15 | t2 = copy.copy(thresh1)
16 | th3 = cv2.adaptiveThreshold(img2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
17 | cv2.THRESH_BINARY,11,2)
18 | image, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
19 | #cv2.drawContours(img, contours, -1, (0,255,0), 3)
20 |
21 | for i in xrange(len(contours)):
22 | cnt = contours[i]
23 | if cv2.contourArea(cnt) > 1000 and cv2.contourArea(cnt) < 15000:
24 | cv2.drawContours(img, [cnt],-1, [255, 255, 255])
25 | '''
26 | if cv2.contourArea(cnt) > 0 and cv2.contourArea(cnt) < 10000000:
27 | hull = cv2.convexHull(cnt,returnPoints = False)
28 | defects = cv2.convexityDefects(cnt,hull)
29 |
30 | for i in range(defects.shape[0]):
31 | s,e,f,d = defects[i,0]
32 | start = tuple(cnt[s][0])
33 | end = tuple(cnt[e][0])
34 | cv2.line(img,start,end,[0,255,0],1)
35 | '''
36 |
37 | cv2.imshow('image',img)
38 | cv2.waitKey(0)
39 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/withoutClearance/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/1.jpg
--------------------------------------------------------------------------------
/withoutClearance/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/2.jpg
--------------------------------------------------------------------------------
/withoutClearance/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/3.jpg
--------------------------------------------------------------------------------
/withoutClearance/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/4.jpg
--------------------------------------------------------------------------------
/withoutClearance/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/5.jpg
--------------------------------------------------------------------------------
/withoutClearance/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vampcoder/A-star-planning/6ff447d9ffb6f95cfd908f6b477a44bf8b4b15ac/withoutClearance/6.jpg
--------------------------------------------------------------------------------