Skip to content

Instantly share code, notes, and snippets.

View royshil's full-sized avatar

Roy Shilkrot royshil

View GitHub Profile
@royshil
royshil / simple_pyqt6_opencv.py
Created February 6, 2024 14:12
Simple PyQt6 and OpenCV VideoCapture viewer using a worker thread
from PyQt6.QtCore import QObject, QThread, pyqtSignal, Qt, QTimer
from PyQt6.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsPixmapItem, QApplication
from PyQt6.QtGui import QImage, QPixmap
import cv2
import time
class CameraWorker(QObject):
frameCaptured = pyqtSignal(object) # Emit frame data
def __init__(self, camera_index=0):
@royshil
royshil / ndi.py
Created February 5, 2024 04:37
Simplest cyndlid NDI + OpenCV Python example
# pip install cyndilib opencv-python
import cv2
from cyndilib.wrapper.ndi_recv import RecvColorFormat, RecvBandwidth
from cyndilib.finder import Finder
from cyndilib.receiver import Receiver
from cyndilib.video_frame import VideoFrameSync
finder = Finder()
# Create a Receiver without a source
@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 / 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 / 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 / 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 / ffmpeg_concat_xfade.py
Last active January 3, 2024 01:11
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 / 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 / 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 / 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",
},
)