Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env ruby
require 'fileutils'
# Takes two arguments:
# Arg 1 - path to the "GRP/frame information" txt file, output by LadybugCapPro
# Arg 2 - path to the folder containing all the fames as PNG files. Assumes prefix 'ladybug_panoramic_'
path_to_frame_info_file = ARGV[0]
path_to_png_folder = ARGV[1]
# find all frames that need to be filled in
dropped_frames = []
prev_line = ""
File.readlines(path_to_frame_info_file).each do |line|
num_dropped_frames_match = /ERROR: Dropped frame : (\d)/.match(line)
frame_number_match = /^(\d{6})/.match(prev_line)
prev_line = line
next unless num_dropped_frames_match && frame_number_match
dropped_frames.push({num: num_dropped_frames_match[1].to_i, frame: frame_number_match[1].to_i})
end do
# move all files to new naming convention so they don't get overwritten while filing in gaps
Dir['*.png'].each do |filename| filename, "#{filename}.tmp"
# put files back in sequence, duplicating neighbouring frames to fill gaps
extra_frames = 0
Dir['*.png.tmp'].each do |filename|
number = /ladybug_panoramic_(\d{6}).png.tmp/.match(filename)[1].to_i
new_name = "ladybug_panoramic_#{(number + extra_frames).to_s.rjust(6, '0')}.png"
puts "Frame #{filename} is now file #{new_name}" filename, new_name
dropped = dropped_frames.find {|frame| frame[:frame] == number}
next unless dropped
puts "Copying frame #{new_name} #{dropped[:num]} times"
(1..dropped[:num]).each do |n|
extra_frames += 1
FileUtils.cp new_name, "ladybug_panoramic_#{(number + extra_frames).to_s.rjust(6, '0')}.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment