|
|
@@ -1,33 +1,46 @@
|
|
1
|
1
|
import os, sys
|
|
2
|
2
|
import pandas as pd
|
|
3
|
|
-import numpy as np
|
|
4
|
|
-sys.path.append('..')
|
|
|
3
|
+sys.path.append('.')
|
|
5
|
4
|
import modules.coordsi as csi
|
|
6
|
5
|
import math
|
|
7
|
6
|
import time
|
|
8
|
7
|
|
|
9
|
|
-# initialize root path
|
|
10
|
|
-root = './List_Data_Call/'
|
|
|
8
|
+def main(input):
|
|
|
9
|
+ if len(input) != 2:
|
|
|
10
|
+ print('Usage: python3 ./scripts/createhandletrace.py <parent path of surgery ID> ')
|
|
|
11
|
+ sys.exit(1)
|
|
|
12
|
+ root = input[1]
|
|
|
13
|
+ summary_1 = csi.summaryOriginCoord(root, camid=1)
|
|
11
|
14
|
|
|
12
|
|
-summary_1 = csi.summaryOriginCoord(root, camid=1)
|
|
|
15
|
+ if not os.path.exists('./handletrace'):
|
|
|
16
|
+ try:
|
|
|
17
|
+ os.makedirs('./handletrace')
|
|
|
18
|
+ except Exception as e:
|
|
|
19
|
+ print(e)
|
|
|
20
|
+ #make a loop for each index
|
|
|
21
|
+ for index, row in summary_1.iterrows():
|
|
|
22
|
+ timestamp = []
|
|
|
23
|
+ start_time = time.time()
|
|
|
24
|
+ df = csi.readCam(os.path.join(index,'cam1.csv'))
|
|
|
25
|
+ df = csi.convertToSI(df, 3.5, 1.5, 3.4)
|
|
|
26
|
+ df = csi.getVelocity(df)
|
|
|
27
|
+ df = csi.getAcceleration(df)
|
|
|
28
|
+ df = csi.getFullTrace(df,row['approx_total_frame'] )
|
|
|
29
|
+ df = csi.addValidDetection(df, 25.0)
|
|
|
30
|
+ try:
|
|
|
31
|
+ df.to_csv(os.path.join('./handletrace/', index[17:]+'.csv'), index=False)
|
|
|
32
|
+ #save spend time and index of summary_1 in timestamp list
|
|
|
33
|
+ timestamp.append([index, time.time() - start_time])
|
|
|
34
|
+ print([index, time.time() - start_time])
|
|
|
35
|
+ except Exception as e:
|
|
|
36
|
+ print(e)
|
|
|
37
|
+ continue
|
|
|
38
|
+ #save timestamp list to csv file
|
|
|
39
|
+ pd.DataFrame(timestamp, columns=['index', 'time']).to_csv('./handletrace/timestamp.csv', index=False)
|
|
13
|
40
|
|
|
14
|
|
-#make a loop for each index
|
|
15
|
|
-for index, row in summary_1.iterrows():
|
|
16
|
|
- timestamp = []
|
|
17
|
|
- start_time = time.time()
|
|
18
|
|
- df = csi.readCam(os.path.join(index,'cam1.csv'))
|
|
19
|
|
- df = csi.convertToSI(df, 3.5, 1.5, 3.4)
|
|
20
|
|
- df = csi.getVelocity(df)
|
|
21
|
|
- df = csi.getAcceleration(df)
|
|
22
|
|
- df = csi.getFullTrace(df,row['approx_total_frame'] )
|
|
23
|
|
- df = csi.addValidDetection(df, 25.0)
|
|
|
41
|
+if __name__ == '__main__':
|
|
24
|
42
|
try:
|
|
25
|
|
- df.to_csv(os.path.join('./handletrace/', index[17:]+'.csv'), index=False)
|
|
26
|
|
- #save spend time and index of summary_1 in timestamp list
|
|
27
|
|
- timestamp.append([index, time.time() - start_time])
|
|
28
|
|
- print([index, time.time() - start_time])
|
|
|
43
|
+ main(sys.argv)
|
|
29
|
44
|
except Exception as e:
|
|
30
|
45
|
print(e)
|
|
31
|
|
- continue
|
|
32
|
|
-#save timestamp list to csv file
|
|
33
|
|
-pd.DataFrame(timestamp, columns=['index', 'time']).to_csv('./handletrace/timestamp.csv', index=False)
|
|
|
46
|
+ sys.exit(1)
|