Skip to content

Instantly share code, notes, and snippets.

View royshil's full-sized avatar

Roy Shilkrot royshil

View GitHub Profile
@royshil
royshil / SimpleVideoStabilizer.cpp
Last active May 8, 2024 05:49
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;
@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 / 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 / read_and_convert_audio.cpp
Created May 4, 2024 02:26
Read and convert an audio file to another format or sample rate with libav and libswresample in C++.
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/frame.h>
#include <libavutil/mem.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
}
#include <iostream>
@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 / CompressYUYV2JPEG.cpp
Created January 14, 2016 20:29
Example of converting a YUYV buffer to JPEG using libJPEG
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
#include <memory>
#include <jpeglib.h>
using namespace std;
@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 / 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
*