使用 Tesseract 忽略符号/图标/小图像

问题描述 投票:0回答:1

Tesseract 在我的图像中做得很好,但是有一些小细节我想修复并使其 100%。

我想在Tesseract过程中忽略这个图标,我什至不想知道是否有东西。

此符号有时会转换为数字或字母。我尝试过使用白名单,但没有解决问题。

我找到了一个可能的解决方案here,但我想知道这是否是我可以采用的最佳选择,或者是否有更简单的方法。

ocr tesseract
1个回答
0
投票

我最终使用了不同的方法来处理这些图标。

我在 ruby 中使用了 Imagemagick,称为 RMagick,它在图像上绘制了一个覆盖所有图标的矩形,并且下面的代码将图像着色为黑白。

require 'rmagick'

class PdfConverter
  include Magick

  def process_image
    pdf_path = 'file.pdf'
    pdf_image = Magick::Image.read(pdf_path) do |options|
      options.density = 400
    end

    pdf_image.each_with_index do |image, i|
      canvas = Magick::Image.new(image.columns, image.rows) do |options|
        options.background_color = 'white'
      end

      # Composite the PDF image on the canvas with alpha handling
      canvas.composite!(image, 0, 0, Magick::OverCompositeOp)
      canvas.alpha(Magick::DeactivateAlphaChannel)
      canvas = canvas.quantize(2, Magick::GRAYColorspace)

      gc = Magick::Draw.new

      gc.fill_opacity(1)
      gc.fill('white')

      # Draw rectangle
      gc.rectangle(1100, 1000, 1200, 4000)
      gc.draw(canvas)

      # Save the resulting image as "b.png"
      canvas.write("public/uploads/#{i}colorize.png")
    end
  end
end
© www.soinside.com 2019 - 2024. All rights reserved.