Explore Tesseract Optical Character Recognition (OCR)

Bagan Proses
from PIL import Image
import pytesseract
import numpy as np
import cv2
import os
import matplotlib.pyplot as plt
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
filename1 = 'C:/Users/Cahya/Downloads/Test/T1.png'
img1 = Image.open(filename1)
img1
Sample 1
image = cv2.imread(filename1)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
imgplot = plt.imshow(rgb)
plt.show()
text = pytesseract.image_to_string(rgb)text
'Tesseract sample'
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
filename2 = 'C:/Users/Cahya/Downloads/Test/test2.png'
img2 = Image.open(filename2)
img2
Sample 2
image = cv2.imread(filename2)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 3)
imgplot = plt.imshow(gray)
plt.show()
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)
True
image = cv2.imread(filename)
imgplot = plt.imshow(image)
plt.show()
text = pytesseract.image_to_string(image)
text
'Tesseract sample'
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
filename3 = 'C:/Users/Cahya/Downloads/Test/KartuNama.jpg'
img = Image.open(filename3)
img
sample 3
image = cv2.imread(filename3)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
imgplot = plt.imshow(gray)
plt.show()
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)
True
image = cv2.imread(filename)
imgplot = plt.imshow(image)
plt.show()
text = pytesseract.image_to_string(image)
text
'w) Sinergi Wahana Gemilang\n[GB Value Added Distributor\n\n \n\nCahyati Supriyati Sangaji\nSolution Specialist\nIBM Software - Internet of Things & Artificial Intelligence\n\n+62-821-41561927\ncahyati.sangaji@swgemilang.com'
## Normalize
for word in text.split("\n"):
if "w)" in word:
word = word.replace("w)", "@")
if "[GB" in word:
word = word.replace("[GB", "@")

print(word)
@ Sinergi Wahana Gemilang
@ Value Added Distributor



Cahyati Supriyati Sangaji
Solution Specialist
IBM Software - Internet of Things & Artificial Intelligence

+62-821-41561927
cahyati.sangaji@swgemilang.com

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store