Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Recognize text from image. #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Image-Processing/Recogize_Text_From_Image/Recognize_text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Recognize Text From Image.
_LIBRARIES USED:_

pytesseract
cv2
os
PIL
#### Installing tesseract
[You can download .exe file from here](https://github.com/UB-Mannheim/tesseract/wiki)
```bash
Then you can provide the path
# path to the Tessaract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
```
#### Installing cv2 module
```bash
pip install opencv-python
```
19 changes: 19 additions & 0 deletions Image-Processing/Recogize_Text_From_Image/Text_Recognizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from PIL import Image
import pytesseract
import cv2
import os

# path to the Tessaract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image = cv2.imread("image.jpg") #read image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #convert image into gray colored image
filename = "{}.jpg".format(os.getpid())
cv2.imwrite(filename, gray) #write image into file
text = pytesseract.image_to_string(Image.open(filename)) #convert image into string and store in variable text
cv2.imshow("Image", image)
cv2.imshow("Output", gray)
cv2.waitKey(1)
print("successfully found") if 'NEVER' in text else print("Text Not Found")
os.remove(filename)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.