Versioned fork of the OpenCV gem for Ruby
Go to file
ser1zw 6efcd5d1ca
Merge pull request #105 from hegoru/patch-1
Fix of DevKit link
2020-07-06 14:16:36 +09:00
examples remove some unsupported codes 2014-01-18 20:40:49 +09:00
ext/opencv replace ALLOCA_N to RB_ALLOC_N (#103) 2020-06-16 07:17:03 +09:00
images add documents of CvHaarClassifierCascade 2012-08-05 01:45:20 +09:00
lib bump up version 2017-03-06 22:39:13 +09:00
test Fix Fixnum's in documentation and in tests 2017-02-10 12:43:54 +01:00
.gitignore Merge branch 'develop' into documentation 2014-01-14 17:45:45 +09:00
.travis.yml Use Travis CI for continuous integration 2017-05-25 09:13:57 -04:00
.yardopts update .yardopts 2014-03-30 17:43:44 +09:00
DEVELOPERS_NOTE.md update document 2013-05-05 03:34:07 +09:00
Gemfile add yard documentation as a rake task 2014-01-18 19:06:04 +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 add .yardopts 2014-01-19 03:03:00 +09:00
README.md Add Travis CI badge 2017-05-25 09:13:58 -04:00
Rakefile fix license name to the license identifier defined at http://spdx.org/licenses/ 2016-07-17 01:33:52 +09:00
config.yml fix config file 2013-05-05 03:34:50 +09:00
install-ruby-opencv-with-rubyinstaller-on-windows.md Update install-ruby-opencv-with-rubyinstaller-on-windows.md 2020-07-02 23:51:58 +03:00
ruby-opencv.gemspec bump up version 2017-03-06 22:39:13 +09:00
yard_extension.rb update for generating documents 2014-01-14 18:15:44 +09:00

README.md

Build Status with Travis CI

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 (RubyInstaller)

See install-ruby-opencv-with-rubyinstaller-on-windows.md.

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