Created
April 12, 2014 14:26
-
-
Save smashwilson/10538383 to your computer and use it in GitHub Desktop.
Read images from a webcam. OCR any text and write it to stdout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hornetseye_v4l2' | |
require 'hornetseye_xorg' | |
require 'hornetseye_rmagick' | |
require 'tesseract' | |
include Hornetseye | |
camera = V4L2Input.new | |
image = X11Display.show { camera.read } | |
image.to_ubytergb.save_ubytergb 'snapshot.png' | |
e = Tesseract::Engine.new do |e| | |
e.language = :eng | |
e.blacklist = '|' | |
end | |
puts e.text_for('snapshot.png').strip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This only works on Linux (v4l2 is "video for Linux 2"). My webcam's resolution is also not great, so it can't seem to read things like receipts well (yet -- I've tried basically nothing in terms of preprocessing.)
Also there was a bunch of setup I had to do to get hornetseye installing properly: mostly
apt
stuff, but I also had to rebuild Ruby withCONFIGURE_OPTS=--enable-shared rbenv install 2.1.1
.