Skip to content

Instantly share code, notes, and snippets.

View royshil's full-sized avatar

Roy Shilkrot royshil

View GitHub Profile
@royshil
royshil / AndroidCamera2TouchToFocus.java
Last active May 4, 2024 02:51
How to implement Touch-to-Focus in Android using Camera2 APIs
//Override in your touch-enabled view (this can be differen than the view you use for displaying the cam preview)
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
final int actionMasked = motionEvent.getActionMasked();
if (actionMasked != MotionEvent.ACTION_DOWN) {
return false;
}
if (mManualFocusEngaged) {
Log.d(TAG, "Manual focus already engaged");
return true;
@royshil
royshil / circle_of_deadlines.html
Created June 20, 2017 15:59
A d3v4 visualization of yearly submission deadlines (conference, grant, etc). Tool for the hungry assistant professor.
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.23.1/babel.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/4.6.0/d3.min.js"></script>
<script src="http://unpkg.com/d3-radial-axis@1.5/dist/d3-radial-axis.min.js"></script>
<script src="https://npmcdn.com/d3fc-rebind@4.0.1/build/d3fc-rebind.js"></script>
<script src="https://npmcdn.com/d3fc-data-join@2.0.0/build/d3fc-data-join.js"></script>
<script src="https://npmcdn.com/d3fc-label-layout@4.0.0/build/d3fc-label-layout.js"></script>
@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()
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 / setup.sh
Last active January 27, 2018 14:05
Setup an automatic Tensorflow-CUDA-Docker-Jupyter machine on Google Cloud Platform
#!/bin/bash
# First you must install the 4.4.0 kernel:
# $ sudo apt-get install linux-image-4.4.0-112-generic
# find all the other kernels and remove them:
# $ sudo apt-get purge linux-image-4.13.0-1008-gcp
# $ sudo update-grub
# $ sudo reboot
sudo apt-get update && sudo apt-get install -y \
@royshil
royshil / BUILD
Created March 8, 2018 20:51
Scripts for cross-compiling Tensorflow 1.5+ for the Jetson TK1 arm-based SoM
package(default_visibility = ["//visibility:public"])
cc_toolchain_suite(
name = "toolchain",
toolchains = {
"armeabi-v7a|compiler": ":cc-compiler-armeabi",
"k8|compiler": ":cc-compiler-local",
},
)
@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 / cylindricalWarping.py
Last active May 7, 2024 06:42
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 / ffmpeg_concat_xfade.py
Last active April 28, 2024 17:12
A video concatenation tool based on FFMPEG with crossfade between the segments (with the `xfade` filter)
#!/usr/local/bin/python3
import argparse
import subprocess
import itertools
parser = argparse.ArgumentParser(description='Concatenate videos with FFMPEG, add "xfade" between segments.')
parser.add_argument('--segments_file', '-f', metavar='Segments file', type=str, nargs=1,
help='Segments text file for concatenating. e.g. "segments.txt"')
@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