python-tesseract

image_to_string doesn't work in Mac

折月煮酒 提交于 2019-12-07 03:34:13
问题 I'm trying to follow this example of pytesser (link) in a Mac Maverick. >>> from pytesser import * >>> im = Image.open('phototest.tif') >>> text = image_to_string(im) But, in the last line I get this error message: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pytesser.py", line 31, in image_to_string call_tesseract(scratch_image_name, scratch_text_name_root) File "pytesser.py", line 21, in call_tesseract proc = subprocess.Popen(args) File "/Library/Frameworks

Pytesseract random bug when reading text

女生的网名这么多〃 提交于 2019-12-06 13:17:06
I'm creating a bot for a video game and I have to read some information displayed on the screen. Given that the information is always at the same position, I have no issue to take a screenshot and crop the picture to the right position. 90% of the time, the recognition will be perfect, but sometimes it will return something that seems totally random (see the example below). I've tried to turn the picture into black and white with no success, and tried to change the pytesseract config (config = ("-l fra --oem 1 --psm 6")) def readScreenPart(x,y,w,h): monitor = {"top": y, "left": x, "width": w,

How to fill the gaps in letters after Canny edge detection

折月煮酒 提交于 2019-12-06 06:34:50
问题 I'm trying to do an Arabic OCR using Tesseract, but the OCR doesn't work unless the letters are filled with black color. How do I fill the gaps after Canny edge detection? Here is a sample image and sample code: import tesserocr from PIL import Image import pytesseract import matplotlib as plt import cv2 import imutils import numpy as np image = cv2.imread(r'c:\ahmed\test3.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.bilateralFilter(gray,30,40,40) #gray = cv2.GaussianBlur

How to process and extract text from image

谁说胖子不能爱 提交于 2019-12-06 06:18:48
I'm trying to extract text from image using python cv2. The result is pathetic and I can't figure out a way to improve my code. I believe the image needs to be processed before the extraction of text but not sure how. I've tried to convert it into black and white but no luck. import cv2 import os import pytesseract from PIL import Image import time pytesseract.pytesseract.tesseract_cmd='C:\\Program Files\\Tesseract-OCR\\tesseract.exe' cam = cv2.VideoCapture(1,cv2.CAP_DSHOW) cam.set(cv2.CAP_PROP_FRAME_WIDTH, 8000) cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 6000) while True: return_value,image = cam

Symbol lookup error while using Tesseract

十年热恋 提交于 2019-12-06 03:40:58
I've been using Tesseract 4, for a project for more than two months now. (This means that it's running on input images for more than two months.) The problem that I'm shown is: multiprocess.pool.RemoteTraceback: """ Traceback (most recent call last): File "/home/cse/.local/lib/python3.5/site-packages/multiprocess/pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "/home/cse/.local/lib/python3.5/site-packages/multiprocess/pool.py", line 44, in mapstar return list(map(*args)) File "/home/cse/.local/lib/python3.5/site-packages/pathos/helpers/mp_helper.py", line 15, in <lambda

Image Preprocessing for OCR - Tessaract

旧时模样 提交于 2019-12-05 18:08:31
Obviously this image is pretty tough as it is low clarity and is not a real word. However, with this code, I'm detecting nothing close: import pytesseract from PIL import Image, ImageEnhance, ImageFilter image_name = 'NedNoodleArms.jpg' im = Image.open(image_name) im = im.filter(ImageFilter.MedianFilter()) enhancer = ImageEnhance.Contrast(im) im = enhancer.enhance(2) im = im.convert('1') im.save(image_name) text = pytesseract.image_to_string(Image.open(image_name)) print(text) outputs , Mdfiaodfiamms Any ideas here? The image my contrasting function produces is: Which looks decent? I don't have

Read text from image using OCR for the image which have two columns or three columns of data using python

独自空忆成欢 提交于 2019-12-05 07:14:21
问题 In the example image (just a reference, my images will be of same pattern) a page which have full horizontal text and other have two horizontal column of text. How to automatically detect the pattern of the document and read one after the other column of data in python?. I am using Tesseract OCR with Psm 6, where it is reading horizontally which is wrong. 回答1: One way to accomplish this is using morphological operations and contour detection. With the former you essentially "bleed" all

image_to_string doesn't work in Mac

拜拜、爱过 提交于 2019-12-05 06:22:44
I'm trying to follow this example of pytesser ( link ) in a Mac Maverick. >>> from pytesser import * >>> im = Image.open('phototest.tif') >>> text = image_to_string(im) But, in the last line I get this error message: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pytesser.py", line 31, in image_to_string call_tesseract(scratch_image_name, scratch_text_name_root) File "pytesser.py", line 21, in call_tesseract proc = subprocess.Popen(args) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__ errread, errwrite)

How to fill the gaps in letters after Canny edge detection

一笑奈何 提交于 2019-12-04 17:00:19
I'm trying to do an Arabic OCR using Tesseract, but the OCR doesn't work unless the letters are filled with black color. How do I fill the gaps after Canny edge detection? Here is a sample image and sample code: import tesserocr from PIL import Image import pytesseract import matplotlib as plt import cv2 import imutils import numpy as np image = cv2.imread(r'c:\ahmed\test3.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.bilateralFilter(gray,30,40,40) #gray = cv2.GaussianBlur(gray,(1,1), 0) gray =cv2.fastNlMeansDenoising(gray ,None, 4, 7, 21) image = cv2.adaptiveThreshold(gray

get Font Size in Python with Tesseract and Pyocr

空扰寡人 提交于 2019-12-04 13:13:46
Is it possible to get font size from an image using pyocr or Tesseract ? Below is my code. tools = pyocr.get_available_tools() tool = tools[0] txt = tool.image_to_string( Imagee.open(io.BytesIO(req_image)), lang=lang, builder=pyocr.builders.TextBuilder() ) Here i get text from image using function image_to_string . And now, my question is, if i can get font-size (number) too of my text. Using tesserocr , you can get a ResultIterator after calling Recognize on your image, for which you can call the WordFontAttributes method to get the information you need. Read the method's documentation for