DEV Community

Taresh Chaudhari
Taresh Chaudhari

Posted on

Reading Text from Rubber product

Image description
Hi,
I am trying to read the characters from the image, which has characters with black color in the background. Attaching the code which i used to extract, currently its giving the partial output. Can you help me to guide how to make it accurate?

import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'C:\Users\M562765\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'

Paths to your images

image_paths = [
'C:/Users/M562765/Downloads/Unable-images/Unable/crop1.jpg']

Function to process an image and extract text

def extract_text_from_image(image_path):
# Open the image
img = Image.open(image_path)

# Use pytesseract to perform OCR
extracted_text = pytesseract.image_to_string(img, config='--psm 6') # PSM 6 assumes a block of text
return extracted_text.strip()
Enter fullscreen mode Exit fullscreen mode




Process all images and print results

for img_path in image_paths:
text = extract_text_from_image(img_path)
print(f"Text extracted from {img_path}: {text}")

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs