Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make proper command line program #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 40 additions & 31 deletions rollingshutter.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
def rs(folder,speed=1):

from PIL import Image
import glob

# ENTER YOUR DIRECTORIES AND FILE TYPE HERE
frame_dir = "/Users/mattparker/Documents/rollingshuttervideos/" + str(folder) + "/"
frame_file = "png"
output_dir = "/Users/mattparker/Documents/rollingshuttervideos/"

width = 1920
height = 1080

# Making our blank output frame
output_image = Image.new('RGB', (width, height))


# let us go through the frames one at a time

current_row = 0

for filename in glob.glob(frame_dir + "*." + frame_file):
frame = Image.open(filename)
new_line = frame.crop((0, current_row, width, current_row+speed))
output_image.paste(new_line, (0,current_row))
current_row += speed

# and export the final frame
output_image.save(output_dir + 'output_image.png')

return 'DONE'
from PIL import Image
import argparse
import glob
import sys

parser = argparse.ArgumentParser(description = 'Fake a rolling shutter effect')
parser.add_argument('folder', help = 'Folder containing image files (named sequentially)')
parser.add_argument('-o', '--output', help = 'Desired output filename (default: out.png)', default = 'out.png')
parser.add_argument('-t', '--type', help = 'Filetype to look for in folder (default: png)', default = 'png')

args = parser.parse_args()

# ENTER YOUR DIRECTORIES AND FILE TYPE HERE
frames = [Image.open(img) for img in glob.glob(args.folder + '/*.' + args.type)]

# Extract size from first frame
width, height = frames[0].size

# Making our blank output frame
output_image = Image.new('RGB', (width, height))

# let us go through the frames one at a time

total_frames = len(frames)
speed = height/total_frames
current_row = 0

for i, frame in enumerate(frames):
new_line = frame.crop((0, int(current_row), width, int(current_row + speed)))
output_image.paste(new_line, (0, int(current_row)))
current_row += speed
i += 1
sys.stdout.write('\r{:3d}% [{:73}]'.format(int(i/total_frames*100), '#'*int(i/total_frames*73)))
sys.stdout.flush()

print()

# and export the final frame
output_image.save(args.output)
print("Saved output to '{}'".format(args.output))