CodingMSTR LogoCodingMSTR
Python OCR Project | Text Detection Using Python

Python OCR Project | Text Detection Using Python

Free

<span style="letter-spacing: 0.1px;">Text Detection Using Python | Python OCR Program</span>

Category: Python, Machine Learning
Added On: September 23, 2024
Developer: By Praveen
Demo/LiveYoutube Video

For any customization or code setup, feel free to contact us. We also offer deployment on live servers.

For any issues related to downloading, email me at devpraveenkr@gmail.com

Need additional support or customization? Contact me!

Project Screenshots

No screenshots available

Project Description

import cv2
import pytesseract

# Set the path for the Tesseract executable (only for Windows users)
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

# Load the image
image = cv2.imread('image.png')  # Replace with your image path

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Apply thresholding to preprocess the image (optional)
# You can adjust the thresholding method as needed
thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY_INV)[1]

# Use Tesseract to do OCR on the preprocessed image
custom_config = r'--oem 3 --psm 6'  # OEM: 3 (default), PSM: 6 (Assume a single uniform block of text)
text = pytesseract.image_to_string(thresh, config=custom_config)

# Print the recognized text
print("Recognized Text:")
print(text)

# Optional: Display the original image and the processed image
cv2.imshow('Original Image', image)
cv2.imshow('Processed Image', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

Project Demo Video