Ruby Rails - Rtesseract 无法在 Heroku 上运行
Ruby on Rails - Rtesseract not working on 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 上部署时,我添加了以下构建包:
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....."
我正在尝试在 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 上部署时,我添加了以下构建包:
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....."