gpt4 book ai didi

python - Python + OpenCV + Pytesseract建议

转载 作者:行者123 更新时间:2023-12-02 16:07:02 25 4
gpt4 key购买 nike

我正在尝试对此图像进行OCR处理,该图像会有所不同(0-4 / 4):enter image description here

我一直在尝试使用Pytesseract,但没有得到正确的结果。

这是我到目前为止所拥有的:

screen_crop = cv2.imread(screen)
screen_gray = cv2.cvtColor(screen_crop, cv2.COLOR_BGR2GRAY)
screen_thresh = cv2.threshold(screen_gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
screen_noise = cv2.medianBlur(screen_thresh, 1)
cv2.imshow('img', screen_noise)
ocr = pytesseract.image_to_string(screen_noise)
print(ocr)
cv2.waitKey(0)

这是使用OpenCV处理后的结果: enter image description here

OCR返回“re”,“res” ...

建议(不需要是pytesseract)吗?谢谢!

最佳答案

使用keras-ocr而不是pytesseract我获得了一些不错的OCR结果。这是我用于测试的colab笔记本的链接:https://colab.research.google.com/drive/1ccohrWn98EF4VdAtwl-shs4S5RxDu0Ew

import matplotlib.pyplot as plt
import keras_ocr

# keras-ocr will automatically download pretrained
# weights for the detector and recognizer.
pipeline = keras_ocr.pipeline.Pipeline()

def get_predictions(images, keywords=None, plot=False):
images = [keras_ocr.tools.read(url) for url in images]
prediction_groups = pipeline.recognize(images)
words = [[prediction[0] for prediction in image
if prediction[0] in (keywords or [])
or keywords == None]
for image in prediction_groups]
if plot:
# Plot the predictions
fig, axs = plt.subplots(nrows=len(images), figsize=(20, 20))
for ax, image, predictions in zip(axs, images, prediction_groups):
keras_ocr.tools.drawAnnotations(image=image,
predictions=predictions,
ax=ax)
return words

输入:
search_images = [
'/image/ybpke.png',
'https://cdn1.egglandsbest.com/assets/images/products/_productFeatureMobi/shell_classic-12over@2x.jpg',
'https://egglandsbest.coyne-digital.com/wp-content/uploads/2014/08/classic-eggs-MTB.png',
'https://www.utahsown.org/wp-content/uploads/2017/05/egglands_best_eggs_large_18ct_foam_MT.jpg',
'https://egglandsbest.coyne-digital.com/wp-content/uploads/2014/08/egglands_best_cage-free_eggs_large_12ct_plastic_MT.jpg',
'https://cdn1.egglandsbest.com/assets/images/products/_productFeatureMobi/shell_classic-24over@2x.jpg',
]

search_keywords = [
'egglands',
'best',
'extra',
'large',
'cage',
'free',
'vegetarian',
'24',
'12',
'18',
'014'
]



predicted_words = get_predictions(search_images)

print(predicted_words)

输出:
[['014'], ['your', 'fresh', 'farm', 'nowi', 'for', 'diet', 'nutritious', 'alits', 'egglands', 'eb', 'best', 'excellent', 'source', 'ofe', 'brandspark', 'vitamins', 'ppro', 'most', 'b5', 'egg', 'b12', 'superior', 'tasting', 'b2', 'americas', 'd', 'e', 'trusted', 'large', 'plus125mg', 'omega', '3', 'grade', 'a', 'eggs', '12', 'saturated', 'fat', '250', 'less', 'american', 'by', 'regular', 'eggs', 'than', 'shoppers', 'fed', 'hens', 'vegetarian', 'per', 'egg', 'lb', 'oz', 'boo', 'colestero', 'coten', 'net', 'wt', '24', 'oz1', 'b', 'facts', 'fon', 'ssee', 'uirmon', 's', 'n', ''], ['farm', 'fresh', 'stays', 'nowi', 'egglands', 'longer', 'fresher', 'best', 'lles', 'vitatnins', 'd', 'biz', 'e', 'zeggse', 'b', 'gradealarge', 'amlne', 'hs', 'ule', 'oe', 'raing', 'doe', 'taltes', 'ce'], ['stays', 'nowi', 'longer', 'eb', 'fresher', 'farm', 'fresh', 'excellent', 'source', 'of', 'eggiands', 'vitamins', 'd', 'brandseer', 'b12', 'e', 'most', 'trusted', 'good', 'best', 'source', 'of', 'soerens', 'vitamins', 'b2', 'b5', 'plusllsmg', 'omega', '3', 'anericas', 'superior', 'tasting', 'egs', '250', 'less', 'saturated', 'fat', '18', 'eggssa', 'large', 'gradea', 'than', 'regular', 'eggs', 'peregg', 'lleg', 'ensizels', 'dibs', 'asia', 'cottn', 'vegetarian', 'fed', 'hens'], ['farm', 'fresh', 'stays', 'nowa', 'le', 'egglands', 'longer', 'free', 'eb', 'fresher', 'best', 'd', 'cage', 'pro', 'excellent', 'source', 'of', 'vitamins', 'd', 'b12', 'e', 'most', 'good', 'source', 'of', 'trusted', 'vitamins', 'b2', 'b5', 'vecetarian', 'plusil', 'fed', 'smess', 'hens', 'omega', '3', '259', '12', 'eggs', 'saturated', 'grade', 'fat', 'ag', 'large', 'brown', 'than', 'regular', 'eggs', 'etranso'], ['your', 'nowhi', 'for', 'diet', 'nutritious', 'eb', 'fresh', 'farm', '0', 'r', 'egglands', 'excellent', 'source', 'of', 'vitamins', 'best', 'b2', 'b12', 'b5', 'd', 'e', 'tasting', 'egg', 'plusi25mg', 'americas', 'superior', 'omega', '3', '250', 'saturated', 'fat', 'less', 'large', 'eggs', 'than', 'regular', 'a', 'grade', 'egg', 'per', 'wuamon', 'icts', 'fon', 'chclesten', 'content', 'sel', '24', 'eggs', 'fed', 'vegetarian', 'hens', 'usda', 'keep', 'refrigerated', 'bandsparl', 'a', 'or', 'below', '45f', 'at', 'most', 'gde', 'trusted', 'wt', '15', 'oz', '3', 'lbsi', '1301', 'net', 'american', 'shofters', 'atons', 'torc', 's']]

您可以指定要执行ocr的网址列表和(可选)要在这些图像中找到的单词列表。它将返回在每个图像中找到的单词列表的列表。您还可以可视化输出,并为每个检测看到带注释的边界框。

关于python - Python + OpenCV + Pytesseract建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61665223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com