Skip to content

Instantly share code, notes, and snippets.

@paul-ihnatolia
Last active December 30, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-ihnatolia/7827275 to your computer and use it in GitHub Desktop.
Save paul-ihnatolia/7827275 to your computer and use it in GitHub Desktop.
Ruby OpenCV
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