0

I have multiple text in image with two background,

i need to ignore background and extract text from my image. ex: 1

2

because of background color ( black and white), it's very difficult to extract text..

i'm using this code:


import cv2
import pytesseract
import numpy as np

#pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
tessdata_dir_config = '--tessdata-dir "/usr/local/Cellar/tesseract-lang/4.1.0/share/tessdata"'


# Load image, grayscale, Otsu's threshold
#image = cv2.imread('/Users/snrt1/PycharmProjects/pythonProjectopencv/image/20.png')
image = cv2.imread('/Users/snrt1/PycharmProjects/pythonProjectopencv/image/150.jpg')

# Load image, convert to HSV, color threshold to get mask
#image = cv2.imread('2.png')
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower = np.array([0, 0, 0])
upper = np.array([100, 175, 110])
mask = cv2.inRange(hsv, lower, upper)

# Invert image and OCR
invert = 255 - mask
data = pytesseract.image_to_string(invert, lang='eng+ara', config='--psm 6')
print(data)

cv2.imshow('mask', mask)
cv2.imshow('invert', invert)
cv2.waitKey()

the result is :

3

he only extracted the sentence with the white background

How i can extract all text from this image ?

thanks

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87

0 Answers0