简体   繁体   中英

Text Extraction from Image with Single letter in it

I have an image F not of much good quality with a single letter in it. I need to extract the value from this

I tried doing this with open CV. the code works on good quality image but need help to extract from this image

from PIL import Image
import pytesseract
import argparse
import os
import cv2
import numpy as np

img = cv2.imread(r"/home/ubuntu/xyz/xyz.jpg")
img = cv2.resize(img, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_CUBIC)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
img = cv2.GaussianBlur(img, (5, 5), 0)
img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)\[1\]  
# Save the filtered image
cv2.imwrite(r"/home/ubuntu/xyz/rr.jpg", img)
# Read text with tesseract for python
result = pytesseract.image_to_string(img, lang="eng")
result

why u need Gaussian Blur in this situation

img = cv2.GaussianBlur(img, (5, 5), 0)

with a big window (5,5)

I think you can make a white border outside instead of resizing the image, and you may use erosion technical to remove the noise from image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM