Skip to content

Instantly share code, notes, and snippets.

@smashwilson
Created April 12, 2014 14:26
Show Gist options
  • Save smashwilson/10538383 to your computer and use it in GitHub Desktop.
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.
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
@smashwilson
Copy link
Author

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 with CONFIGURE_OPTS=--enable-shared rbenv install 2.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment