我使用EASYOCR检测图像中的文本,并使用TESSERACT进行识别,但无法检测到旋转的文本。如何检测旋转的文本? 我使用了这段代码:
# # 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)