Skip to content

Instantly share code, notes, and snippets.

@hmahadik
hmahadik / zmq_router_dealer.js
Created June 1, 2020 18:16
zeromq.js Router/Dealer Sample
var zmq = require('zeromq');
/* ZMQ Router */
var router_addr = 'tcp://0.0.0.0:5554'
var router_options = {
identity: "SourceFrame"
}
var router = zmq.socket('router', router_options);
router.bindSync(router_addr);
@hmahadik
hmahadik / zmqrouter.cpp
Created June 2, 2020 16:14
ZMQ Router Sample
/*
./zmqrouter
identity: SinkFrame
msg: Connect
identity: SinkFrame
msg: Connect
identity: SinkFrame
msg: Connect
*/
@hmahadik
hmahadik / mixed_dpi_scaling.sh
Last active August 3, 2020 18:08 — forked from jackdpeterson/dock.sh
Ubuntu 18.04 - Mixed DPI with 27" 4K Monitor scaled by 1.5 (HiDPI), and one 24" 1080p monitor scaled by 1.0 (LoDPI)
#!/bin/bash
set -eux
echo "setting 27 inch 4K monitor"
xrandr --output DisplayPort-0 --mode 3840x2160 --scale "1.5x1.5" --rate 60 --primary
echo "setting 24 inch 1080p monitor"
xrandr --output HDMI-A-0 --mode 1920x1080 --scale "2x2" --pos 5760x0
echo "setting global scaling to 2x"
@hmahadik
hmahadik / measure_decode_time_ms.py
Created September 11, 2020 14:58
Easy way to measure how long it takes to decode frames using OpenCV's VideoCapture class
import cv2
import time
def measureDecodeTimeMs(src):
cap = cv2.VideoCapture(src)
for i in range(10):
a = time.time()
ok, frame = cap.read()
if not ok:
print("Error: Unable to read frame")
@hmahadik
hmahadik / install_docker_imx.sh
Last active September 2, 2022 14:29
Download and install static docker binaries for aarch64 (tested on imx).
#!/bin/bash
set -eux
cd /tmp
rm -rfv docker*
wget -O /tmp/docker.tgz https://download.docker.com/linux/static/stable/aarch64/docker-20.10.6.tgz
tar xvf docker.tgz
mv -v docker/* /usr/bin
rm -rfv docker*
# sed 's/exit 0/dockerd\&\nexit 0/' /etc/rc.local >> /etc/rc.local
echo "Done."
@hmahadik
hmahadik / gstreamer-pipelines.sh
Last active May 12, 2021 20:47
Misc gstreamer pipelines
# i.MX 8M Plus
# USB camera h264 RTP stream
# Sending
gst-launch-1.0 -v v4l2src ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! vpudec ! queue ! clockoverlay ! queue ! vpuenc_h264 ! h264parse ! rtph264pay config-interval=10 pt=96 ! udpsink host=192.168.1.214 port=5000 sync=false
# Receiving
gst-launch-1.0.exe -vvv udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, payload=(int)96" ! rtph264depay ! decodebin ! autovideosink
# Convert image sequence (.jpg files) into an mkv
gst-launch-1.0 multifilesrc location="%d.jpg" index=0 ! image/jpeg,width=1920,height=1080,framerate=25/1 ! jpegdec ! videoconvert ! videorate ! queue ! vpuenc_h264 ! h264parse ! matroskamux ! filesink location="2220_imx8mp.mkv"
import pyaudio
import math
import struct
import playsound
CHUNK = 2048
THRESHOLD = 70
REFERENCE_LEVEL = 0.00005
def rms( data ):
@hmahadik
hmahadik / tflite_runtime_inference.py
Last active May 17, 2021 17:36
Inference using tflite_runtime's interpreter with input data generated using np's random_sample
from tflite_runtime import interpreter
import numpy as np
import time
i = interpreter.Interpreter("mobilenet_v1_1_224.tflite")
input_details = i.get_input_details()
output_details = i.get_output_details()
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
i.set_tensor(input_details[0]['index'], input_data)
t1=time.time(); i.invoke(); t2=time.time(); print(f"Warm-up time: {1000.0*(t2-t1)} ms")
@hmahadik
hmahadik / set-up-nvidia-tegra-apt-repo-sources.sh
Created June 17, 2021 20:47
Run this script from inside the container using sudo
#!/bin/bash
# heavily borrowed from mdegans/docker-tegra-ubuntu
set -eux
wget https://repo.download.nvidia.com/jetson/jetson-ota-public.asc -O /etc/apt/trusted.gpg.d/jetson-ota-public.asc
chmod 644 /etc/apt/trusted.gpg.d/jetson-ota-public.asc
apt-get update && apt-get install -y --no-install-recommends ca-certificates
echo "deb https://repo.download.nvidia.com/jetson/common r32.4 main" > nvidia-l4t-apt-source.list
echo "deb https://repo.download.nvidia.com/jetson/t194 r32.4 main" >> nvidia-l4t-apt-source.list
mv nvidia-l4t-apt-source.list /etc/apt/sources.list.d/
apt-get update
@hmahadik
hmahadik / auto-refresh-html-img.js
Created August 19, 2021 15:18
Refreshes the first HTML img element every 5 seconds.
let interval = setInterval(()=>{
let img = document.getElementsByTagName("img").item(0);
img.src = img.src;
console.log("Reloaded. Next reload in 5s.");
}, 5000);