Skip to content

Instantly share code, notes, and snippets.

View joschuck's full-sized avatar

Johannes Schuck joschuck

View GitHub Profile
image = cv2.imread('book_page_1_cropped.jpg', 0)
ret, th = cv2.threshold(image,
0, # threshold value, ignored when using cv2.THRESH_OTSU
255, # maximum value assigned to pixel values exceeding the threshold
cv2.THRESH_BINARY + cv2.THRESH_OTSU) # thresholding type
from matplotlib import pyplot as plt
gray = cv2.imread('book_page_1_cropped.jpg', 0) # open as grayscale
plt.hist(gray.ravel(), 256, [0,256])
plt.show()
import cv2
import numpy as np
image = cv2.imread('book_page_1_cropped.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret, th = cv2.threshold(gray,
127, # threshold value
255, # maximum value assigned to pixel values exceeding the threshold
cv2.THRESH_BINARY) # threshold method type
@joschuck
joschuck / adaptive_thresholding.py
Last active July 9, 2020 17:52
Enhance Scanned Document
image = cv2.imread('input.jpg', 0) # read as grayscale
th = cv2.adaptiveThreshold(image,
255, # maximum value assigned to pixel values exceeding the threshold
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, # gaussian weighted sum of neighborhood
cv2.THRESH_BINARY, # thresholding type
5, # block size (5x5 window)
3) # constant
@joschuck
joschuck / Loading Animation
Created September 30, 2018 11:21
Python Console
import time
import sys
animation = "|/-\\"
for i in range(100):
time.sleep(0.1)
sys.stdout.write("\r" + animation[i % len(animation)])
sys.stdout.flush()
@joschuck
joschuck / images_cli_utils.sh
Created March 16, 2018 05:24
Coder Dealing with Images
# get informations like channels, colorspace, etc.
identify -verbose file.png
@joschuck
joschuck / smooth_lidar.png
Last active September 17, 2020 13:10
Smooth out a depth image or array from lidar measurements
smooth_lidar.png
@joschuck
joschuck / adaboost.lua
Created July 14, 2017 16:16
Adaboost for lua with Torch
Adaboost = {}
Adaboost.__index = Adaboost
function Adaboost:create(training_set, ground_truth)
local adaboost = {}
setmetatable(adaboost,Adaboost)
adaboost.training_set = training_set
adaboost.ground_truth = ground_truth
adaboost.N = training_set:size()[1]
adaboost.weights = torch.ones(adaboost.N):div(adaboost.N)
@joschuck
joschuck / ffmpeg
Last active August 6, 2016 10:18
ffmpeg
# cut video
ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4
# convert to webm
ffmpeg -i input-file.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output-file.webm
#concat
ffmpeg -f concat -safe 0 -i mylist.txt -c copy darmstadt.mp4
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}