0

I detected the text in my image using EASYOCR and used TESSERACT to do the recognition, but the text that is rotated could not be detected. How I can detect rotated text? I used this code:

# # Text detection with easyocr and recognition with tesseract
import cv2
import easyocr
import pytesseract
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"

# Load image
image = cv2.imread('image 18.jpg')

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

# Initialize the EasyOCR text detector
reader = easyocr.Reader(['en'])

# Detect text in image
results = reader.readtext(gray)

# Image preprocessing for Tesseract
_, processed_image = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

# Recover text regions detected by EasyOCR
for (bbox, _, _) in results:
    # Extract coordinates from bounding box
    x_min, y_min = map(int, bbox[0])
    x_max, y_max = map(int, bbox[2])
    # Vérifier les limites de l'image
    x_min = max(0, x_min)
    y_min = max(0, y_min)
    x_max = min(image.shape[1], x_max)
    y_max = min(image.shape[0], y_max)
    # # Extract text region
    if x_max>x_min and y_max>y_min :
        text_region = processed_image[y_min:y_max, x_min:x_max]

        # Text recognition with Tesseract
        text = pytesseract.image_to_string(text_region, lang='eng')

        # # Draw the bounding box on the image
        cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)

        # Display text detected by Tesseract
        cv2.putText(image, text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)


# Display image with bounding boxes and detected text
cv2.imwrite('Text Detection_2.jpg', image)

Result: enter image description here

Woodford
  • 3,746
  • 1
  • 15
  • 29
  • Do you know the angle at which the text is rotated? You could try rotating the image in the opposite direction and process it multiple times at all the required angles. – Julian Jun 08 '23 at 17:12
  • no, I don't know the angle of rotation, since there can be several angles of rotation in each text. Rotation angle can change from text to text – Kawtar Zidouh Jun 08 '23 at 17:55

0 Answers0