-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample code testing.py
More file actions
191 lines (163 loc) · 3.97 KB
/
Copy pathsample code testing.py
File metadata and controls
191 lines (163 loc) · 3.97 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
"""
import pandas as pd
import matplotlib.pyplot as plt
file=pd.read_csv("F:\\summer project\\image processing\\Trajectories_only_crop_new"+"\\"+"newringcrp"+str(40)+".txt")
frame=file["frame_no"]
x=file["x"]
plt.plot(frame,x)
plt.show()
"""
#CURVE FIT AND AVERAGING METHOD
import cv2
"""
from matplotlib import pyplot as plt
import numpy as np
x=[i for i in range(1,22)]
y=[1,2,3,4,5,6,7,8,9,10,11,11,9,8,7,6,5,4,3,2,1]
xnew=np.linspace(1,22,220)
maxima=max(y)
max_loc=y.index(maxima)
max_points=[]
for i in range(max_loc-5,max_loc+5):
if y[i]==maxima:
max_points.append(i)
print(max_points)
print(np.mean(max_points))
curve=np.polyfit(x,y,5) #return coeff of polynomial
poly=np.poly1d(curve)
print(poly(x))
print(max(poly(xnew)))
plt.scatter(x,y)
plt.plot(xnew,poly(xnew),color="r")
plt.plot()
plt.show()
"""
"""
import matplotlib.pyplot as plt
a=[1.05671771e+04,7.90383583e+03,1.15053737e+04,2.69238158e+04,4.01654871e+04,3.00164875e+04,8.47225375e+03,1.84213250e+03,
5.56397792e+03 ,6.76030667e+03, 2.54727708e+03,-1.21161500e+03
]
b=[i for i in range(len(a))]
plt.plot(b,a)
plt.show()
import cv2
import numpy as np
import pandas as pd
"""
import pandas as pd
img=cv2.imread("F:\\summer project\\image processing\\Frame operations"+"\\"+"frame0"+".jpg")
cv2.namedWindow("img",cv2.WINDOW_NORMAL)
for i in range(0,175): # i as ring index
file = pd.read_csv("F:\\summer project\\image processing\\Trajectories_only_crop_new\\newringcrp"+str(i)+".txt")
frames_count=file.shape[0] # no. of frames data in a typical ring txt file
x0 = file["x"]
y0 = file["y"]
a = 80
b = 18
cv2.circle(img,(int(x0[0]),int(y0[0])),3,(0,0,255),-1)
cv2.putText(img,str(i),(int(x0[0]),int(y0[0])),cv2.FONT_ITALIC,1,(0,255,0),2)
cv2.imshow("img",img)
cv2.imwrite("index_of_rings.jpg",img)
cv2.waitKey()
#matrix operations
"""
import cv2
import numpy as np
a=np.array([35,9,65,49,36,45,87,91,24,39,56,98])
a=a.reshape(3,4)
print(a)
maxloc=np.where(a==np.max(a))
y=int(maxloc[0]+1)
x=int(maxloc[1]+1)
print(y,x)
corr_offset=[y-a.shape[0],x-a.shape[1]]
print(corr_offset)
"""
#ROTATE THE IMAGE
"""
import cv2
import numpy as np
img=cv2.imread("messi5.jpg")
#imgr=cv2.rotate(img,rotateCode=2)
h,w,c=img.shape
matrix=cv2.getRotationMatrix2D((int(w/2),int(h/2)),45,1.0)
rotated=cv2.warpAffine(img,matrix,(w,h))
cv2.imshow("rotator",rotated)
cv2.waitKey(0)
"""
#HSV COLOR RANGE USAGE FAILED
"""
import cv2
import numpy as np
cv2.namedWindow("crop")
img=cv2.imread("desired area.jpg")
lblue=np.array([110,50,50])
hblue=np.array([130,255,255])
mask=cv2.inRange(img,lblue,hblue)
cv2.imshow("crop",mask)
cv2.waitKey()
"""
#Approach second continued
"""
import cv2
import numpy as np
img=cv2.imread("desired area.jpg")
grey=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
_,th=cv2.threshold(grey,127,255,cv2.THRESH_BINARY)
morph=cv2.morphologyEx(th,cv2.MORPH_OPEN,())
cv2.imshow("img",img)
cv2.waitKey()
cv2.destroyAllWindows()
"""
""" #nested for loop approach
import cv2
import numpy as np
cv2.namedWindow("crop")
img=cv2.imread("3500cropped.jpg")
h=img.shape[0]
w=img.shape[1]
pts=[(50,50),(100,150),(200,50),(300,30)]
pts=np.array(pts)
img=cv2.polylines(img,[pts],True,(0,255,0),2)
img_pts=[]
for x in range(w):
for y in range(h):
dist = cv2.pointPolygonTest(pts, (x, y), False)
if dist==1:
img_pts.append(img[y,x])
else:
continue
pixel_pts=np.array(img_pts,dtype=np.uint8)
print(pixel_pts)
cv2.imshow("area",img)
cv2.waitKey()
cv2.destroyAllWindows()
"""
"""
import cv2
import numpy as np
img=cv2.imread("logo.png")
black=np.zeros_like(img)
white=cv2.bitwise_not(black)
sum=cv2.subtract(white, black)
cv2.imshow("sum",sum)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
"""
import random
a=random.randint(1,255)
print(a)
"""
"""
import cv2
import numpy as np
import matplotlib.pyplot as plt
cv2.namedWindow("img",cv2.WINDOW_NORMAL)
img=cv2.imread("3500.jpg")
cnt=np.array([(874,1021),(875,1003),(782,995),(781,1013)])
cv2.polylines(img,[cnt],True,(0,255,0),5)
cv2.imshow("img",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""