ruby-on-rails - Ruby on Rails - Rtesseract 不适用于 Heroku
问题描述
我正在尝试部署 Heroku RTesseract 功能以读取图像上的文本。
我将 gem 添加到 Gemfile
gem 'rtesseract'
我将该功能实现到PagesController#home
(确保它很脏,但在添加到我的真实应用程序之前用于测试)
class PagesController < ApplicationController
def home
image = RTesseract.new('https://www.drillster.com/info/img/screenshot-ticket-received.en.png')
@result = image.to_s
end
end
它运行良好http://localhost:3000/
。我可以看到页面的文字打印
当我在 Heroku 上部署时,我添加了以下 buildpacks :
heroku buildpacks:set heroku/ruby
heroku buildpacks:add https://github.com/pathwaysmedical/heroku-buildpack-tesseract
当我在 Heroku 上启动我的应用程序时,我可以看到错误:
Tesseract::Error (Cannot open input file:
https://www.drillster.com/info/img/screenshot-ticket-received.en.png)
代码执行该行时出现错误@result = image.to_s
如果有人已经解决了这个问题,帮助我真的很高兴!
提前感谢您的帮助和阅读!
解决方案
所以看起来他们在这个提交中添加了 libcurl 以从 URLS 获取图像:
https://github.com/tesseract-ocr/tesseract/commit/286d8275c783062057d09bb8e5e6607a8917abd9
那是在 2019 年 10 月
在此处查看更改日志: https ://github.com/tesseract-ocr/tesseract/blob/master/ChangeLog
我们看到版本 2018-10-29 - V4.0.0
该构建包中的版本是: https ://github.com/pathwaysmedical/heroku-buildpack-tesseract/blob/master/tesseract-ocr-4.0.tar.gz
所以我猜buildpack版本不支持通过URL获取图像。我敢打赌,当您在本地运行它时,您拥有的是 4.1 而不是旧的 4.0?
您可以分叉该构建包,获取最新源并使用 libcurl 编译它,或者您可以尝试将其下载到临时文件,然后将该临时文件位置传递给库。尽管出于各种原因这并不好,但您可能希望在完成后将其删除。
如果我对版本号有误,请告诉我。
如果你安装了 httparty,你可以做这样的事情来测试它
url = 'https://www.drillster.com/info/img/screenshot-ticket-received.en.png'
File.open("/tmp/test_file.jpg", "wb") do |f|
f.write HTTParty.get(url).body
end
image = RTesseract.new('/tmp/test_file.jpg')
image.to_s
# "Requested ticket\n\nTo make this test, a user must have a ticket....."
推荐阅读
- r - 如何计算 R 中不同月份的 MTD
- apache - 我如何为整个网站做 https,除了一个文件夹?
- php - 偶数、奇数、奇数、偶数、偶数等的模运算符
- android - 我在另一个类的数据库助手类中检索我的插入函数但是当我运行应用程序时它显示空异常
- mysql - 将主键从 id 切换到数据透视表中的值组合
- mysql - 在 MySQL 中通过分隔符拆分并获取字符串的一部分
- kubernetes - System.exit(1) 上的 GCP Kubernetes 行为
- node.js - 如何使用nodejs在单个查询中将文档插入多个集合
- jquery - 如何使用复选框逻辑显示 div?
- java - 从二进制数据在android pdf查看器中显示PDF