Giter VIP home page Giter VIP logo

ruby-opencv's Introduction

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

ruby-opencv's People

Contributors

ser1zw avatar thenoseman avatar xli avatar ryanfb avatar abronte avatar banzaiman avatar larskanis avatar nowaterlili avatar martinpilch avatar pcting avatar tenderlove avatar skateman avatar gonzedge avatar hieuk09 avatar jansowinski avatar liamwhite avatar pwim avatar tylerkahn avatar yskz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.