Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit d9f209b

Browse files
committed
Minor bug fixes and fix insta360 acc orientation
1 parent 0a90c21 commit d9f209b

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

gyroflow.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ def open_video_func(self):
18561856
path = dialog.selectedFiles()
18571857
if (len(path) == 0 or len(path[0]) == 0):
18581858
print("No file selected")
1859-
return
1859+
return False
18601860
self.infile_path = path[0]
18611861
self.open_vid_button.setText("Video file: {}".format(self.infile_path.split("/")[-1]))
18621862
self.open_vid_button.setStyleSheet("font-weight:bold;")
@@ -1900,8 +1900,8 @@ def open_video_func(self):
19001900
# print("Automatically detected gyro log file: {}".format(self.gyro_log_path.split("/")[-1]))
19011901
# break
19021902

1903-
19041903
self.update_gyro_input_settings()
1904+
return True
19051905

19061906
def video_as_log_func(self):
19071907
self.gyro_log_path = self.infile_path
@@ -2504,9 +2504,9 @@ def open_video_with_player_func(self):
25042504
"""Open file using Qt filedialog
25052505
"""
25062506
self.video_viewer.reset_map_function()
2507-
self.open_video_func()
2508-
self.video_viewer.set_video_path(self.infile_path)
2509-
self.video_viewer.next_frame()
2507+
if self.open_video_func():
2508+
self.video_viewer.set_video_path(self.infile_path)
2509+
self.video_viewer.next_frame()
25102510

25112511
def set_player_video(self):
25122512
self.video_viewer.set_video_path(self.infile_path)
@@ -2606,7 +2606,7 @@ def main():
26062606
if __name__ == "__main__":
26072607
main()
26082608
# Pack to exe using:
2609-
# pyinstaller gyroflow.py --add-binary <path-to-python>\Python38\Lib\site-packages\cv2\opencv_videoio_ffmpeg430_64.dll
2609+
# pyinstaller gyroflow.py --add-binary <path-to-python>\Python38\Lib\site-packages\cv2\opencv_videoio_ffmpeg430_64.dll -F
26102610
# in my case:
26112611
# pyside2-rcc images.qrc -o bundled_images.py
26122612
# poetry run pyinstaller -F --icon=media\icon.ico gyroflow.py --add-binary C:\Users\elvin\AppData\Local\Programs\Python\Python38\Lib\site-packages\cv2\opencv_videoio_ffmpeg440_64.dll;.

gyrolog.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,17 @@ def apply_inverse_rotation(self, rotmat):
373373
def plot_gyro(self):
374374
xplot = plt.subplot(311)
375375

376-
plt.plot(self.gyro[:,0], self.gyro[:,1])
376+
plt.plot(self.standard_gyro[:,0], self.standard_gyro[:,1])
377377
plt.ylabel("omega x [rad/s]")
378378

379379
plt.subplot(312, sharex=xplot)
380380

381-
plt.plot(self.gyro[:,0], self.gyro[:,2])
381+
plt.plot(self.standard_gyro[:,0], self.standard_gyro[:,2])
382382
plt.ylabel("omega y [rad/s]")
383383

384384
plt.subplot(313, sharex=xplot)
385385

386-
plt.plot(self.gyro[:,0], self.gyro[:,3])
386+
plt.plot(self.standard_gyro[:,0], self.standard_gyro[:,3])
387387
#plt.plot(self.integrator.get_raw_data("t") + d2, self.integrator.get_raw_data("z"))
388388
plt.xlabel("time [s]")
389389
plt.ylabel("omega z [rad/s]")
@@ -394,26 +394,26 @@ def plot_acc(self):
394394
if type(self.acc) != type(None):
395395
xplot = plt.subplot(411)
396396

397-
plt.plot(self.acc[:,0], self.acc[:,1])
397+
plt.plot(self.standard_acc[:,0], self.standard_acc[:,1])
398398
plt.ylabel("acc x [g]")
399399

400400
plt.subplot(412, sharex=xplot)
401401

402-
plt.plot(self.acc[:,0], self.acc[:,2])
402+
plt.plot(self.standard_acc[:,0], self.standard_acc[:,2])
403403
plt.ylabel("acc y [g]")
404404

405405
plt.subplot(413, sharex=xplot)
406406

407-
plt.plot(self.acc[:,0], self.acc[:,3])
407+
plt.plot(self.standard_acc[:,0], self.standard_acc[:,3])
408408
#plt.plot(self.integrator.get_raw_data("t") + d2, self.integrator.get_raw_data("z"))
409409
plt.xlabel("time [s]")
410410
plt.ylabel("acc z [g]")
411411

412412
plt.subplot(414, sharex=xplot)
413413

