[英]Text extraction from the images
我需要從圖像中提取字符,但是由於周圍的光效,圖像變化很大。 因此,我無法修復任何特定的預處理方法。
我的預處理代碼如下所示:
from skimage import io
import cv2
from skimage.filters import threshold_otsu, sobel
from skimage import img_as_ubyte
import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
image = io.imread(imgg)
dim = (700, 100) #76 pixels
resized_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
image = rgb2gray(resized_image)
threshold = threshold_otsu(image)
bina_image = image < threshold
img = img_as_ubyte(bina_image )
image_copy = img.copy()
kernel = np.ones((3,3), np.uint8)
clahe = cv2.createCLAHE(clipLimit=5.0, tileGridSize=(1,1))
img[:,:,0] = clahe.apply(img[:,:,0])
imghsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
imghsv[:,:,2] = [[max(pixel - 25, 0) if pixel < 190 else min(pixel + 25, 255) for pixel in row] for row in imghsv[:,:,2]]
imghsv[imghsv < 170] = 0
imghsv[imghsv > 170] = 255
我嘗試過 tesseract、EasyOCR 和 KerasOCR 等 ocrs,但沒有一個適用於這種情況。 你能建議我如何從這些圖像中獲取所有字符嗎?
文本二值化代表了在不同光照和噪聲下的復雜任務。 諸如灰度級、亮度和背景的變化等因素使閾值方案復雜化。 如果你有足夠的資源,我推薦你谷歌雲視覺
實現它的代碼很容易理解:
def detect_text_uri(uri):
"""Detects text in the file located in Google Cloud Storage or on the Web.
"""
from google.cloud import vision
client = vision.ImageAnnotatorClient()
image = vision.Image()
image.source.image_uri = uri
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.