Skip to content

Instantly share code, notes, and snippets.

View hmmbug's full-sized avatar

Mark Hollow hmmbug

  • London, United Kingdom
View GitHub Profile
@hmmbug
hmmbug / crop_morphology.py
Created May 7, 2017 18:30
An updated version of the OpenCV text crop script by Dan Vanderkam on www.danvk.org
#!/usr/bin/env python
'''Crop an image to just the portions containing text.
Usage:
./crop_morphology.py path/to/image.jpg
This will place the cropped image in path/to/image.crop.png.
For details on the methodology, see
http://www.danvk.org/2015/01/07/finding-blocks-of-text-in-an-image-using-python-opencv-and-numpy.html
UPDATE 2017-05-07 by hmmbug:
- Removed dependency on PIL and
@hmmbug
hmmbug / detect_letters.py
Created October 30, 2016 03:17
Extracting text with OpenCV
# A python port of http://stackoverflow.com/a/23565051/2416742
import cv2
def detect_letters(img, struct_elem_x=17, struct_elem_y=3, contour_size=100):
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_sobel = cv2.Sobel(img_gray, cv2.CV_8U, 1, 0, ksize=3, scale=1,
delta=0, borderType=cv2.BORDER_DEFAULT)
ret, img_threshold = cv2.threshold(img_sobel, 0, 255,
@hmmbug
hmmbug / hipchatclient.py
Created April 24, 2015 15:32
simple python hipchat command
#!/usr/bin/env python
#
# A mini hipchat client. Sends a message to a predetermined room.
# Requires HypChat (pip install hypchat)
#
# Mark Hollow. April 2015
#
# Config file (hipchat.json), in JSON format:
# {
# "hipchat": {
@hmmbug
hmmbug / set_disk_scheduler.sh
Created July 15, 2014 03:08
bash: detect SSD/HDD and set appropriate disk scheduler
# set disk scheduler
sed -i "/^echo .*queue\/scheduler$/d" /etc/rc.local
for d in /dev/sd?
do
device=${d/\/dev\//}
rotational=$(cat /sys/block/${device}/queue/rotational)
if [ "$rotational" = "0" ] ; then
echo noop > /sys/block/${device}/queue/scheduler
echo "echo noop > /sys/block/${device}/queue/scheduler" >> /etc/rc.local
@hmmbug
hmmbug / get_network_adress.sh
Created July 15, 2014 03:00
bash - calculate network address from IP address & netmask
#!/bin/bash
IP_ADDR=$(hostname -i)
IFS=. read -r io1 io2 io3 io4 <<< "$IP_ADDR"
IFS=. read -r mo1 mo2 mo3 mo4 < <(ifconfig -a | sed -n "/inet addr:$IP_ADDR /{ s/.*Mask://;p; }")
NET_ADDR="$((io1 & mo1)).$(($io2 & mo2)).$((io3 & mo3)).$((io4 & mo4))"
@hmmbug
hmmbug / graphite
Created April 28, 2014 17:32
ubuntu 14.04 + graphite + nginx
# goes in /etc/nginx/sites-available & link in ../sites-enabled
upstream graphite {
server unix:///tmp/uwsgi.sock;
}
server {
listen 9002;
server_name localhost;