From 0e316cdf68534ccf34f1122370296151ce2bc111 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sun, 27 Jan 2013 12:31:21 +0900 Subject: [PATCH] update documents --- DEVELOPERS_NOTE.md | 118 +++++++++++++++++++++++++++++++++++ README.md | 98 +++++++++++++++++++++++++++++ README.rdoc | 149 --------------------------------------------- 3 files changed, 216 insertions(+), 149 deletions(-) create mode 100644 DEVELOPERS_NOTE.md create mode 100644 README.md delete mode 100644 README.rdoc diff --git a/DEVELOPERS_NOTE.md b/DEVELOPERS_NOTE.md new file mode 100644 index 0000000..0403b8b --- /dev/null +++ b/DEVELOPERS_NOTE.md @@ -0,0 +1,118 @@ +# DEVELOPER'S NOTE + +## Requirement for develop ruby-opencv + +* OpenCV +* Git +* Microsoft Visual C++ (for mswin32) + * +* MinGW and MSYS (for mingw32) + * gcc, g++ and MSYS are needed. + * +* Some gems (see Gemfile) + * [bundler](https://github.com/carlhuda/bundler/) + * [hoe](https://github.com/seattlerb/hoe) + * [hoe-gemspec](https://github.com/flavorjones/hoe-gemspec) + * [rake-compiler](https://github.com/luislavena/rake-compiler) + * [gem-compile](https://github.com/frsyuki/gem-compile) + + +## Create ruby-opencv gem +Run the following commands. +When you use mingw32, use **MSYS console**, or when you use mswin32, +use [**Visual Studio Command Prompt**](http://msdn.microsoft.com/en-us/library/ms229859.aspx) +instead of cmd.exe. + +``` +$ git clone git://github.com/ruby-opencv/ruby-opencv.git +$ cd ruby-opencv +$ git checkout master +$ bundle install +$ rake gem +``` +**ruby-opencv-x.y.z.gem** will be created in pkg/ directory. + +To create pre-build binaries, run the following commands in Windows. + +``` +$ cd pkg +$ gem compile ruby-opencv-*.gem +``` + +**ruby-opencv-x.y.z-x86-mingw32.gem** will be created when you use mingw32, or +**ruby-opencv-x.y.z-x86-mswin32.gem** when you use mswin32. + + +## Install Ruby/OpenCV manually +### Linux/Mac + +``` +$ git clone git://github.com/ruby-opencv/ruby-opencv.git +$ cd ruby-opencv +$ git checkout master +$ ruby extconf.rb --with-opencv-dir=/path/to/opencvdir +$ make +$ make install +``` + +Note: **/path/to/opencvdir** is the directory where you installed OpenCV. + + +### Windows (mswin32) + +Run the following commands on [**Visual Studio Command Prompt**](http://msdn.microsoft.com/en-us/library/ms229859.aspx). + +``` +$ git clone git://github.com/ruby-opencv/ruby-opencv.git +$ cd ruby-opencv +$ git checkout master +$ ruby extconf.rb --with-opencv-dir=C:\path\to\opencvdir\install # for your own built OpenCV library +$ nmake +$ nmake 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\vc10\lib +``` + + +### Windows (mingw32) + +Run the following commands on **MSYS console**. + +``` +$ git clone git://github.com/ruby-opencv/ruby-opencv.git +$ cd ruby-opencv +$ git checkout master +$ 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 +``` + + +## Run tests + +To run all tests, run **test/runner.rb** + +``` +$ cd ruby-opencv/test +$ ruby runner.rb +``` + +To run tests of the specified function, run a specific test with --name option. + +The following sample runs tests for CvMat#initialize + +``` +$ cd ruby-opencv/test +$ ruby test_cvmat.rb --name=test_initialize +``` + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f68ad2 --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# ruby-opencv + +An OpenCV wrapper for Ruby. + +* Web site: +* Ruby 1.8.7, 1.9.3 and OpenCV 2.4.3 are supported. + +## 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 +You can use pre-build binary for Windows (mswin32, mingw32). + +1. Install [OpenCV](http://sourceforge.net/projects/opencvlibrary/files/opencv-win/) +2. Set path to OpenCV libraries. When you installed OpenCV to **C:\opencv**, add **C:\opencv\build\x86\vc10\bin (for mswin32)** or **C:\opencv\build\x86\mingw\bin (for mingw32)** to the systems path. +3. Install ruby-opencv + +``` +$ gem install ruby-opencv +``` + +## Sample code +### Load and Display an Image + +A 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 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. + +```ruby +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 + diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index a25b683..0000000 --- a/README.rdoc +++ /dev/null @@ -1,149 +0,0 @@ -= OpenCV - -The initial Open Computer Vision library was originally developed by Intel -Corporation. Recent development has been headed by Willow Garage, Inc. - -* 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 - -== DESCRIPTION: - -OpenCV wrapper for Ruby - -== FEATURES/PROBLEMS: - -* Some OpenCV functions are wrapped. -* Ruby 1.8.7, 1.9.3 and OpenCV 2.4.3 are supported. - -== DEPENDENCIES: - -* OpenCV (required) - * Ruby/OpenCV relies on the OpenCV library http://opencv.willowgarage.com/wiki/InstallGuide - -* Microsoft Visual C++ (for mswin32) - * http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express - -* MinGW and MSYS (for mingw32) - * gcc, g++ and MSYS are needed. - * http://www.mingw.org - - -== INSTALLATION: -=== Install Ruby/OpenCV manually -==== Unix/Linux/Mac - - $ git clone git://github.com/ruby-opencv/ruby-opencv.git - $ cd ruby-opencv - $ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead - $ ruby extconf.rb --with-opencv-dir=/path/to/opencvdir - $ make - $ make install - -==== Windows (mswin32) - -Use *nmake* instead of *make*. - - $ git clone git://github.com/ruby-opencv/ruby-opencv.git - $ cd ruby-opencv - $ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead - $ ruby extconf.rb --with-opencv-dir=C:\path\to\opencvdir\install # for your own built OpenCV library - $ nmake - $ nmake 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\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 - $ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead - $ 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: - -*/path/to/opencvdir* is the path you installs OpenCV library (default: /usr/local). - -For example, if you install OpenCV library to */opt/local/* like: - - $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/local/ ./OpenCV-2.4.2 - $ make - $ make install - -Install Ruby/OpenCV with the following command: - - $ ruby extconf.rb --with-opencv-dir=/opt/local - $ make - $ make install - - -=== Create Ruby/OpenCV Gem -You can also install this library creating a gem like: - - $ git clone git://github.com/ruby-opencv/ruby-opencv.git - $ cd ruby-opencv - $ git checkout master # for OpenCV 2.4 or later. To use OpenCV 2.3, type "git checkout OpenCV_2.3" instead - $ bundle install - $ rake gem - $ gem install pkg/opencv-*.gem -- --with-opencv-dir=/path/to/opencvdir - -To add ruby-opencv in your Gemfile: - - $ echo -e "\n"'gem "opencv", :git => "https://github.com/ruby-opencv/ruby-opencv"' >> Gemfile - $ bundle config build.opencv --with-opencv-dir=/path/to/opencvdir - $ bundle install # or bundle update - -== SYNOPSIS: -=== Show Image using GUI Component - - #!/usr/bin/env ruby - require "opencv" - - image = OpenCV::IplImage.load("sample.jpg") - window = OpenCV::GUI::Window.new("preview") - window.show(image) - OpenCV::GUI::wait_key - -=== Face Detection - -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]) - detector.detect_objects(image).each do |region| - color = OpenCV::CvColor::Blue - image.rectangle! region.top_left, region.bottom_right, :color => color - end - image.save_image(ARGV[1]) - -For more samples, see examples/*.rb - -== LICENSE: - -The BSD Liscense - -see LICENSE.txt -