Skip to content

Instantly share code, notes, and snippets.

View royshil's full-sized avatar

Roy Shilkrot royshil

View GitHub Profile
@royshil
royshil / lap_pyr.py
Created September 29, 2017 14:59
Laplacian pyramid blending with a mask in OpenCV-Python
# adapted from http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_pyramids/py_pyramids.html
import cv2
import numpy as np
def Laplacian_Pyramid_Blending_with_mask(A, B, m, num_levels = 6):
# assume mask is float32 [0,1]
# generate Gaussian pyramid for A,B and mask
GA = A.copy()
@royshil
royshil / opencv_capture_v4l2.py
Created March 4, 2016 18:59
A way to set V4L2 camera params for OpenCV, when cv2.VideoCapture doesn't work. This requires the python-v42lcapture module (https://github.com/gebart/python-v4l2capture)
#!/usr/bin/env python
import numpy as np
import cv2
import os
import v4l2capture
import select
if __name__ == '__main__':
#cap = cv2.VideoCapture(0)
@royshil
royshil / google_cloud_speech_json_to_srt.py
Last active December 30, 2021 14:50
Google Cloud Speech JSON to .str converter script, with timestamp keeping and multiple files support
#!/usr/local/bin/python3
import os
import json
import sys
import argparse
import math
import subprocess
from tqdm import tqdm
@royshil
royshil / gist:6318407
Created August 23, 2013 11:39
A CMake Find module for FFMPEG that will tear the HD apart looking for the libs and includes ;)
# - Try to find FFMPEG
# Once done this will define
# FFMPEG_FOUND - System has FFMPEG
# FFMPEG_INCLUDE_DIRS - The FFMPEG include directories
# FFMPEG_LIBRARIES - The libraries needed to use FFMPEG
# FFMPEG_LIBRARY_DIRS - The directory to find FFMPEG libraries
#
# written by Roy Shilkrot 2013 http://www.morethantechnical.com/
#
@royshil
royshil / video_cropper.py
Last active June 5, 2023 02:18
Quicrop! A minimal tool for cropping video with Tkinter and ffmpeg-python
import tkinter as tk
from tkVideoPlayer import TkinterVideo
from ffmpeg import FFmpeg, Progress
import os
import sys
import argparse
parser = argparse.ArgumentParser(description="Crop a video")
parser.add_argument("video", metavar="video", type=str, help="video file to crop")
args = parser.parse_args()
@royshil
royshil / video_to_480_gif.sh
Created June 21, 2023 02:20
Various flavors of video-to-GIF scripts
# Convert the video to a 480x GIF @ x2 speed
file1=$(basename -- "$1")
dir=$(dirname "$1")
file1="${file1%.*}"
/usr/local/bin/ffmpeg -hide_banner -loglevel panic -i "$1" -filter_complex "[0:v] scale=w='min(480,iw)':h=-1,fps=8,setpts=(1/2)*PTS, split [a][b]; [a] palettegen [p]; [b][p] paletteuse" -y "$dir/$file1.gif"
@royshil
royshil / cylindricalWarping.py
Last active June 21, 2023 15:55
Warp an image to cylindrical coordinates for cylindrical panorama stitching, using Python OpenCV
import cv2
import numpy as np
def cylindricalWarp(img, K):
"""This function returns the cylindrical warp for a given image and intrinsics matrix K"""
h_,w_ = img.shape[:2]
# pixel coordinates
y_i, x_i = np.indices((h_,w_))
X = np.stack([x_i,y_i,np.ones_like(x_i)],axis=-1).reshape(h_*w_,3) # to homog
Kinv = np.linalg.inv(K)
@royshil
royshil / SimpleAdHocTracker.cpp
Created March 15, 2015 18:21
Ad-Hoc AR tracker from a planar scene without need for markers
/*
* SimpleAdHocTracker.cpp
*
* Created on: Mar 15, 2015
* Author: roy_shilkrot
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Roy Shilkrot
*
@royshil
royshil / export_twitter_image.py
Last active October 23, 2023 19:47
Export Tweet as Image (screenshot embed)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import logging
import os
import sys
import argparse
import urllib.parse
@royshil
royshil / SimpleVideoStabilizer.cpp
Last active November 1, 2023 23:30
A simple video stabilizer in OpenCV, based on goodFeaturesToTrack, calcOpticalFlowPyrLK and estimateRigidTransform.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/video.hpp>
#include <iostream>
using namespace cv;
using namespace std;