https://github.com/ruby-opencv/ruby-opencv
Versioned fork of the OpenCV gem for Ruby
https://github.com/ruby-opencv/ruby-opencv
Last synced: about 1 month ago
JSON representation
Versioned fork of the OpenCV gem for Ruby
- Host: GitHub
- URL: https://github.com/ruby-opencv/ruby-opencv
- Owner: ruby-opencv
- License: other
- Fork: true (jeffrafter/ruby-opencv)
- Created: 2010-12-29T17:41:43.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T13:49:35.000Z (about 4 years ago)
- Last Synced: 2025-03-07T07:36:29.498Z (about 1 month ago)
- Language: C++
- Homepage: http://rubyforge.org/projects/opencv/
- Size: 51.9 MB
- Stars: 813
- Watchers: 38
- Forks: 128
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Changelog: History.txt
- License: License.txt
Awesome Lists containing this project
- awesome-ruby - ruby-opencv - An OpenCV wrapper for Ruby. (Scientific)
README

# ruby-opencv
An OpenCV wrapper for Ruby.
* Web site:
* Ruby 2.x and OpenCV 2.4.13 are supported.
* [Documentation](http://www.rubydoc.info/gems/ruby-opencv/frames)## Requirement
* OpenCV
* [Download](http://sourceforge.net/projects/opencvlibrary/)
* [Install guide](http://docs.opencv.org/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html#table-of-content-introduction)## Install
### Linux/Mac
1. Install [OpenCV](http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/)
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](install-ruby-opencv-with-rubyinstaller-on-windows.md).
## Sample code
### Load and Display an ImageA sample to load and display an image. An equivalent code of [this tutorial](http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html#display-image).
```ruby
require 'opencv'
include OpenCVif ARGV.size == 0
puts "Usage: ruby #{__FILE__} ImageToLoadAndDisplay"
exit
endimage = nil
begin
image = CvMat.load(ARGV[0], CV_LOAD_IMAGE_COLOR) # Read the file.
rescue
puts 'Could not open or find the image.'
exit
endwindow = 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.
```ruby
require 'opencv'
include OpenCVif ARGV.length < 2
puts "Usage: ruby #{__FILE__} source dest"
exit
enddata = './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
endimage.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