text detection from image using opencv python

Solutions on MaxInterview for text detection from image using opencv python by the best coders in the world

showing results for - "text detection from image using opencv python"
Leah
03 Feb 2018
1#wasim shaikh github:httperror451
2import cv2
3import numpy as np
4import pytesseract
5
6pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
7
8# Load image, convert to HSV format, define lower/upper ranges, and perform
9# color segmentation to create a binary mask
10image = cv2.imread('1.jpg')
11hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
12lower = np.array([0, 0, 218])
13upper = np.array([157, 54, 255])
14mask = cv2.inRange(hsv, lower, upper)
15
16# Create horizontal kernel and dilate to connect text characters
17kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,3))
18dilate = cv2.dilate(mask, kernel, iterations=5)
19
20# Find contours and filter using aspect ratio
21# Remove non-text contours by filling in the contour
22cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
23cnts = cnts[0] if len(cnts) == 2 else cnts[1]
24for c in cnts:
25    x,y,w,h = cv2.boundingRect(c)
26    ar = w / float(h)
27    if ar < 5:
28        cv2.drawContours(dilate, [c], -1, (0,0,0), -1)
29
30# Bitwise dilated image with mask, invert, then OCR
31result = 255 - cv2.bitwise_and(dilate, mask)
32data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
33print(data)
34
35cv2.imshow('mask', mask)
36cv2.imshow('dilate', dilate)
37cv2.imshow('result', result)
38cv2.waitKey()
39
Max
27 Jan 2017
1import cv2
2import numpy as np
3import pytesseract
4
5pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
6
7# Load image, convert to HSV format, define lower/upper ranges, and perform
8# color segmentation to create a binary mask
9image = cv2.imread('1.jpg')
10hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
11lower = np.array([0, 0, 218])
12upper = np.array([157, 54, 255])
13mask = cv2.inRange(hsv, lower, upper)
14
15# Create horizontal kernel and dilate to connect text characters
16kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,3))
17dilate = cv2.dilate(mask, kernel, iterations=5)
18
19# Find contours and filter using aspect ratio
20# Remove non-text contours by filling in the contour
21cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
22cnts = cnts[0] if len(cnts) == 2 else cnts[1]
23for c in cnts:
24    x,y,w,h = cv2.boundingRect(c)
25    ar = w / float(h)
26    if ar < 5:
27        cv2.drawContours(dilate, [c], -1, (0,0,0), -1)
28
29# Bitwise dilated image with mask, invert, then OCR
30result = 255 - cv2.bitwise_and(dilate, mask)
31data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
32print(data)
33
34cv2.imshow('mask', mask)
35cv2.imshow('dilate', dilate)
36cv2.imshow('result', result)
37cv2.waitKey()
38
queries leading to this page
python popencv convert text to imageopencv letter recognitionopencv detect words in page textword detection opencvpyhton text detection opencv liveocr in python using opencv without tesseractfind image quality for text detection pythonpython opencv read text from imagecontour to detection text from thershold imagepython character detectiontext recognition in images by pythonopencv detect text from imagetext detection from image pythonopencv convert image to textcharacter finder in image pythontext detection via opencvtext detection and extraction using opencv andocr in python using opencvtext recognition in images or videos by pythonpython tesseract ocr with opencvopencv text recognitionpython detect text from imagecomplete the missed part in letters in opencvocr with opencvopencv analyse textopencv recognize letterstext detection from open cvdetect text in image opencv from scratchtext detection pythonpyhton text detection opencvpython opencv send text on detectioneast text detection modelpython text detection from imagetext detection from image in pythonopencv text detection demoopencv text detection example pythonreading only horizontal text from image using opencv and tesseract pythonopencv find text in imageopencv text detection pythonopencv reading characters wrongpython text detection libraryopencv detect custom texttesseract to find text final code check extracted text from tesseract text logicperfect text recognition from images pythonopencv detect text in imagedetect letters in image pythonpython opencv text detectionhow to detect text in image using opencv pythonopencv convert image to text c 23detect bounding box text or non text by pythonhow to make boxes of images to read text opencvdetection coordinates of word in images python opencvword detection python opencvcharacters boundary python cv2 text in image image to text detection ocr pythontext detection from image using opencv pythontext detection using opencvdetect text in image python opencvhow to read text from image vertically opencvtext detection in image pythonuse contours to detect text opencv pythonocr using python opencvdetect text from image opencvtext detection from image using opencv pythondetect text cv2text extraction from image using opencv pythonopen cv to detect texttext detection imageopencv text detectionsample images for text detection opencvtext detection opencvdetect text in image opencvread text with open cvtext detection from image using opencv python