Skip to content

Instantly share code, notes, and snippets.

View crearo's full-sized avatar
🥨

Rish Bhardwaj crearo

🥨
View GitHub Profile
@crearo
crearo / lut-shaders.java
Last active August 11, 2018 06:09
GLES shaders for look up table texture - false colorizing a greyscale image
// Simple vertex shader
private static final String VERTEX_SHADER =
"uniform mat4 uMVPMatrix;\n" +
"uniform mat4 uTexMatrix;\n" +
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"varying vec2 vTextureCoord;\n" +
"void main() {\n" +
" gl_Position = uMVPMatrix * aPosition;\n" +
" vTextureCoord = (uTexMatrix * aTextureCoord).xy;\n" +
@crearo
crearo / ColorConversions.java
Last active February 4, 2024 17:06
YUV420P to RGBA8888 color conversion - with explanation as to why you may fail trying this in java
/**
* It took me a whole 6 hours to finally get the color conversion right.
* I have a fairly good understanding of the various color formats (YUV420P, SP, 422, etc etc),
* and how to access individual Y, U, and V components.
* I however struggled because of a very simple yet hair-pulling gotcha.
* All primitives in Java are signed! If you come from a Python-like world where 0xFF prints 255,
* you see yourself struggle just the same. I am however embarrassed at spending 6 hours on this.
*
* @author rish
*/
@crearo
crearo / pedestrian-detector.py
Created April 4, 2018 17:30
A simple pedestrian detector based on PyImageSearch's blogpost
import numpy as np
import cv2
from imutils.object_detection import non_max_suppression
from imutils import paths
import argparse
import imutils
"""
The parameters passed to the hog detector need to be played around
with to get optimum speed vs accuracy. This will always be a tradeoff.
@crearo
crearo / software-stab.py
Created December 21, 2017 08:06
Simple software stabilization with linear smoothing filter
'''
Performs software stabilization using optical flow + linear smoothing.
Vision algos used :
- KLT for flow tracking
- Harris corner detection to detect points to be tracked in each frame
This is the Python translation I wrote of the original .cpp code written by nghiaho.com/?p=2093
'''
import cv2
import numpy as np
@crearo
crearo / FileLogger.java
Created December 18, 2017 10:11
Provides Android's Log.d() like logging for logging to files
package com.rish.imagestab.utils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
/**
* Created by rish on 14/6/17.
@crearo
crearo / video-side-by-side.py
Created December 15, 2017 10:50
Takes two input videos of the same dimensions and stores them side by side
'''
A small script to play videos of the same dimensions side by side.
I needed this while showing two videos side by side; one stabilized and one not stabilized during my
works on video stabilization.
'''
import cv2, sys
import numpy as np
if len(sys.argv) < 3:
@crearo
crearo / WiFiConnector.java
Created September 13, 2017 03:06
Android code to connect to a WiFi network programatically.
package com.tonbo.streamer.network;
import android.content.Context;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.annotation.CheckResult;
@crearo
crearo / fragment_shader_YUV420P_to_RGB.frag
Last active December 19, 2024 13:14
A fragment shader to convert YUV420P to RGB.
/** A fragment shader to convert YUV420P to RGB.
* Input textures Y - is a block of size w*h.
* texture U is of size w/2*h/2.
* texture V is of size w/2*h/2.
* In this case, the layout looks like the following :
* __________
* | |
* | Y | size = w*h
* | |
* |________|
@crearo
crearo / fragment_shader_NV12_to_RGB.frag
Last active August 1, 2024 01:57
A fragment shader to convert NV12 to RGB.
/** A fragment shader to convert NV12 to RGB.
* Input textures Y - is a block of size w*h.
* texture UV is of size w*h/2.
* Remember, both U and V are individually of size w/2*h/2, but they are interleaved.
* The layout looks like this :
* ----------
* | |
* | Y | size = w*h
* | |
* |________|
@crearo
crearo / LineGraphView.java
Last active July 13, 2017 05:54
A simple line graph view that renders at 60fps. Fast, elegant.
package rish.crearo.imagestabv2;
/**
* Original author unknown.
*
* Modified by rish on 10/7/17.
* [email protected]
*/
import android.content.Context;