414-
plt.plot(self.acc[:,0], np.sqrt(np.sum(self.acc[:,1:]**2,1)))
415-
plt.plot([0, self.acc[-1,0]], [1.1,1.1])
416-
plt.plot([0, self.acc[-1,0]], [0.9,0.9])
414+
plt.plot(self.standard_acc[:,0], np.sqrt(np.sum(self.standard_acc[:,1:]**2,1)))
415+
plt.plot([0, self.standard_acc[-1,0]], [1.1,1.1])
416+
plt.plot([0, self.standard_acc[-1,0]], [0.9,0.9])
417417
#plt.plot(self.integrator.get_raw_data("t") + d2, self.integrator.get_raw_data("z"))
418418
plt.xlabel("time [s]")
419419
plt.ylabel("mag [g]")
@@ -756,8 +756,8 @@ def __init__(self):
756756
self.filename_pattern = "(?i).*\.mp4"
757757

758758
self.variants = {
759-
"smo4k": [0],
760-
"insta360 oner": [0]
759+
"smo4k": [22],
760+
"insta360 oner": [22]
761761
}
762762

763763
self.variant = "smo4k"
@@ -783,19 +783,19 @@ def guess_log_from_videofile(self, videofile):
783783
def extract_log_internal(self, filename):
784784

785785
if self.variant=="smo4k":
786-
gyro_data_input, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[])
786+
self.gyro, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[])
787787
elif self.variant=="insta360 oner":
788-
gyro_data_input, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[], revertIMU=False)
788+
self.gyro, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[], revertIMU=False)
789789
else:
790790
# Assume SMO4K - For no real reason....
791-
gyro_data_input, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[])
791+
self.gyro, self.acc = insta360_util.get_insta360_gyro_data(filename, filterArray=[])
792792

793793
# Coverting gyro to XYZ to -Z,-X,Y
794-
self.gyro = np.empty([len(gyro_data_input), 4])
795-
self.gyro[:,0] = gyro_data_input[:,0][:]
796-
self.gyro[:,1] = gyro_data_input[:,2][:] * -1
797-
self.gyro[:,2] = gyro_data_input[:,3][:]
798-
self.gyro[:,3] = gyro_data_input[:,1][:] * -1
794+
#self.gyro = np.empty([len(gyro_data_input), 4])
795+
#self.gyro[:,0] = gyro_data_input[:,0][:]
796+
#self.gyro[:,1] = gyro_data_input[:,2][:] * -1
797+
#self.gyro[:,2] = gyro_data_input[:,3][:]
798+
#self.gyro[:,3] = gyro_data_input[:,1][:] * -1
799799

800800
return True
801801

@@ -999,20 +999,30 @@ def extract_log_internal(self, filename):
999999

10001000
#print(tscale, gscale, ascale)
10011001

1002+
1003+
header = line.split(",")
1004+
header_length = len(header)
1005+
1006+
has_gyro = "gx" in header
1007+
has_acc = "ax" in header
1008+
has_mag = "mx" in header
1009+
1010+
10021011
# Get data
10031012
lines = csvfile.readlines()
10041013

10051014
data_list = []
10061015

10071016
for line in lines:
10081017
splitdata = [float(x) for x in line.split(",")]
1009-
t = splitdata[0] * tscale
1018+
if len(splitdata) == header_length: # make sure no missing fields
1019+
t = splitdata[0] * tscale
10101020

1011-
gx = splitdata[1] * gscale
1012-
gy = splitdata[2] * gscale
1013-
gz = splitdata[3] * gscale
1021+
gx = splitdata[1] * gscale
1022+
gy = splitdata[2] * gscale
1023+
gz = splitdata[3] * gscale
10141024

1015-
data_list.append([t, gx, gy, gz])
1025+
data_list.append([t, gx, gy, gz])
10161026

10171027
self.gyro = np.array(data_list)
10181028

@@ -1155,6 +1165,7 @@ def guess_log_type_from_log(logfile, check_data = False):
11551165
#"test_clips/DJIG0043wiebe.mp4",
11561166
#"test_clips/GX016015.MP4",
11571167
#"test_clips/nivim_insta360.mp4",
1168+
"test_clips/smo4k_calibration.mp4",
11581169
"test_clips/Tiago_Ferreira_5_inch.mp4",
11591170
"test_clips/MasterTim17_caddx.mp4",
11601171
"test_clips/starling2.MOV",

insta360_utility.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def get_insta360_gyro_data(path, filterArray=[[1, 0.35], [1,0.04]], revertIMU=Tr
1515
if revertIMU is not True:
1616
gyro_data[:,1] = gyro_data[:,1]*-1
1717
gyro_data[:,3] = gyro_data[:,3]*-1
18+
acc_data[:,1] = acc_data[:,1]*-1
1819
acc_data[:,3] = acc_data[:,3]*-1
1920

2021
fin.close()
@@ -99,7 +100,7 @@ def __parseAccRecord(fin, size):
99100
tm = float(timecode/1000)
100101
d_times.append(tm)
101102
d_gyros.append((tm, -gyroRoll, gyroPitch, -gyroYaw))
102-
d_acc.append((tm, accRoll, accPitch, -accYaw))
103+
d_acc.append((tm, -accRoll, accPitch, -accYaw))
103104
return np.array(d_times), np.array(d_gyros), np.array(d_acc)
104105

105106
def __arrayLowPassFilter(array, orderOfFilter, criticalFrequency):

0 commit comments

Comments
 (0)