英文:
Pytesseract not giving excpected resaults
问题
使用 pytesseract 进行图像转文本,并进行了一些基本的图像增强,问题是我得到了非常奇怪的结果。
Python
import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance
filename = 'image3.png'
color_image = Image.open(filename)
# 增强颜色级别
curr_col = ImageEnhance.Color(color_image)
new_col = 5
img_colored = curr_col.enhance(new_col)
# 增强锐度
curr_col = ImageEnhance.Sharpness(color_image)
new_enh = 2
img_colored = curr_col.enhance(new_enh)
# 颜色级别增强了 2.5 倍
bw = img_colored.convert('L')
bw.save('BW_image.png')
img_colored.save('enchanc.png')
img1 = np.array(Image.open("BW_image.png"))
text = pytesseract.image_to_string(img1)
print(text)
英文:
using pytesseract for image to text along with some basic image enhancing, Problem is that im getting very weird resaults.
Pyton
import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance
filename = 'image3.png'
color_image = Image.open(filename)
# Enhance Color Level
curr_col = ImageEnhance.Color(color_image)
new_col = 5
img_colored = curr_col.enhance(new_col)
\#enhance sharpness
curr_col = ImageEnhance.Sharpness(color_image)
new_enh = 2
img_colored = curr_col.enhance(new_enh)
# Color level enhanced by a factor of 2.5
bw = img_colored.convert('L')
bw.save('BW_image.png')
img_colored.save('enchanc.png')
img1 = np.array(Image.open("BW_image.png"))
text = pytesseract.image_to_string(img1)
print(text)
This is image3.png and this is what i get printed in the console
"Nam 65 can gala"
image3.png
答案1
得分: 0
从你的代码中可以看出,你对图像 'image3.png' 进行了一些增强处理,但之后你打开了另一张图像 'img1',然后将其传递给 pytesseract。
import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance
filename = 'image3.png'
color_image = Image.open(filename)
text = pytesseract.image_to_string(color_image)
print(text)
这段代码输出的结果是:利润:68.0666 金币
英文:
From your code, you apply some enhancements on the image 'image3.png', but you open another image img1 and then pass it to pytesseract.
import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance
filename = 'image3.png'
color_image = Image.open(filename)
text = pytesseract.image_to_string(color_image)
print(text)
this code outputs: Profit: 68.0666 gold
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论