1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
Versioned fork of the OpenCV gem for Ruby
Find a file
2014-01-14 18:15:44 +09:00
examples fix facerec sample 2014-01-13 17:42:52 +09:00
ext/opencv update for generating documents 2014-01-14 18:15:44 +09:00
images add documents of CvHaarClassifierCascade 2012-08-05 01:45:20 +09:00
lib bump up version 2013-12-08 19:08:15 +09:00
test support Ruby 2.1.0 and OpenCV 2.4.8 2014-01-04 17:12:04 +09:00
.gitignore Merge branch 'develop' into documentation 2014-01-14 17:45:45 +09:00
config.yml fix config file 2013-05-05 03:34:50 +09:00
DEVELOPERS_NOTE.md update document 2013-05-05 03:34:07 +09:00
Gemfile remove dependency on gem-compile 2013-05-02 02:54:31 +09:00
History.txt Initial commit, with some minor changes from orig (date, exec bit, line endings, /usr/bin/env) 2008-08-19 11:01:28 -04:00
License.txt fix typo of Liscense.txt 2013-03-03 03:01:00 +09:00
Manifest.txt Merge branch 'develop' into documentation 2014-01-14 17:45:45 +09:00
Rakefile load pre-compile configs from config files 2013-05-05 02:23:19 +09:00
README.md support Ruby 2.1.0 and OpenCV 2.4.8 2014-01-04 17:12:04 +09:00
ruby-opencv.gemspec Merge branch 'develop' into documentation 2014-01-14 17:45:45 +09:00
yard_extension.rb update for generating documents 2014-01-14 18:15:44 +09:00

ruby-opencv

An OpenCV wrapper for Ruby.

Requirement

Install

Linux/Mac

  1. Install OpenCV
  2. Install ruby-opencv
$ gem install ruby-opencv -- --with-opencv-dir=/path/to/opencvdir

Note: /path/to/opencvdir is the directory where you installed OpenCV.

Windows

You can use pre-build binary for Windows (mswin32, mingw32).

  1. Install OpenCV
  2. Set path to OpenCV libraries. When you installed OpenCV to C:\opencv, add C:\opencv\build\x86\vc10\bin (for mswin32) or C:\opencv\build\x86\mingw\bin (for mingw32) to the systems path.
  3. Install ruby-opencv
$ gem install ruby-opencv

Sample code

Load and Display an Image

A sample to load and display an image. An equivalent code of this tutorial.

require 'opencv'
include OpenCV

if ARGV.size == 0
  puts "Usage: ruby #{__FILE__} ImageToLoadAndDisplay"
  exit
end

image = nil
begin
  image = CvMat.load(ARGV[0], CV_LOAD_IMAGE_COLOR) # Read the file.
rescue
  puts 'Could not open or find the image.'
  exit
end

window = GUI::Window.new('Display window') # Create a window for display.
window.show(image) # Show our image inside it.
GUI::wait_key # Wait for a keystroke in the window.

Face Detection

A sample to detect faces from an image.

require 'opencv'
include OpenCV

if ARGV.length < 2
  puts "Usage: ruby #{__FILE__} source dest"
  exit
end

data = './data/haarcascades/haarcascade_frontalface_alt.xml'
detector = CvHaarClassifierCascade::load(data)
image = CvMat.load(ARGV[0])
detector.detect_objects(image).each do |region|
  color = CvColor::Blue
  image.rectangle! region.top_left, region.bottom_right, :color => color
end

image.save_image(ARGV[1])
window = GUI::Window.new('Face detection')
window.show(image)
GUI::wait_key

For more samples, see examples/*.rb

LICENSE:

The BSD Liscense

see LICENSE.txt