【问题标题】:Slicing an image into strips for OCR将图像切片以进行 OCR
【发布时间】:2021-08-18 11:37:10
【问题描述】:

我正在尝试将 PNG 切片成一系列条带,因此我可以使用 tesseract 准确读取银行对帐单的每一行(如果有东西已经读取了银行对帐单,请告诉我

我已经开始使用image slicer 库,它只分割成图块。

import image_slicer
from PIL import Image

pages = convert_from_path('OCRBeebun/Bacon.pdf', 500)
i = 0
firstRun = False

if firstRun:
    for page in pages:

        page.save("img_"+str(i)+'.png','PNG')
        i+=1


image_slicer.slice("img_0.png",14)

有什么想法吗?

【问题讨论】:

  • 分享代码?
  • @UrDistraction 将其切成 14 个图块,无论如何它可以是行切片吗?

标签: python image ocr tesseract


【解决方案1】:

如果您使用cv2.imread() 打开图像,那么您可以像切片字符串一样切片图像(您还必须为此导入 numpy),例如,

import numpy
import cv2

img = cv2.imread('path-to-image.png', cv2.IMREAD_GRAYSCALE) # you can have that flag if u need it tho
# if you have the coordinates to slice the image, then
cropped_img = img[height_start:height_end, width_start:width_end]
# You can also run the above line in a loop to get more than one sliced image

# To save the sliced image
cv2.imwrite('cropped_image.png', cropped_img)

在 height_start、height_end、width_start 和 width_end 中输入您的值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    相关资源
    最近更新 更多