[英]Extract digit from noisy image
從噪聲圖像中提取數字
我想從手機相機拍攝的圖像中提取文本。 首先,我嘗試使用以下代碼將圖像轉換為灰度:
imgg = Image.open('originale.jpg').convert('LA')
其次,我嘗試使用此代碼對灰度圖像進行閾值處理以獲取只有黑白的圖像::
retval, threshold = cv2.threshold(grayscaled, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imwrite("threshold.png", threshold)
第三,我嘗試使用 pytesseract 提取文本,但這段代碼的結果不正確。
result5 = pytesseract.image_to_string(Image.open("threshold.png"))
這是我要提取數字的圖像,例如:我預期的 output 是: 111 2 11 4 1 23 2 3
。
這是我的形象:
這是我的完整代碼:
import cv2
import numpy as np
import pytesseract
from PIL import Image
img = cv2.imread('originale.jpg')
grayscaled = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
retval, threshold = cv2.threshold(grayscaled, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imwrite("threshold.png", threshold)
result = pytesseract.image_to_string(Image.open("threshold.png"))
print(result)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.