我使用了EAST?(高效準確的場景文本檢測器)的以下PyTorch 實現來識別和繪制許多圖像中文本周圍的邊界框,效果非常好!pytesseract但是,為了從這些圖像中提取文本并將它們轉換為字符串,我正在嘗試使用 OCR 的下一步——失敗得很厲害。--oem使用和的所有可能配置--psm,我無法檢測到pytesseract看起來非常清晰的文本,例如:已識別的文本位于圖像下方。即使我應用了對比度增強,并嘗試了擴張和腐蝕,我也無法讓 tesseract 識別文本。這只是許多圖像中文本更大更清晰的示例之一。關于轉換、配置或其他庫的任何建議都會有所幫助!更新:在嘗試高斯模糊 + Otso 閾值處理后,我能夠在白色背景上獲得黑色文本(顯然這是 pytesseract 的理想選擇),并且還添加了西班牙語,但它仍然無法閱讀非常純文本 - 例如:讀起來是胡言亂語。處理后的文本圖像是和我正在使用的代碼:img_path = './images/fesa.jpg'img = Image.open(img_path)boxes = detect(img, model, device)origbw = cv2.imread(img_path, 0)for box in boxes:? ??? ? box = box[:-1]? ? poly = [(box[0], box[1]),(box[2], box[3]),(box[4], box[5]),(box[6], box[7])]? ? x = []? ? y = []? ? for coord in poly:? ? ? ? x.append(coord[0])? ? ? ? y.append(coord[1])? ? startX = int(min(x))? ? startY = int(min(y))? ? endX = int(max(x))? ? endY = int(max(y))? ? #use pre-defined bounding boxes produced by EAST to crop the original image?? ??? ? cropped_image = origbw[startY:endY, startX:endX]? ? #contrast enhancement?? ? clahe = cv2.createCLAHE(clipLimit=4.0, tileGridSize=(8,8))? ? res = clahe.apply(cropped_image)? ? text = pytesseract.image_to_string(res, config = "-psm 12")? ??? ? plt.imshow(res)? ? plt.show()? ? print(text)
tesseract 無法識別易于閱讀的文本
慕田峪4524236
2023-05-23 16:33:02