Skip to content

Commit 1adcd62

Browse files
author
arch
committed
add option for muliaxis json output
1 parent 4556c35 commit 1adcd62

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

funscript_editor/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ def main():
99
""" CLI Main Function """
1010
parser = argparse.ArgumentParser()
1111
parser.add_argument("--generator", action = 'store_true', help = "Run only the generator")
12+
parser.add_argument("--multiaxis", action = 'store_true', help = "Show options for multiaxis output")
1213
parser.add_argument("-i", "--input", type = str, help = "Video File")
13-
parser.add_argument("-o", "--output", type = str, default = "/tmp/funscript_actions.csv", help = "Output Path")
14+
parser.add_argument("-o", "--output", type = str, default = "/tmp/funscript_actions.json", help = "Output Path")
1415
parser.add_argument("-s", "--start", type = float, default = 0.0, help = "Start Time in Milliseconds")
1516
parser.add_argument("-e", "--end", type = float, default = -1.0, help = "End/Stop Time in Milliseconds")
1617
args = parser.parse_args()
@@ -19,4 +20,4 @@ def main():
1920
os.environ['PATH'] = os.getcwd() + os.sep + os.environ['PATH']
2021

2122
if not args.generator: show_editor()
22-
else: generate_funscript(args.input, args.start, args.end, args.output)
23+
else: generate_funscript(args.input, args.start, args.end, args.output, args.multiaxis)

funscript_editor/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@ def generate_funscript(
2626
video_file: str,
2727
start_time: float,
2828
end_time :float,
29-
output_file: str) -> None:
29+
output_file: str,
30+
include_multiaxis_options: bool = False) -> None:
3031
""" Generate a funscript with minimal UI
3132
3233
Args:
3334
video_file (str): path to video file
3435
start_time (float): start time in milliseconds
3536
end_time (float): end time in milliseconds (set -1.0 to use video end)
3637
output_file (str): path for the output file
38+
include_multiaxis_options (bool): include options for multiaxis output
3739
"""
3840
setup_logging()
3941
logging.info("Python Funscript Generator %s", VERSION)
4042
logging.info("Startup Path: %s", str(os.getcwd()))
4143
logging.info("Args: video_file=%s, start_time=%s, end_time=%s, output_file=%s", \
4244
str(video_file), str(start_time), str(end_time), str(output_file))
4345
app = QtWidgets.QApplication(sys.argv)
44-
_ = FunscriptGeneratorWindow(video_file, start_time, end_time, output_file)
46+
_ = FunscriptGeneratorWindow(video_file, start_time, end_time, output_file, include_multiaxis_options)
4547
sys.exit(app.exec_())

funscript_editor/config/hyperparameter.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ signal:
2929
high_second_derivative_points_threshold: 1.2
3030

3131
# filter length to detect a direction change
32-
direction_change_filter_len: 4
32+
direction_change_filter_len: 3
3333

3434
# threshold value in milliseconds to merge additional points
35-
additional_points_merge_time_threshold_in_ms: 100
35+
additional_points_merge_time_threshold_in_ms: 70
3636

3737
# threshold value to merge additional points
3838
additional_points_merge_distance_threshold: 10.0

funscript_editor/ui/funscript_generator_window.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import funscript_editor.utils.logging as logging
33
import os
4+
import json
45
import time
56
import platform
67
import cv2
@@ -15,7 +16,7 @@
1516

1617
from PyQt5 import QtCore, QtGui, QtWidgets
1718

18-
USE_OPTICALFLOW = False
19+
USE_OPTICALFLOW = False # Enable some hardcoded optical flow testcode
1920
if USE_OPTICALFLOW:
2021
from funscript_editor.algorithms.opticalflow import OpticalFlowFunscriptGeneratorThread, OpticalFlowFunscriptGeneratorParameter
2122

@@ -44,6 +45,9 @@ def __init__(self,
4445
if os.path.exists(definitions.ICON_PATH):
4546
self.setWindowIcon(QtGui.QIcon(definitions.ICON_PATH))
4647

48+
if include_multiaxis:
49+
self.__logger.info("Enable multiaxis output")
50+
4751
if not isinstance(output_file, Funscript):
4852
output_file = os.path.abspath(output_file)
4953
if os.path.isdir(output_file):
@@ -108,15 +112,34 @@ def __funscript_generated(self, funscripts, msg, success) -> None:
108112
first_metric = [x for x in funscripts.keys()][0]
109113

110114
if isinstance(self.output_file, Funscript):
115+
if len(funscripts) > 1:
116+
self.__logger.warning("Multiaxis output for build-in UI is not implemented")
111117
for item in funscripts[first_metric].get_actions():
112118
self.output_file.add_action(item['pos'], item['at'], SETTINGS['raw_output'])
113119
self.funscriptCompleted.emit(self.output_file, msg, success)
114120
else:
115121
os.makedirs(os.path.dirname(self.output_file), exist_ok=True)
116-
with open(self.output_file, 'w') as f:
117-
f.write('at;pos\n')
118-
for item in funscripts[first_metric].get_actions():
119-
f.write('{at};{pos}\n'.format(at=item['at'], pos=item['pos']))
122+
if self.output_file.lower().endswith('.json'):
123+
funscript_json_output = {
124+
'version': 1,
125+
'actions': {}
126+
}
127+
128+
for key in funscripts.keys():
129+
funscript_json_output['actions'][key] = []
130+
for item in funscripts[key].get_actions():
131+
funscript_json_output['actions'][key].append(item)
132+
133+
with open(self.output_file, 'w') as f:
134+
json.dump(funscript_json_output, f)
135+
else:
136+
# dump to CSV
137+
if len(funscripts) > 1:
138+
self.__logger.warning("Multiaxis output for csv is not implemented")
139+
with open(self.output_file, 'w') as f:
140+
f.write('at;pos\n')
141+
for item in funscripts[first_metric].get_actions():
142+
f.write('{at};{pos}\n'.format(at=item['at'], pos=item['pos']))
120143

121144
self.__logger.info("Save result to %s", self.output_file)
122145
if not success: self.__show_message(msg, error=True)

0 commit comments

Comments
 (0)