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,