Skip to content

Instantly share code, notes, and snippets.

View clungzta's full-sized avatar

Alex McClung clungzta

View GitHub Profile
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('/home/alex/opencv_workshop_videos/opencv-play/images/sky4.jpg')
mask = np.zeros(img.shape[:2],np.uint8)
def plot_1Dhistogram(img,nbins,mask=None):
# plot 1D histograms for each chanel
nbins = 30
@clungzta
clungzta / hist_exhaustive_search.py
Last active March 10, 2017 22:10
Exhaustive histogram search of numpy histogram arrays, uses cv2 compareHist
import os
import cv2
import numpy as np
def hist_exhaustive_search(hists_to_search, labels, test_hist, methodName="Hellinger"):
OPENCV_METHODS = {}
OPENCV_METHODS["Correlation"] = cv2.HISTCMP_CORREL
OPENCV_METHODS["Intersection"] = cv2.HISTCMP_INTERSECT
OPENCV_METHODS["Hellinger"] = cv2.HISTCMP_BHATTACHARYYA
@clungzta
clungzta / transparent_overlay_cv2.py
Created March 28, 2017 10:20
Example for overlaying a transparent image onto a background image using cv2
import numpy as np
import cv2
img = cv2.imread('background.jpg')
overlay_t = cv2.imread('foreground_transparent.png',-1) # -1 loads with transparency
def overlay_transparent(background_img, img_to_overlay_t, x, y, overlay_size=None):
"""
@brief Overlays a transparant PNG onto another image using CV2
@clungzta
clungzta / build_debug_android_kivy.sh
Created May 15, 2017 23:29
Simple bash script to build and run debug android app using Kivy and ADB, includes filtered log output option
VERBOSITY = 1
# Change Package name to suit that
PACKAGE_NAME=org.test.kivytestapp
echo $PACKAGE_NAME
echo "Building the android app in debug mode."
buildozer -v android debug
echo "Loading the app onto to the debug mode device."
import os, io
import json
import rosbag
import subprocess
from sensor_msgs.msg import PointCloud2
from rospy_message_converter import json_message_converter
def bag_to_pcd(filepath, topic):
# Call PCL ROS `bag_to_pcd` http://wiki.ros.org/pcl_ros
command = ['rosrun', 'pcl_ros', 'bag_to_pcd', filepath, topic, './output_pcd']
@clungzta
clungzta / measurement_error.py
Last active May 27, 2017 11:11
Very simple python script to print error in measurements (maximum absolute difference from the mean), useful for science experiments
import numpy as np
# List of measuerement samples
A = [0.058, 0.06, 0.066]
mean = np.mean(A)
greatest_difference_from_mean = np.amax(np.abs(np.mean(A) - A))
print(u'{:.3f} \u00B1 {:.3f}'.format(mean, greatest_difference_from_mean))
@clungzta
clungzta / cv2_transparent_overlay.py
Created August 23, 2017 03:40
Function for overlaying transparent (PNG) images in python
import cv2
import numpy as np
def overlay_transparent(background_img, img_to_overlay_t, x, y, overlay_size=None):
"""
@brief Overlays a transparant PNG onto another image using CV2
@param background_img The background image
@param img_to_overlay_t The transparent image to overlay (has alpha channel)
@param x x location to place the top-left corner of our overlay
@clungzta
clungzta / gstreamer_webcam_janus_webrtc.md
Last active March 7, 2018 08:18
(Ubuntu) Linux instructions for streaming webcam to janus gateway

Step 1 - Follow install and setup instructions for janus, gst-launch1.0, nginx (and required dependencies)

https://www.rs-online.com/designspark/building-a-raspberry-pi-2-webrtc-camera

Step 2 - Launch Janus

./janus -F /opt/janus/etc/janus/

Step 3 - Start streaming from webcam

gst-launch-1.0 v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! videoconvert ! x264enc pass=qual quantizer=20 tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=8004

Step 4 - Open demo page in browser

@clungzta
clungzta / devboxstatus.sh
Last active October 29, 2017 02:03
Utility to get the details of a Linux process (process_type, PID, executable path, running time, TTY, CPU Usage, RAM Usage, NVIDIA GPU Usage and the IP of user that executed it)
# All python* processes running on this system (includes python and python3)
searchTerm=python
echo ''
for pid in `ps -ef | grep $searchTerm | awk '{print $2}'`
do
TTYNAME=$(ps u --pid $pid | awk 'FNR > 1 {print $7}' | grep -v '?')
if [ ! -z "${TTYNAME}" ]; then
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
@clungzta
clungzta / multiprocess_bogosort.py
Created November 8, 2017 08:34
BOGOSORT: Implementation of the ultra efficient (n-1)n! sorting algorithm using python multiprocesses
import os
import time
from random import *
import multiprocessing
class Consumer(multiprocessing.Process):
def __init__(self, task_queue, result_queue):
multiprocessing.Process.__init__(self)
self.task_queue = task_queue