lily-hust commited on
Commit
57311fa
·
1 Parent(s): a861c23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -30
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
 
3
  #from pandas import DataFrame as df
4
  import csv
 
5
  import math
6
 
7
  def main():
@@ -9,7 +10,7 @@ def main():
9
 
10
  st.markdown('Only support single file conversion at this time. Will be processing batch files in the future. \n')
11
  st.markdown('The input file should be in the format of csv where fields are separated by ";". The output will be also a csv file. \n')
12
- st.markdown('The input field order is\n')
13
  st.markdown('fileID; image file name; time stamp; pose_x; pose_y; pose_z; ori_w; ori_x; ori_y; ori_z.\n')
14
  st.markdown('The unit of the input pos_x, pos_y and pos_z is meter.\n')
15
  st.markdown('The unit of the output pos_x, pos_y and pos_z is feet, and ori_roll, ori_pitch, ori_yaw is degree.\n')
@@ -23,14 +24,12 @@ def euler_from_quaternion(x, y, z, w):
23
  roll_x = math.atan2(t0, t1)
24
 
25
  t2 = +2.0 * (w * y - z * x)
26
- #t2 = +1.0 if t2 > +1.0 else t2
27
- #t2 = -1.0 if t2 < -1.0 else t2
28
  pitch_y = math.asin(t2)
29
 
30
  t3 = +2.0 * (w * z + x * y)
31
  t4 = +1.0 - 2.0 * (y * y + z * z)
32
  yaw_z = math.atan2(t3, t4)
33
- # the y here obvious points to the 90 anticlockwise to x, instead of the general definition of quaternion and Eular angles where y points to 90 degree clockwise to x
34
  return math.degrees(roll_x), -math.degrees(pitch_y), math.degrees(yaw_z) # in degree
35
 
36
  def run_the_app():
@@ -58,38 +57,34 @@ def run_the_app():
58
  writer = csv.DictWriter(wf, fieldnames=fieldnames)
59
  writer.writeheader()
60
 
61
- with open(uploaded_files, 'r', encoding='utf-8') as rf:
62
- reader = csv.DictReader(rf)
63
-
64
- for row in reader:
65
- row_v = list(row.values())[0].split(';')
66
- # in the input file, the quat order is ori_w,ori_x,ori_y,ori_z
67
- roll, pitch, yaw = euler_from_quaternion(float(row_v[7]),
68
- float(row_v[8]),
69
- float(row_v[9]),
70
- float(row_v[6]))
71
 
72
  # now yaw is the angle to x, anticlockwise. But our definition is the angle to y(north), clockwise
73
- yaw = -yaw + 90.0
74
- if yaw < -180.0:
75
- yaw += 360.0
76
- elif yaw > 180.0:
77
- yaw -= 360.0
78
 
79
- rec = {fieldnames[0]: row_v[0],
80
- fieldnames[1]: row_v[1][1:],
81
- fieldnames[2]: row_v[2],
82
- fieldnames[3]: float(row_v[3])*3.28084,
83
- fieldnames[4]: float(row_v[4])*3.28084,
84
- fieldnames[5]: float(row_v[5])*3.28084,
85
- fieldnames[6]: roll,
86
- fieldnames[7]: pitch,
87
- fieldnames[8]: yaw}
88
- writer.writerow(rec)
89
 
90
 
91
 
92
- st.download_button("Download the converted files",
93
  data = "converted.csv")
94
 
95
  if __name__ == "__main__":
 
2
 
3
  #from pandas import DataFrame as df
4
  import csv
5
+ import pandas as pd
6
  import math
7
 
8
  def main():
 
10
 
11
  st.markdown('Only support single file conversion at this time. Will be processing batch files in the future. \n')
12
  st.markdown('The input file should be in the format of csv where fields are separated by ";". The output will be also a csv file. \n')
13
+ st.markdown('The input fields include\n')
14
  st.markdown('fileID; image file name; time stamp; pose_x; pose_y; pose_z; ori_w; ori_x; ori_y; ori_z.\n')
15
  st.markdown('The unit of the input pos_x, pos_y and pos_z is meter.\n')
16
  st.markdown('The unit of the output pos_x, pos_y and pos_z is feet, and ori_roll, ori_pitch, ori_yaw is degree.\n')
 
24
  roll_x = math.atan2(t0, t1)
25
 
26
  t2 = +2.0 * (w * y - z * x)
 
 
27
  pitch_y = math.asin(t2)
28
 
29
  t3 = +2.0 * (w * z + x * y)
30
  t4 = +1.0 - 2.0 * (y * y + z * z)
31
  yaw_z = math.atan2(t3, t4)
32
+
33
  return math.degrees(roll_x), -math.degrees(pitch_y), math.degrees(yaw_z) # in degree
34
 
35
  def run_the_app():
 
57
  writer = csv.DictWriter(wf, fieldnames=fieldnames)
58
  writer.writeheader()
59
 
60
+ df = pd.read_csv(uploaded_files, sep = ';')
61
+ for row in range(df.shape[0]):
62
+ roll, pitch, yaw = euler_from_quaternion(float(df.at[row, ' pano_ori_x']),
63
+ float(df.at[row, ' pano_ori_y']),
64
+ float(df.at[row, ' pano_ori_z']),
65
+ float(df.at[row, ' pano_ori_w']))
 
 
 
 
66
 
67
  # now yaw is the angle to x, anticlockwise. But our definition is the angle to y(north), clockwise
68
+ yaw = -yaw + 90.0
69
+ if yaw < -180.0:
70
+ yaw += 360.0
71
+ elif yaw > 180.0:
72
+ yaw -= 360.0
73
 
74
+ rec = {fieldnames[0]: df.at[row, '# pano poses v1.0: ID'],
75
+ fieldnames[1]: df.at[row, ' filename'][1:],
76
+ fieldnames[2]: df.at[row, ' timestamp'],
77
+ fieldnames[3]: float(df.at[row, ' pano_pos_x'])*3.28084,
78
+ fieldnames[4]: float(df.at[row, ' pano_pos_y'])*3.28084,
79
+ fieldnames[5]: float(df.at[row, ' pano_pos_z'])*3.28084,
80
+ fieldnames[6]: roll,
81
+ fieldnames[7]: pitch,
82
+ fieldnames[8]: yaw}
83
+ writer.writerow(rec)
84
 
85
 
86
 
87
+ st.download_button("Download the converted files",
88
  data = "converted.csv")
89
 
90
  if __name__ == "__main__":