[英]Extract a white with black border text in an image with a complex background
[英]Extract text from Image with black background
我想在 Python 中使用pytesseract從圖像中提取白色文本,但我沒有得到好的結果。
它向我顯示零為“@”、“a”和“e”。
這是圖像:
這是我正在使用的示例代碼:
import numpy as np
import cv2
import pytesseract
from PIL import Image
def preprocess_finale(im):
im= cv2.bilateralFilter(im, 5, 55,60)
im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
_, im = cv2.threshold(im, 240, 255, 1)
return im
img = Image.open("Image.png")
img = cv2.cvtColor(np.array(img), cv2.COLOR_BGRA2BGR)
im = cv2.imread(img, cv2.IMREAD_GRAYSCALE)
custom_config = r"--oem 3 --psm 4 -c tessedit_char_whitelist= '0123456789. '"
im=preprocess_finale(img)
text = pytesseract.image_to_string(im, lang='eng', config=custom_config)
print(text)
結果如下:
900.265 NITa0e.234 LUX2566 Eulee
有什么解決方案可以得到更好的結果嗎?
您可以在調整大小的圖像版本中使用簡單的 ocr。
import easyocr
import cv2
image = cv2.imread('Di0yp.png')
image = cv2.resize(image,(780,600)) # 740,480 # 740,600
cv2.imwrite('resize.png',image)
reader = easyocr.Reader(['en'],gpu=False)
result = reader.readtext('resize.png')
for detection in result:
print(detection)
所需的輸出是,
([[399, 313], [507, 313], [507, 333], [399, 333]], "'000, 265 NIT", 0.5332222214815537)
([[399, 333], [509, 333], [509, 351], [399, 351]], '000 , 834 LuX', 0.37962750554971325)
([[421, 351], [527, 351], [527, 371], [421, 371]], '0. 566 EV100', 0.440570646870379)
我認為這可能會幫助你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.