ruby-opencv

0.0.18last stable release 8 years ago
Complexity Score
High
Open Issues
27
Dependent Projects
11
Weekly Downloadsglobal
134

License

  • BSD-3-Clause
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

ruby-opencv

An OpenCV wrapper for Ruby.

  • Web site: https://github.com/ruby-opencv/ruby-opencv
  • Ruby 2.x and OpenCV 2.4.13 are supported.
  • Documentation

Requirement

  • OpenCV http://opencv.org/
    • Download
    • Install guide

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

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
No
Github Stars
813
Dependenciestotal
4
DependenciesOutdated
4
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute ruby-opencv in your own private RubyGems registry

gem install ruby-opencv
Processing...
Done

19 Releases

RubyGems on Cloudsmith

Getting started with RubyGems on Cloudsmith is fast and easy.