mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-06-05 11:39:33 +00:00
Tools: Add reverse cut to cut.py
This commit is contained in:
26
tools/cut.py
26
tools/cut.py
@@ -5,7 +5,7 @@ import glob
|
||||
import copy
|
||||
import logging
|
||||
|
||||
def cut_file(filename, _from, _to):
|
||||
def cut_file(filename, _from, _to, reverse = False):
|
||||
imported_frames = []
|
||||
anim_id = ""
|
||||
|
||||
@@ -52,15 +52,27 @@ def cut_file(filename, _from, _to):
|
||||
_to = len(imported_frames)-1
|
||||
|
||||
path = '{}/cut_{}_{}'.format(os.path.dirname(filename),_from,_to)
|
||||
|
||||
if reverse:
|
||||
path += '_r'
|
||||
|
||||
csv_file = open(path+'/'+os.path.basename(filename), mode='w+')
|
||||
with csv_file:
|
||||
csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
if anim_id != "":
|
||||
csv_writer.writerow([anim_id])
|
||||
for i in range(_from, _to+1):
|
||||
csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'],
|
||||
imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']])
|
||||
if not reverse:
|
||||
for i in range(_from, _to+1):
|
||||
csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'],
|
||||
imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']])
|
||||
else:
|
||||
for i in range(_from):
|
||||
csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'],
|
||||
imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']])
|
||||
for i in range(_to, len(imported_frames)):
|
||||
csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'],
|
||||
imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']])
|
||||
|
||||
|
||||
print("Successfully created file {}".format(path+'/'+os.path.basename(filename)))
|
||||
|
||||
@@ -73,13 +85,15 @@ if __name__ == "__main__":
|
||||
help="Cut from this frame, default is 0 (from the beginning)")
|
||||
parser.add_argument('-t','--to', type=int, default=0,
|
||||
help="Cut to this frame (including this one), default is 0 (to the end)")
|
||||
parser.add_argument('-r', '--reverse', action='store_true', help="Reverse cutting, this tool will cut from the beginning to <frm> frame and from <to> frame to the end")
|
||||
args = parser.parse_args()
|
||||
|
||||
_from = args.frm
|
||||
_to = args.to
|
||||
|
||||
path = '{}/cut_{}_{}'.format(args.directory,_from,_to)
|
||||
|
||||
if args.reverse:
|
||||
path += '_r'
|
||||
|
||||
if not os.path.exists(path):
|
||||
try:
|
||||
@@ -91,7 +105,7 @@ if __name__ == "__main__":
|
||||
|
||||
files = [f for f in glob.glob(args.directory + '/*.csv')]
|
||||
for f in files:
|
||||
cut_file(f, _from, _to)
|
||||
cut_file(f, _from, _to, args.reverse)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user