Posts

Showing posts from May, 2017

Install OpenCV to work with Python

Image
This tutorial will install OpenCV 2.4 for Python 2.7on Windows. Download OpenCV for your OS from  https://sourceforge.net/projects/opencvlibrary/files/ I use opencv cv 2.4 for windows  https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/ Extract opencv to a folder  Install Python 2.7 Copy file cv2.pyd in folder /opencv/build/python/2.7/x64 to Python27/Lib/site-packages/ We will need instal numpy library: pip install numpy Test with simple code: import cv2 print "Read image with opencv" img = cv2 . imread( "E:/test.png" ) print "Convert to gray" img = cv2 . cvtColor(img, cv2 . COLOR_BGR2GRAY) print "Write gray image" cv2 . imwrite( "E:/gray.png" , img) print "------ Done -------" Result:

Recognize text from image with Python + OpenCV + OCR

Image
Requires Python 2.7 Pillow (3.4.2) pytesseract (0.1.6) => OCR numpy (1.11.2) Opencv-2.4.13 (cv2)=> OpenCV Note: library version above while writing this blog. You may need  How to install OpenCV to work with Python? We use OpenCV before recognize text from image to increase accuracy. Video: https://youtu.be/83vFL6d57OI Source code: import cv2 import numpy as np import pytesseract from PIL import Image # Path of working folder on Disk src_path = "E:/Lab/Python/Project/OCR/" def get_string (img_path): # Read image with opencv img = cv2 . imread(img_path) # Convert to gray img = cv2 . cvtColor(img, cv2 . COLOR_BGR2GRAY) # Apply dilation and erosion to remove some noise kernel = np . ones(( 1 , 1 ), np . uint8) img = cv2 . dilate(img, kernel, iterations = 1 ) img = cv2 . erode(img, kernel, iterations = 1 ) # Write image after removed noise cv2 . imwrite(src_path + "removed_nois...