-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestpath1.py
More file actions
118 lines (91 loc) · 2.48 KB
/
testpath1.py
File metadata and controls
118 lines (91 loc) · 2.48 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
import numpy as np
import cv2
img = cv2.imread(r"C:\Users\Sivasthigan\PycharmProjects\droneproject\1.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, threshold = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
cv2.bitwise_not(threshold, threshold)
contours, hierarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
listx = []
listy = []
point=[]
points = []
lst_sort=[]
value = {}
megalist=[]
lst_coordinates=[]
fx = 0
fy = 0
index=0
w=0
for i in range(0, len(contours)):
c = contours[i]
size = cv2.contourArea(c)
if size > 11:
M = cv2.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
points.append([cX,cY])
cv2.circle(img, (fx, fy), 5, (255, 0, 0), 10)
cv2.circle(img, (cX, cY), 5, (255, 0, 0), 10)
dictlis=[]
for p in range(len(points)):
dictlis.append([p+1,points[p]])
print(dictlis)
for i in range(len(points)):
graph = {}
print('points',points)
print('dictlis',dictlis)
for j in points:
points1 = {}
Pathdistance = np.sqrt((fx-j[0]) ** 2 + (fy - j[1]) ** 2)
#print('2nd time', fx, fy)
#print("fidtance of first path", Pathdistance)
points1['cX']=j[0]
points1['cY']=j[1]
points1['Pathdistance']=Pathdistance
lst_coordinates.append(points1)
#print(points1)
print(lst_coordinates)
#print(points1)
for k in lst_coordinates:
lst_sort.append(k['Pathdistance'])
lst_sort.sort()
max_fp_dstance = min(lst_sort)
#print(lst_sort)
for z in range(len(dictlis)):
graph[str(dictlis[z][0])] =lst_coordinates[z]['Pathdistance']
print('graph',graph)
#megalist.append(graph)
#print('mega',megalist)
x = 0
for t in lst_coordinates:
# xx = i['cX']
# yy = i['cY']
# point.append([xx,yy])
# print(point)
index = index + 1
for k, v in t.items():
if (t[k] == max_fp_dstance):
mX = t['cX']
mY = t['cY']
x = index
break
if (index == x):
break
fx=mX
fy=mY
value[str(w)] = graph
for q in range (len(dictlis)):
if dictlis[q][1]==[fx,fy]:
#q=q+1
#print(q)
w=dictlis[q][0]
print(w)
break
print(fx,fy)
lst_coordinates.clear()
lst_sort.clear()
points.remove([fx,fy])
dictlis.remove([w,[fx,fy]])
#graph.clear()
print(value)