Skip to content

Instantly share code, notes, and snippets.

@yiminglin-ai
yiminglin-ai / for_notebook_and_terminal.py
Last active September 27, 2021 16:01
[parallelism] python scripts on threading and mutiprocessing
"""
tips from Jie:
1) Put worker_proc in a py file. The code may not work properly if you define it directly in your notebook. On the other hand, dispenser_proc can be defined in the notebook.
2) Use multiprocessing.Queue, not queue.Queue.
3) It's essential to have a job dispenser thread. Multiprocessing queue has a finite capacity. If you send jobs from your main thread, your code could hang.
If dispensing jobs in the main thread, it may hang. Reason: workers try to put stuff into the result queue, result queue becomes full, the main thread is not reading from result queue because it still tries to put stuff into the job queue, the workers hang such that they won’t read from the job queue, both workers are main thread hang
4) I use None to indicate 'end of queue'. It's important for the worker_proc to put None back into the job_queue once it gets a None, otherwise other workers may hang.
"""
@yiminglin-ai
yiminglin-ai / install_zsh.sh
Last active March 21, 2019 13:49
compile zsh from scratch
# Installs Zsh with Oh-My-Zsh without root privileges
#
# Instructions
# 1) bash install_zsh.sh
# 2) edit .zshrc and add the path to your Zsh binary to the PATH variable
# 3) add `set-option -g default-shell <path to zsh>/bin/zsh` to `~/.tmux.conf`
#
# References: https://www.drewsilcock.co.uk/compiling-zsh
#
# ## Ncruses
@yiminglin-ai
yiminglin-ai / compile_dlib_for_specific_android_ABI.sh
Last active August 26, 2022 14:39
[Android NDK] #android #ndk #jni #dlib
# asssume you're in the dlib
cd dlib && mkdir build-armeabi-v7a && cd build-armeabi-v7a;
$ANDROID_CMAKE \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=../../../dlib-build-armeabi-v7a \
-DANDROID_NDK=$ANDROID_NDK \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_NATIVE_API_LEVEL=26 \
@yiminglin-ai
yiminglin-ai / video-metada-finder.py
Last active October 31, 2018 17:30
[video misc] #python #video
#!/usr/local/bin/python3
import subprocess
import shlex
import json
# function to find the resolution of the input video file
def findVideoMetada(pathToInputVideo):
cmd = "ffprobe -v quiet -print_format json -show_streams"
args = shlex.split(cmd)
args.append(pathToInputVideo)
@yiminglin-ai
yiminglin-ai / download_videos.py
Last active January 4, 2019 13:09
[mobiface] #python #tracking #mobiface
from subprocess import call
from glob import glob
import threading
import queue
anno_files = glob('./*.csv')
vids = []
for af in anno_files:
with open(af) as f:
lines = f.readlines()
@yiminglin-ai
yiminglin-ai / dlib.py
Last active January 7, 2021 10:46
[visualization] visualizing images or videos #python #moviepy #matplotlib
from collections import OrderedDict
#For dlib’s 68-point facial landmark detector:
FACIAL_LANDMARKS_68_IDXS = OrderedDict([
("mouth", (48, 68)),
("inner_mouth", (60, 68)),
("right_eyebrow", (17, 22)),
("left_eyebrow", (22, 27)),
("right_eye", (36, 42)),
("left_eye", (42, 48)),
@yiminglin-ai
yiminglin-ai / makefile.m
Created October 8, 2018 09:04
[Compile Opencv using mex ] compile c++ files which rely on OpenCV3 for Matlab using mex #opencv #matlab #mex
%// This make.m is for MATLAB
%// Function: compile c++ files which rely on OpenCV for Matlab using mex
%// Author : zouxy
%// Date : 2014-03-05
%// HomePage : http://blog.csdn.net/zouxy09
%// Email : zouxy09@qq.com
%// Modified by Yiming Lin to support OpenCV3 and Ubuntu
%// Date 2018-10-08
%% Please modify your path of OpenCV
@yiminglin-ai
yiminglin-ai / matlab_errors.md
Last active October 8, 2018 12:43
Matlab errors #matlab #cuda

VideoReader : Could not read file due to an unexpected error. Reason: Unable to initialize the video properties

sudo apt install ubuntu-restricted-extras

Reference

CUDA errors

Make sure the installed version of MATLAB supports the installed version of CUDA. This is very important. I compiled OpenCV with CUDA9.0 and try to compile a mexFunction calling OpenCV CUDA functions in Matlab R2018b. They this release only supports CUDA9.1 so I rolled back to R2018a.
Reference: GPU Support by Release

@yiminglin-ai
yiminglin-ai / cmake.md
Last active October 8, 2018 12:46
compile OpenCVwith CUDA9.0 support

opencv3

cmake -D CMAKE_BUILD_TYPE=RELEASE \
	-D CMAKE_INSTALL_PREFIX=/usr/local \
	-D INSTALL_PYTHON_EXAMPLES=OFF  \
	-D INSTALL_C_EXAMPLES=OFF \
	-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules \
	-D PYTHON_EXECUTABLE=/home/yiming/.miniconda/bin/python \
    -D WITH_CUDA=ON \
    -D WITH_MATLAB=ON \
@yiminglin-ai
yiminglin-ai / setup_ubuntu_16.04.sh
Last active August 24, 2017 15:28
My personal setup for a new Ubuntu to avoid repeated configurations.
#!/usr/bin/env bash
# update systems
sudo apt-get update -y
sudo apt-get upgrade -y
# system essentials
sudo apt-get -qq install build-essential git wget cmake curl
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils
sudo apt-get -qq install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libatlas-base-dev