-
Notifications
You must be signed in to change notification settings - Fork 0
/
recordData.py
46 lines (43 loc) · 1.35 KB
/
recordData.py
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
from toolbox.opencvFramework import *
from toolbox.mathUtility import *
def runRecordData(mode:int,matchMethod=0):
camS=CamerSystem()
timer=Timer()
f=open("data.txt", "w")
xposData=[]
timeData=[]
plt.ion()
# plt.figure(1)
while True:
if mode!=3:
frame=None
if mode==1:
frame=camS.ColorThreshold(showSource=True)
elif mode==2:
frame=camS.MotionThreshold()
if frame is None:
break
x, y =camS.GetCenterByLongestContour(img=frame,type=ProcessType.CenterCoordinate,debug=True)
else:
x,y=camS.GetCenterByMatchTemplet(method=matchMethod)
if len(xposData)>1:
if abs(x-xposData[-1])>20:
continue
if x==-1:
break
if not f.writable():
print("File is occupied!Check access!")
timeRecode=timer.TimePast()
f.write(",".join([str(round(i,2)) for i in(x,y,timeRecode)])+"\n")
# xposData.append(x)
# timeData.append(timeRecode)
# plt.plot(np.array(xposData),np.array(timeData))
# plt.draw()
k = cv2.waitKey(int(1000 / camS.getFPS()))
if k == 27:
break
camS.releasCam()
cv2.destroyAllWindows()
f.close()
if __name__ == '__main__':
runRecordData(3)