Pytesseract未提供预期结果。

huangapple go评论49阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年1月9日 16:53:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定