Not sure which shell you're using, but you should take a look at this: Ruby / OpenCV is a Ruby OpenCV shell .
Face Detection Sample:
#!/usr/bin/env ruby require 'opencv' include OpenCV
The classifier can be downloaded here .
EDIT
The following code uses OpenCV, rb_webcam gem, and RMagick to capture a webcam image and save it as a jpg file:
require 'rb_webcam' require 'RMagick' capture = Webcam.new image = capture.grab width = image.size[:width] rows = image.data.unpack("C*").each_slice(3).to_a.each_slice(width).to_a capture.close height = rows.length img = Magick::Image.new width, height rows.each_with_index do |r, i| q = r.map {|b, g, r| Magick::Pixel.new r * 256, g * 256, b * 256, 0} img.store_pixels(0, i, width, 1, q) end img.format = 'jpg' img.write 'webcam.jpg'
source share