Last active
December 30, 2015 12:09
-
-
Save paul-ihnatolia/7827275 to your computer and use it in GitHub Desktop.
Ruby OpenCV
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 "opencv" | |
include OpenCV | |
WINDOW_NAME = "Difference visualization" | |
# read videostream from camera | |
camera = OpenCV::CvCapture.open(0) | |
# open simple window wedget | |
# can show (CvMat/IplImage) | |
window = OpenCV::GUI::Window.new(WINDOW_NAME) | |
def image_diff(img0, img1, img2) | |
d1 = img2.abs_diff(img1) | |
d2 = img1.abs_diff(img0) | |
d1.and(d2) | |
end | |
# First read 3 images | |
t_minus = camera.query() | |
t = camera.query() | |
t_plus = camera.query() | |
while true | |
image = camera.query | |
window.show(image_diff(t_minus, t, t_plus)) | |
# Read next image | |
t_minus = t | |
t = t_plus | |
t_plus = camera.query()#[1] | |
key = OpenCV::GUI::wait_key(10) | |
# ESC is pressed | |
if key == 1048603 | |
window.destroy() | |
break | |
end | |
end | |
puts "Goodbye" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment