Created
April 30, 2017 16:21
-
-
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
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 '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 |
Author
BanzaiMan
commented
Apr 30, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment