Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Created April 30, 2017 16:21
Show Gist options
  • Save BanzaiMan/8bab2a28c11e37c411405cdda1a151a6 to your computer and use it in GitHub Desktop.
Save BanzaiMan/8bab2a28c11e37c411405cdda1a151a6 to your computer and use it in GitHub Desktop.
OpenCV: Show what camera sees, capture if anything other than 'q' is pressed
require 'rubygems'
require 'opencv'
include OpenCV
camera = CvCapture.open(1)
window = GUI::Window.new("camera")
while true
camera.grab
window.show(img = camera.retrieve)
key = GUI.wait_key(33)
if key == 'q'.ord
break
else
open('foo.jpg', 'wb') do |f|
f.write img.encode('.jpg').pack("c*")
end
end
end
@BanzaiMan
Copy link
Author

BanzaiMan commented Apr 30, 2017

$ brew install opencv # or equivalent on other platforms
$ gem install opencv

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