2011-01-01 07:45:24 -05:00
|
|
|
= OpenCV
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
The initial Open Computer Vision library was originally developed by Intel
|
|
|
|
Corporation. Recent development has been headed by Willow Garage, Inc.
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
* OpenCV project home http://opencv.willowgarage.com/wiki/
|
|
|
|
* Download http://sourceforge.net/projects/opencvlibrary/
|
|
|
|
* Ruby/OpenCV original author's web page http://blueruby.mydns.jp/opencv
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
== DESCRIPTION:
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
OpenCV wrapper for Ruby
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
== FEATURES/PROBLEMS:
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
* Some OpenCV functions are wrapped.
|
2012-07-14 07:22:04 -04:00
|
|
|
* Ruby 1.8.7, 1.9.3 and OpenCV 2.4.2 are supported.
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
== DEPENDENCIES:
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
* OpenCV (required)
|
2012-02-04 06:43:36 -05:00
|
|
|
* Ruby/OpenCV relies on the OpenCV library http://opencv.willowgarage.com/wiki/InstallGuide
|
2011-09-23 04:33:39 -04:00
|
|
|
|
2012-02-04 06:43:36 -05:00
|
|
|
* Microsoft Visual C++ (for mswin32)
|
|
|
|
* http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
|
|
|
|
|
|
|
|
* MinGW and MSYS (for mingw32)
|
|
|
|
* gcc, g++ and MSYS are needed.
|
|
|
|
* http://www.mingw.org
|
2011-09-23 04:33:39 -04:00
|
|
|
|
|
|
|
|
2010-02-27 12:33:53 -05:00
|
|
|
== INSTALLATION:
|
2011-09-23 04:33:39 -04:00
|
|
|
=== Install Ruby/OpenCV manually
|
2011-11-27 18:31:12 -05:00
|
|
|
==== Unix/Linux/Mac
|
2010-02-27 12:33:53 -05:00
|
|
|
|
2012-01-22 00:56:37 -05:00
|
|
|
$ git clone git://github.com/ruby-opencv/ruby-opencv.git
|
2011-09-23 04:33:39 -04:00
|
|
|
$ cd ruby-opencv
|
2012-05-13 10:57:46 -04:00
|
|
|
$ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead
|
2011-09-23 04:33:39 -04:00
|
|
|
$ ruby extconf.rb --with-opencv-dir=/path/to/opencvdir
|
|
|
|
$ make
|
|
|
|
$ make install
|
2010-02-27 12:33:53 -05:00
|
|
|
|
2011-11-27 18:31:12 -05:00
|
|
|
==== Windows (mswin32)
|
|
|
|
|
2012-02-04 06:43:36 -05:00
|
|
|
Use *nmake* instead of *make*.
|
2012-01-12 11:45:31 -05:00
|
|
|
|
2012-01-22 00:56:37 -05:00
|
|
|
$ git clone git://github.com/ruby-opencv/ruby-opencv.git
|
2011-11-27 18:31:12 -05:00
|
|
|
$ cd ruby-opencv
|
2012-05-13 10:57:46 -04:00
|
|
|
$ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead
|
2012-02-04 06:43:36 -05:00
|
|
|
$ ruby extconf.rb --with-opencv-dir=C:\path\to\opencvdir\install # for your own built OpenCV library
|
2011-11-27 18:31:12 -05:00
|
|
|
$ nmake
|
|
|
|
$ nmake install
|
|
|
|
|
2012-02-04 06:43:36 -05:00
|
|
|
To use pre-built OpenCV libraries, set the following option to extconf.rb.
|
|
|
|
|
|
|
|
$ ruby extconf.rb --with-opencv-include=C:\path\to\opencvdir\build\include --with-opencv-lib=C:\path\to\opencvdir\build\x86\vc10\lib
|
|
|
|
|
|
|
|
|
|
|
|
==== Windows (mingw32)
|
|
|
|
|
|
|
|
Type the following commands on the *MSYS* *console*.
|
|
|
|
|
|
|
|
$ git clone git://github.com/ruby-opencv/ruby-opencv.git
|
|
|
|
$ cd ruby-opencv
|
2012-05-13 10:57:46 -04:00
|
|
|
$ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead
|
2012-02-04 06:43:36 -05:00
|
|
|
$ ruby extconf.rb --with-opencv-dir=/C/path/to/opencvdir/install # for your own built OpenCV library
|
|
|
|
$ make
|
|
|
|
$ make install
|
|
|
|
|
|
|
|
To use pre-built OpenCV libraries, set the following option to extconf.rb.
|
|
|
|
|
|
|
|
$ ruby extconf.rb --with-opencv-include=/c/path/to/opencvdir/build/include --with-opencv-lib=/c/path/to/opencvdir/build/x86/mingw/lib
|
|
|
|
|
|
|
|
|
|
|
|
==== NOTE:
|
2011-11-27 18:31:12 -05:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
*/path/to/opencvdir* is the path you installs OpenCV library (default: /usr/local).
|
2010-02-27 12:33:53 -05:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
For example, if you install OpenCV library to */opt/local/* like:
|
2011-04-07 01:25:08 -04:00
|
|
|
|
2012-07-14 07:22:04 -04:00
|
|
|
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/local/ ./OpenCV-2.4.2
|
2011-09-23 04:33:39 -04:00
|
|
|
$ make
|
|
|
|
$ make install
|
2011-05-03 04:24:27 -04:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
Install Ruby/OpenCV with the following command:
|
2011-05-03 04:24:27 -04:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
$ ruby extconf.rb --with-opencv-dir=/opt/local
|
|
|
|
$ make
|
|
|
|
$ make install
|
2011-04-07 01:25:08 -04:00
|
|
|
|
2010-02-27 12:33:53 -05:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
=== Create Ruby/OpenCV Gem
|
|
|
|
You can also install this library creating a gem like:
|
2011-05-31 05:03:31 -04:00
|
|
|
|
2012-01-22 00:56:37 -05:00
|
|
|
$ git clone git://github.com/ruby-opencv/ruby-opencv.git
|
2011-09-23 04:33:39 -04:00
|
|
|
$ cd ruby-opencv
|
2012-05-13 10:57:46 -04:00
|
|
|
$ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead
|
2011-09-23 04:33:39 -04:00
|
|
|
$ bundle install
|
|
|
|
$ rake gem
|
|
|
|
$ gem install pkg/opencv-*.gem -- --with-opencv-dir=/path/to/opencvdir
|
2011-05-31 05:03:31 -04:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
To add ruby-opencv in your Gemfile:
|
2011-05-31 05:03:31 -04:00
|
|
|
|
2012-01-22 00:56:37 -05:00
|
|
|
$ echo -e "\n"'gem "opencv", :git => "https://github.com/ruby-opencv/ruby-opencv"' >> Gemfile
|
2012-01-14 12:28:40 -05:00
|
|
|
$ bundle config build.opencv --with-opencv-dir=/path/to/opencvdir
|
2011-09-23 04:33:39 -04:00
|
|
|
$ bundle install # or bundle update
|
2011-06-02 09:37:14 -04:00
|
|
|
|
2010-02-27 12:33:53 -05:00
|
|
|
== SYNOPSIS:
|
2011-09-23 04:33:39 -04:00
|
|
|
=== Show Image using GUI Component
|
2010-02-27 12:33:53 -05:00
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
#!/usr/bin/env ruby
|
2010-02-27 12:33:53 -05:00
|
|
|
require "opencv"
|
|
|
|
|
|
|
|
image = OpenCV::IplImage.load("sample.jpg")
|
|
|
|
window = OpenCV::GUI::Window.new("preview")
|
|
|
|
window.show(image)
|
|
|
|
OpenCV::GUI::wait_key
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
=== Face Detection
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
Here is a sample face detection program that doesn't rely on the GUI components.
|
|
|
|
In order for this to work you must copy the OpenCV haarcascades data into a
|
|
|
|
subfolder called data.
|
|
|
|
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require "opencv"
|
|
|
|
|
|
|
|
if ARGV.length < 2
|
|
|
|
puts "Usage: your_app_name source dest"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
data = "./data/haarcascades/haarcascade_frontalface_alt.xml"
|
|
|
|
detector = OpenCV::CvHaarClassifierCascade::load(data)
|
|
|
|
image = OpenCV::IplImage.load(ARGV[0])
|
2011-08-11 11:27:20 -04:00
|
|
|
detector.detect_objects(image).each do |region|
|
2010-02-27 12:33:53 -05:00
|
|
|
color = OpenCV::CvColor::Blue
|
|
|
|
image.rectangle! region.top_left, region.bottom_right, :color => color
|
|
|
|
end
|
|
|
|
image.save_image(ARGV[1])
|
|
|
|
|
2011-09-23 04:33:39 -04:00
|
|
|
For more samples, see examples/*.rb
|
2010-02-27 12:33:53 -05:00
|
|
|
|
|
|
|
== LICENSE:
|
|
|
|
|
|
|
|
The BSD Liscense
|
|
|
|
|
|
|
|
see LICENSE.txt
|
2011-09-23 04:33:39 -04:00
|
|
|
|