Answers for "python text recognition from image"

7

image to text python

from PIL import Image
import pytesseract

image = 'PATH/TO/IMAGE'
text = pytesseract.image_to_string(Image.open(image), lang="eng")
print(text)

# Code From here: https://www.youtube.com/watch?v=kxHp5ng6Rgw
Posted by: Guest on February-02-2021
3

python image to text

# Import some modules
import cv2 # An image proccessing library
import pytesseract # an image to text library
import numpy as np # used for mathematics but can be used in image proccessing

# Configure the module
pytesseract.pytesseract.tesseract_cmd = r'C:UsersyournameAppDataLocalTesseract-OCRtesseract.exe'

# Make the image grey
img = cv2.imread('your_img.png')
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
gray, img_bin = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
gray = cv2.bitwise_not(img_bin)
kernel = np.ones((2, 1), np.uint8)
img = cv2.erode(gray, kernel, iterations=1)
img = cv2.dilate(img, kernel, iterations=1)
# Use OCR to read the text from the image
out_below = pytesseract.image_to_string(img)
# Print the text
print(out_below)
Posted by: Guest on June-27-2020
5

text recognition python library

import cv2 
import pytesseract

img = cv2.imread('image.jpg')

# Adding custom options
custom_config = r'--oem 3 --psm 6'
pytesseract.image_to_string(img, config=custom_config)
Posted by: Guest on November-08-2020
0

text extraction from image using ocr python

1| # importing modules
2| import cv2
3| import pytesseract
5| # reading image using opencv
6| image = cv2.imread(sample_image.png’)
7| #converting image into gray scale image
8| gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9| # converting it to binary image by Thresholding
10| # this step is require if you have colored image because if you skip this part
11| # then tesseract won't able to detect text correctly and this will give incorrect result
11|threshold_img = cv2.threshold(gray_image, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
12| # display image
13| cv2.imshow(‘threshold image’, threshold_img)
14| # Maintain output window until user presses a key
15| cv2.waitKey(0)
16| # Destroying present windows on screen
17| cv2.destroyAllWindows()
Posted by: Guest on August-16-2021

Code answers related to "python text recognition from image"

Python Answers by Framework

Browse Popular Code Answers by Language