Skip to content

Instantly share code, notes, and snippets.

View royshil's full-sized avatar

Roy Shilkrot royshil

View GitHub Profile
@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 / 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 / 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 / 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 / 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()
/// perform the Simplest Color Balancing algorithm
void SimplestCB(Mat& in, Mat& out, float percent) {
assert(in.channels() == 3);
assert(percent > 0 && percent < 100);
float half_percent = percent / 200.0f;
vector<Mat> tmpsplit; split(in,tmpsplit);
for(int i=0;i<3;i++) {
//find the low and high precentile values (based on the input percentile)
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.segmentation import slic
from skimage.segmentation import mark_boundaries
from skimage.data import astronaut
from skimage.util import img_as_float
import maxflow
from scipy.spatial import Delaunay
@royshil
royshil / downloadPDFs.py
Last active March 22, 2020 01:27
Download All PDFs in a URL using Python mechanize
# This is kind-of based off of this: http://stackoverflow.com/questions/5974595/download-all-the-linksrelated-documents-on-a-webpage-using-python
import cookielib
import urllib2
import mechanize
from time import sleep
import os
import cgi
# A routine to download a file from a link, by simulating a click on it
@royshil
royshil / copy_tf_headers.sh
Last active January 21, 2020 08:01
A script to copy Tensorflow headers to build custom C++ applications
#!/bin/bash
# inspired by a part of: https://github.com/cjweeks/tensorflow-cmake/blob/master/build.sh
#
# Assumes Tensorflow libraries libtensorflow_framework.so and libtensorflow_cc.so were built with Bazel,
# and the ${TF_ROOT}/tensorflow/contrib/makefile/download_dependencies.sh script was executed.
set -o nounset
set -o errexit
set -o pipefail
@royshil
royshil / NRUBSOpenCV.cpp
Last active October 7, 2019 12:21
Simple 2D NURBS renderer for OpenCV, reading a DXF file.
/*
* Simple 2D NURBS renderer for OpenCV, reading DXF files
*
* The MIT License (MIT)
*
* Copyright (c) 2013 Roy Shilkrot
*
* Updated: Nov 2016
*
* Permission is hereby granted, free of charge, to any person obtaining a copy