Skip to content

Instantly share code, notes, and snippets.

View laygond's full-sized avatar
🏅
It is never too late to commit.

Laygond laygond

🏅
It is never too late to commit.
View GitHub Profile
@laygond
laygond / snapshot.py
Created April 5, 2024 00:15
Take snapshots with your webcam by hitting the space bar on your keyboard.
#***
# USAGE: python snapshot.py -l optionalCustomLabelHere
#***
#
# Take snapshots with your webcam.
# - Exit with ESC
# - Snapshot with SPACE
#
# NOTE:
# -Change webcam src to your usb port number (Line 29)
@laygond
laygond / pynput_example.py
Created April 2, 2024 02:31
pynput keylogger starter code example
from pynput.keyboard import Key, Listener
#--- Helper Function ---
def alphanumeric_filter(key):
'''
Return alphanumeric keys as a char type and special keys as a key type
'''
try:
return key.char
except AttributeError:
@laygond
laygond / PrettyPrintDict.py
Last active January 17, 2023 15:15
Overload Print function to pretty print Dictionaries
import json
def print_decorator(func):
"""
Overload Print function to pretty print Dictionaries
"""
def wrapped_func(*args,**kwargs):
if isinstance(*args, dict):
return func(json.dumps(*args, sort_keys=True, indent=2, default=str))
else:
return func(*args,**kwargs)
@laygond
laygond / mrcnn_continous_run.sh
Last active April 24, 2023 13:29
Allows matterport's MRCNN to run in sections so that every few epochs it re-executes # and, therefore, resets the memory solving provisionally the memory leak issue.
# -----------------------------
# USAGE
# -----------------------------
# chmod +x mrcnn_continous_run.sh
# source mrcnn_continous_run.sh
#
# DESCRIPTION:
# Allows matterport's MRCNN to run in sections so that every few epochs it re-executes
# and, therefore, resets the memory solving provisionally the memory leak issue.
#
@laygond
laygond / keep_alive.py
Created July 7, 2020 05:15
Keep session active to prevent Udacity workspace to go to sleep.
#! /opt/carnd_p3/behavioral/bin/python3
from workspace_utils import active_session
import os
import subprocess
with active_session():
# do long-running work here
os.system("/opt/carnd_p3/linux_sim/linux_sim.x86_64")
print("hello")
@laygond
laygond / gluevideos.py
Last active June 30, 2020 21:19
Concatenate (glue) two videos given the two inputs and output paths from terminal
# Concatenate (glue) two videos given the two inputs and output paths
# (if destination path not specified it uses same as first input path)
# by Bryan Laygond
# USAGE:
# python gluevideos.py --v1 "Path/to/first/source/file" \
# --v2 "Path/to/second/source/file" \
# --output "Path/to/destination/file"
import os
@laygond
laygond / trimvideo.py
Last active June 24, 2020 22:42
Trims a video from terminal given start and end time as well as input and ouput path. If time not specified it assumes beginning or end of video. If destination path not specified it uses same as input path.
# Trims a video given start and end time and input and ouput path
# (if time not specified it assumes beginning or end of video)
# (if destination path not specified it uses same as input path)
# by Bryan Laygond
# USAGE:
# python videotrim.py --input "Path/to/source/file" \
# --output "Path/to/destination/file" \
# --start 2.0 \
# --end 7.0
@laygond
laygond / Video2GIF.py
Created September 12, 2019 18:07
Python script that will make GIF for you from a video clip.
#https://medium.com/@TejasBob/moviepy-is-awesome-part2-73b04e2338b0
from moviepy.editor import *
import moviepy.video.fx.all as vfx
clip = VideoFileClip(path/to/downloaded/video)
clip = clip.resize(0.4)
sub = clip.subclip(179, 182)
sub = sub.fx(vfx.crop, x1=115, x2=399, y1=0, y2=288)
clip2 = sub.speedx(final_duration=2)
@laygond
laygond / ScrambleVideoClips.py
Created September 12, 2019 18:02
Split a video into small sections (.5 seconds each) and then randomize them.
# https://github.com/antiboredom/automating-video/blob/master/moviepy-tutorial.md
import random
import moviepy.editor as mp
original_video = mp.VideoFileClip(videofile)
duration = original_video.duration
segment_length = .5
clips = []
@laygond
laygond / writeVideoFromImages.py
Last active February 15, 2022 13:06
Write Video from Images using MoviePy and OpenCV
#pip3 install -U imageio-ffmpeg # It contains VideoFileClip module and must be installed from shell
#from moviepy.editor import VideoFileClip,ImageSequenceClip # Must be added in the beginning with the rest of imported modules
# Define Input and Output folder (USER must Edit)
video_name = "sample.mp4"
video_name_part = video_name.split(".") # sample & mp4 has been split
input_video_path = os.path.join("Input_Video", video_name)
output_images_path = os.path.join("Output_Video", "Processed_Images") # This is a temporary folder to hold processed images
output_video_path = os.path.join("Output_Video", video_name_part[0] + "_output." + video_name_part[1])