mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
experimental implementation for OpenCV 3
This commit is contained in:
parent
2c6f30ab25
commit
11c4154b7c
264 changed files with 53296 additions and 51592 deletions
|
@ -1,137 +0,0 @@
|
|||
# DEVELOPER'S NOTE
|
||||
|
||||
## Requirement to develop ruby-opencv
|
||||
|
||||
* OpenCV
|
||||
* Git
|
||||
* 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>
|
||||
* 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)
|
||||
|
||||
|
||||
## 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
|
||||
$ git ls-files > Manifest.txt
|
||||
$ rake gem:spec
|
||||
$ rake gem
|
||||
```
|
||||
**ruby-opencv-x.y.z.gem** will be created in **pkg** directory.
|
||||
|
||||
To create pre-build binaries, create a config file firstly:
|
||||
|
||||
```yml
|
||||
# config.yml
|
||||
platform: mingw32
|
||||
rubies:
|
||||
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
|
||||
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
|
||||
extopts:
|
||||
- --with-opencv-include=C:/opencv/build/include
|
||||
- --with-opencv-lib=C:/opencv/build/x86/mingw/lib
|
||||
```
|
||||
|
||||
Entries are below:
|
||||
|
||||
- **platform**: Target platform (e.g. mingw32, mswin32)
|
||||
- **rubies**: Array of target versions of ruby's paths (You can create fat gems if you specify multiple versions of ruby)
|
||||
- **extopts**: Array of options to be passed to **extconf.rb**
|
||||
|
||||
Then, run the following command:
|
||||
|
||||
```
|
||||
$ rake gem:precompile CONFIG=config.yml
|
||||
```
|
||||
|
||||
**ruby-opencv-x.y.z-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 ext/opencv/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 ext/opencv/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 ext/opencv/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 ext/opencv/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 ext/opencv/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
|
||||
```
|
||||
|
10
Gemfile
10
Gemfile
|
@ -1,9 +1,5 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
group :development do
|
||||
gem "hoe"
|
||||
gem "hoe-gemspec"
|
||||
gem "rake-compiler"
|
||||
gem "yard"
|
||||
end
|
||||
|
||||
# Specify your gem's dependencies in ruby-opencv.gemspec
|
||||
gemspec
|
||||
gem 'rake-compiler'
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
=== 0.0.6 / 2008-06-27
|
||||
|
||||
* First gem release.
|
||||
|
||||
* Some OpenCV function wrapped.
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 ser1zw
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
30
License.txt
30
License.txt
|
@ -1,30 +0,0 @@
|
|||
The BSD License
|
||||
|
||||
Copyright (c) 2008, Masakazu Yonekura
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of Masakazu Yonekura. nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of Masakazu Yonekura.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
239
Manifest.txt
239
Manifest.txt
|
@ -1,239 +0,0 @@
|
|||
.gitignore
|
||||
.yardopts
|
||||
DEVELOPERS_NOTE.md
|
||||
Gemfile
|
||||
History.txt
|
||||
License.txt
|
||||
Manifest.txt
|
||||
README.md
|
||||
Rakefile
|
||||
config.yml
|
||||
examples/alpha_blend.rb
|
||||
examples/contours/bitmap-contours-with-labels.png
|
||||
examples/contours/bitmap-contours.png
|
||||
examples/contours/bounding-box-detect-canny.rb
|
||||
examples/contours/contour_retrieval_modes.rb
|
||||
examples/contours/rotated-boxes.jpg
|
||||
examples/convexhull.rb
|
||||
examples/face_detect.rb
|
||||
examples/facerec/create_csv.rb
|
||||
examples/facerec/facerec_eigenfaces.rb
|
||||
examples/facerec/facerec_fisherfaces.rb
|
||||
examples/facerec/facerec_lbph.rb
|
||||
examples/facerec/readme.md
|
||||
examples/find_obj.rb
|
||||
examples/houghcircle.rb
|
||||
examples/images/box.png
|
||||
examples/images/box_in_scene.png
|
||||
examples/images/inpaint.png
|
||||
examples/images/lena-256x256.jpg
|
||||
examples/images/lena-eyes.jpg
|
||||
examples/images/lenna-rotated.jpg
|
||||
examples/images/lenna.jpg
|
||||
examples/images/stuff.jpg
|
||||
examples/images/tiffany.jpg
|
||||
examples/inpaint.rb
|
||||
examples/match_kdtree.rb
|
||||
examples/match_template.rb
|
||||
examples/paint.rb
|
||||
examples/snake.rb
|
||||
ext/opencv/algorithm.cpp
|
||||
ext/opencv/algorithm.h
|
||||
ext/opencv/curve.cpp
|
||||
ext/opencv/curve.h
|
||||
ext/opencv/cvavgcomp.cpp
|
||||
ext/opencv/cvavgcomp.h
|
||||
ext/opencv/cvbox2d.cpp
|
||||
ext/opencv/cvbox2d.h
|
||||
ext/opencv/cvcapture.cpp
|
||||
ext/opencv/cvcapture.h
|
||||
ext/opencv/cvchain.cpp
|
||||
ext/opencv/cvchain.h
|
||||
ext/opencv/cvcircle32f.cpp
|
||||
ext/opencv/cvcircle32f.h
|
||||
ext/opencv/cvconnectedcomp.cpp
|
||||
ext/opencv/cvconnectedcomp.h
|
||||
ext/opencv/cvcontour.cpp
|
||||
ext/opencv/cvcontour.h
|
||||
ext/opencv/cvcontourtree.cpp
|
||||
ext/opencv/cvcontourtree.h
|
||||
ext/opencv/cvconvexitydefect.cpp
|
||||
ext/opencv/cvconvexitydefect.h
|
||||
ext/opencv/cverror.cpp
|
||||
ext/opencv/cverror.h
|
||||
ext/opencv/cvfeaturetree.cpp
|
||||
ext/opencv/cvfeaturetree.h
|
||||
ext/opencv/cvfont.cpp
|
||||
ext/opencv/cvfont.h
|
||||
ext/opencv/cvhaarclassifiercascade.cpp
|
||||
ext/opencv/cvhaarclassifiercascade.h
|
||||
ext/opencv/cvhistogram.cpp
|
||||
ext/opencv/cvhistogram.h
|
||||
ext/opencv/cvhumoments.cpp
|
||||
ext/opencv/cvhumoments.h
|
||||
ext/opencv/cvline.cpp
|
||||
ext/opencv/cvline.h
|
||||
ext/opencv/cvmat.cpp
|
||||
ext/opencv/cvmat.h
|
||||
ext/opencv/cvmemstorage.cpp
|
||||
ext/opencv/cvmemstorage.h
|
||||
ext/opencv/cvmoments.cpp
|
||||
ext/opencv/cvmoments.h
|
||||
ext/opencv/cvpoint.cpp
|
||||
ext/opencv/cvpoint.h
|
||||
ext/opencv/cvpoint2d32f.cpp
|
||||
ext/opencv/cvpoint2d32f.h
|
||||
ext/opencv/cvpoint3d32f.cpp
|
||||
ext/opencv/cvpoint3d32f.h
|
||||
ext/opencv/cvrect.cpp
|
||||
ext/opencv/cvrect.h
|
||||
ext/opencv/cvscalar.cpp
|
||||
ext/opencv/cvscalar.h
|
||||
ext/opencv/cvseq.cpp
|
||||
ext/opencv/cvseq.h
|
||||
ext/opencv/cvsize.cpp
|
||||
ext/opencv/cvsize.h
|
||||
ext/opencv/cvsize2d32f.cpp
|
||||
ext/opencv/cvsize2d32f.h
|
||||
ext/opencv/cvslice.cpp
|
||||
ext/opencv/cvslice.h
|
||||
ext/opencv/cvsurfparams.cpp
|
||||
ext/opencv/cvsurfparams.h
|
||||
ext/opencv/cvsurfpoint.cpp
|
||||
ext/opencv/cvsurfpoint.h
|
||||
ext/opencv/cvtermcriteria.cpp
|
||||
ext/opencv/cvtermcriteria.h
|
||||
ext/opencv/cvtwopoints.cpp
|
||||
ext/opencv/cvtwopoints.h
|
||||
ext/opencv/cvutils.cpp
|
||||
ext/opencv/cvutils.h
|
||||
ext/opencv/cvvideowriter.cpp
|
||||
ext/opencv/cvvideowriter.h
|
||||
ext/opencv/eigenfaces.cpp
|
||||
ext/opencv/eigenfaces.h
|
||||
ext/opencv/extconf.rb
|
||||
ext/opencv/facerecognizer.cpp
|
||||
ext/opencv/facerecognizer.h
|
||||
ext/opencv/fisherfaces.cpp
|
||||
ext/opencv/fisherfaces.h
|
||||
ext/opencv/gui.cpp
|
||||
ext/opencv/gui.h
|
||||
ext/opencv/iplconvkernel.cpp
|
||||
ext/opencv/iplconvkernel.h
|
||||
ext/opencv/iplimage.cpp
|
||||
ext/opencv/iplimage.h
|
||||
ext/opencv/lbph.cpp
|
||||
ext/opencv/lbph.h
|
||||
ext/opencv/mouseevent.cpp
|
||||
ext/opencv/mouseevent.h
|
||||
ext/opencv/opencv.cpp
|
||||
ext/opencv/opencv.h
|
||||
ext/opencv/pointset.cpp
|
||||
ext/opencv/pointset.h
|
||||
ext/opencv/trackbar.cpp
|
||||
ext/opencv/trackbar.h
|
||||
ext/opencv/window.cpp
|
||||
ext/opencv/window.h
|
||||
images/CvMat_sobel.png
|
||||
images/CvMat_sub_rect.png
|
||||
images/CvSeq_relationmap.png
|
||||
lib/opencv.rb
|
||||
lib/opencv/psyched_yaml.rb
|
||||
lib/opencv/version.rb
|
||||
ruby-opencv.gemspec
|
||||
test/eigenfaces_save.xml
|
||||
test/fisherfaces_save.xml
|
||||
test/helper.rb
|
||||
test/lbph_save.xml
|
||||
test/runner.rb
|
||||
test/samples/airplane.jpg
|
||||
test/samples/baboon.jpg
|
||||
test/samples/baboon200.jpg
|
||||
test/samples/baboon200_rotated.jpg
|
||||
test/samples/blank0.jpg
|
||||
test/samples/blank1.jpg
|
||||
test/samples/blank2.jpg
|
||||
test/samples/blank3.jpg
|
||||
test/samples/blank4.jpg
|
||||
test/samples/blank5.jpg
|
||||
test/samples/blank6.jpg
|
||||
test/samples/blank7.jpg
|
||||
test/samples/blank8.jpg
|
||||
test/samples/blank9.jpg
|
||||
test/samples/cat.jpg
|
||||
test/samples/chessboard.jpg
|
||||
test/samples/contours.jpg
|
||||
test/samples/fruits.jpg
|
||||
test/samples/haarcascade_frontalface_alt.xml.gz
|
||||
test/samples/inpaint-mask.bmp
|
||||
test/samples/lena-256x256.jpg
|
||||
test/samples/lena-32x32.jpg
|
||||
test/samples/lena-eyes.jpg
|
||||
test/samples/lena-inpaint.jpg
|
||||
test/samples/lena.jpg
|
||||
test/samples/lines.jpg
|
||||
test/samples/messy0.jpg
|
||||
test/samples/messy1.jpg
|
||||
test/samples/movie_sample.avi
|
||||
test/samples/one_way_train_0000.jpg
|
||||
test/samples/one_way_train_0001.jpg
|
||||
test/samples/partially_blank0.jpg
|
||||
test/samples/partially_blank1.jpg
|
||||
test/samples/smooth0.jpg
|
||||
test/samples/smooth1.jpg
|
||||
test/samples/smooth2.jpg
|
||||
test/samples/smooth3.jpg
|
||||
test/samples/smooth4.jpg
|
||||
test/samples/smooth5.jpg
|
||||
test/samples/smooth6.jpg
|
||||
test/samples/str-cv-rotated.jpg
|
||||
test/samples/str-cv.jpg
|
||||
test/samples/str-ov.jpg
|
||||
test/samples/stuff.jpg
|
||||
test/test_curve.rb
|
||||
test/test_cvavgcomp.rb
|
||||
test/test_cvbox2d.rb
|
||||
test/test_cvcapture.rb
|
||||
test/test_cvchain.rb
|
||||
test/test_cvcircle32f.rb
|
||||
test/test_cvconnectedcomp.rb
|
||||
test/test_cvcontour.rb
|
||||
test/test_cvcontourtree.rb
|
||||
test/test_cverror.rb
|
||||
test/test_cvfeaturetree.rb
|
||||
test/test_cvfont.rb
|
||||
test/test_cvhaarclassifiercascade.rb
|
||||
test/test_cvhistogram.rb
|
||||
test/test_cvhumoments.rb
|
||||
test/test_cvline.rb
|
||||
test/test_cvmat.rb
|
||||
test/test_cvmat_drawing.rb
|
||||
test/test_cvmat_dxt.rb
|
||||
test/test_cvmat_imageprocessing.rb
|
||||
test/test_cvmoments.rb
|
||||
test/test_cvpoint.rb
|
||||
test/test_cvpoint2d32f.rb
|
||||
test/test_cvpoint3d32f.rb
|
||||
test/test_cvrect.rb
|
||||
test/test_cvscalar.rb
|
||||
test/test_cvseq.rb
|
||||
test/test_cvsize.rb
|
||||
test/test_cvsize2d32f.rb
|
||||
test/test_cvslice.rb
|
||||
test/test_cvsurfparams.rb
|
||||
test/test_cvsurfpoint.rb
|
||||
test/test_cvtermcriteria.rb
|
||||
test/test_cvtwopoints.rb
|
||||
test/test_cvvideowriter.rb
|
||||
test/test_eigenfaces.rb
|
||||
test/test_fisherfaces.rb
|
||||
test/test_iplconvkernel.rb
|
||||
test/test_iplimage.rb
|
||||
test/test_lbph.rb
|
||||
test/test_mouseevent.rb
|
||||
test/test_opencv.rb
|
||||
test/test_pointset.rb
|
||||
test/test_preliminary.rb
|
||||
test/test_trackbar.rb
|
||||
test/test_window.rb
|
||||
yard_extension.rb
|
33
README.md
33
README.md
|
@ -3,7 +3,7 @@
|
|||
An OpenCV wrapper for Ruby.
|
||||
|
||||
* Web site: <https://github.com/ruby-opencv/ruby-opencv>
|
||||
* Ruby 1.9.3, 2.x and OpenCV 2.4.10 are supported.
|
||||
* Ruby 2.x and OpenCV 3.1.0 are supported.
|
||||
|
||||
## Requirement
|
||||
|
||||
|
@ -41,7 +41,6 @@ A sample to load and display an image. An equivalent code of [this tutorial](htt
|
|||
|
||||
```ruby
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
if ARGV.size == 0
|
||||
puts "Usage: ruby #{__FILE__} ImageToLoadAndDisplay"
|
||||
|
@ -50,15 +49,15 @@ end
|
|||
|
||||
image = nil
|
||||
begin
|
||||
image = CvMat.load(ARGV[0], CV_LOAD_IMAGE_COLOR) # Read the file.
|
||||
image = Cv::imread(ARGV[0], Cv::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 = Cv::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.
|
||||
Cv::wait_key # Wait for a keystroke in the window.
|
||||
```
|
||||
|
||||
### Face Detection
|
||||
|
@ -67,25 +66,25 @@ A sample to detect faces from an image.
|
|||
|
||||
```ruby
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
if ARGV.length < 2
|
||||
puts "Usage: ruby #{__FILE__} source dest"
|
||||
if ARGV.length < 1
|
||||
puts "Usage: ruby #{__FILE__} image"
|
||||
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
|
||||
classifier = Cv::CascadeClassifier.new('examples/haarcascade_frontalface_alt.xml')
|
||||
image = Cv::imread(ARGV[0], -1)
|
||||
|
||||
color = Cv::Scalar.new(0, 255, 255)
|
||||
classifier.detect_multi_scale(image).each do |r|
|
||||
pt1 = Cv::Point.new(r.x, r.y)
|
||||
pt2 = Cv::Point.new(r.x + r.width, r.y + r.height)
|
||||
image.rectangle!(pt1, pt2, color, thickness: 3, line_type: Cv::CV_AA)
|
||||
end
|
||||
|
||||
image.save_image(ARGV[1])
|
||||
window = GUI::Window.new('Face detection')
|
||||
window = Cv::Window.new('Face detection')
|
||||
window.show(image)
|
||||
GUI::wait_key
|
||||
Cv::wait_key
|
||||
```
|
||||
|
||||
For more samples, see examples/*.rb
|
||||
|
|
96
Rakefile
96
Rakefile
|
@ -1,99 +1,15 @@
|
|||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
require 'rubygems'
|
||||
require "rubygems/ext"
|
||||
require "rubygems/installer"
|
||||
require 'hoe'
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rake/extensiontask'
|
||||
require 'fileutils'
|
||||
require './lib/opencv/psyched_yaml'
|
||||
require 'yard'
|
||||
require 'yard/rake/yardoc_task'
|
||||
require './yard_extension'
|
||||
require_relative 'yard_extension'
|
||||
|
||||
SO_FILE = 'opencv.so'
|
||||
task :default => :spec
|
||||
|
||||
Hoe.plugin :gemspec
|
||||
|
||||
hoespec = Hoe.spec 'ruby-opencv' do |s|
|
||||
s.summary = 'OpenCV wrapper for Ruby'
|
||||
s.description = 'ruby-opencv is a wrapper of OpenCV for Ruby. It helps you to write computer vision programs (e.g. detecting faces from pictures) with Ruby.'
|
||||
s.licenses = ['The BSD License']
|
||||
s.developer('lsxi', 'masakazu.yonekura@gmail.com')
|
||||
s.developer('ser1zw', 'azariahsawtikes@gmail.com')
|
||||
s.developer('pcting', 'pcting@gmail.com')
|
||||
|
||||
s.readme_file = 'README.md'
|
||||
s.history_file = 'History.txt'
|
||||
|
||||
s.spec_extras = { :extensions => ['ext/opencv/extconf.rb'] }
|
||||
|
||||
s.test_globs = ['test/test_*.rb']
|
||||
s.urls = ['https://github.com/ruby-opencv/ruby-opencv/']
|
||||
|
||||
s.extra_dev_deps << ['rake-compiler', '~> 0'] << ['hoe-gemspec', '~> 0']
|
||||
|
||||
Rake::ExtensionTask.new('opencv', spec) do |ext|
|
||||
ext.lib_dir = 'lib'
|
||||
end
|
||||
Rake::ExtensionTask.new('opencv') do |ext|
|
||||
ext.lib_dir = 'lib'
|
||||
end
|
||||
|
||||
hoespec.spec.files.delete('.gemtest')
|
||||
|
||||
Rake::Task[:test].prerequisites << :compile
|
||||
|
||||
desc 'Create a pre-compiled gem'
|
||||
task 'gem:precompile' => ['gem'] do
|
||||
tmp_dir = Dir.mktmpdir('tmp', '.')
|
||||
gemfile = Dir.glob("pkg/*.gem")[0]
|
||||
target_dir = File.join(tmp_dir, File.basename(gemfile, '.gem'))
|
||||
|
||||
installer = Gem::Installer.new(gemfile)
|
||||
installer.unpack(target_dir)
|
||||
|
||||
gemspec = installer.spec
|
||||
extension = gemspec.extensions[0]
|
||||
gemspec.extensions.clear
|
||||
|
||||
config = ENV['CONFIG'] ? YAML.load_file(ENV['CONFIG']) : {}
|
||||
rubies = config['rubies'] || [Gem.ruby]
|
||||
args = config['extopts'] || []
|
||||
gemspec.platform = config['platform'] || Gem::Platform::CURRENT
|
||||
|
||||
multi = rubies.size > 1
|
||||
rubies.each { |ruby|
|
||||
lib_dir = 'lib'
|
||||
if multi
|
||||
major, minor, _ = `#{ruby} -e "print RUBY_VERSION"`.chomp.split('.')
|
||||
lib_dir = File.join(lib_dir, [major, minor].join('.'))
|
||||
end
|
||||
|
||||
make_cmd = (`#{ruby} -e "print RUBY_PLATFORM"` =~ /mswin/) ? 'nmake' : 'make'
|
||||
Dir.chdir(target_dir) {
|
||||
cmd = [ruby, extension, *args].join(' ')
|
||||
results = []
|
||||
Gem::Ext::ExtConfBuilder.run(cmd, results)
|
||||
Gem::Ext::ExtConfBuilder.make('', results)
|
||||
|
||||
FileUtils.mkdir_p lib_dir
|
||||
FileUtils.mv SO_FILE, lib_dir
|
||||
sh "#{make_cmd} clean"
|
||||
}
|
||||
|
||||
gemspec.files << File.join(lib_dir, SO_FILE)
|
||||
}
|
||||
|
||||
Dir.chdir(target_dir) {
|
||||
gemfile = Gem::Package.build(gemspec)
|
||||
FileUtils.mv gemfile, File.dirname(__FILE__)
|
||||
}
|
||||
|
||||
FileUtils.rm_rf tmp_dir
|
||||
end
|
||||
|
||||
# yard
|
||||
YARD::Rake::YardocTask.new do |t|
|
||||
t.files = ['lib/**/*.rb', 'ext/**/*.cpp']
|
||||
t.files = ['lib/**/*.rb', 'ext/opencv/*.cpp']
|
||||
end
|
||||
|
||||
# vim: syntax=ruby
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
platform: mingw32
|
||||
rubies:
|
||||
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
|
||||
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
|
||||
extopts:
|
||||
- --with-opencv-include=C:/opencv/build/include
|
||||
- --with-opencv-lib=C:/opencv/build/x86/mingw/lib
|
18
examples/alpha_blend.rb
Executable file → Normal file
18
examples/alpha_blend.rb
Executable file → Normal file
|
@ -1,21 +1,15 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# Alpha blending sample with GUI
|
||||
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
img1 = IplImage.load('images/lenna.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
img2 = IplImage.load('images/tiffany.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
img1 = Cv::imread('images/lenna.jpg', -1)
|
||||
img2 = Cv::imread('images/tiffany.jpg', -1)
|
||||
|
||||
window = GUI::Window.new('Alpha blend')
|
||||
window = Cv::Window.new('Alpha blend')
|
||||
max = 100.0
|
||||
val = max / 2.0
|
||||
window.set_trackbar("Alpha", max, val) { |v|
|
||||
a = v.to_f / max
|
||||
window.show CvMat.add_weighted(img1, a, img2, 1.0 - a, 0)
|
||||
window.show(Cv::add_weighted(img1, a, img2, 1.0 - a, 0))
|
||||
}
|
||||
window.show CvMat.add_weighted(img1, val / max, img2, 1.0 - val / max, 0)
|
||||
GUI::wait_key
|
||||
|
||||
window.show(Cv::add_weighted(img1, val / max, img2, 1.0 - val / max, 0))
|
||||
Cv.wait_key
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
|
@ -1,62 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# Detects contours in an image and
|
||||
# their boundingboxes
|
||||
#
|
||||
require "opencv"
|
||||
|
||||
# Load image
|
||||
cvmat = OpenCV::CvMat.load("rotated-boxes.jpg")
|
||||
|
||||
# The "canny" edge-detector does only work with grayscale images
|
||||
# so to be sure, convert the image
|
||||
# otherwise you will get an OpenCV::CvStsAssert exception.
|
||||
cvmat = cvmat.BGR2GRAY
|
||||
|
||||
# Use the "canny" edge detection algorithm (http://en.wikipedia.org/wiki/Canny_edge_detector)
|
||||
# Parameters are two colors that are then used to determine possible corners
|
||||
canny = cvmat.canny(50, 150)
|
||||
|
||||
# Look for contours
|
||||
# We want them to be returned as a flat list (CV_RETR_LIST) and simplified (CV_CHAIN_APPROX_SIMPLE)
|
||||
# Both are the defaults but included here for clarity
|
||||
contour = canny.find_contours(:mode => OpenCV::CV_RETR_LIST, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
||||
|
||||
# The Canny Algorithm returns two matches for every contour (see O'Reilly: Learning OpenCV Page 235)
|
||||
# We need only the external edges so we ignore holes.
|
||||
# When there are no more contours, contours.h_next will return nil
|
||||
while contour
|
||||
# No "holes" please (aka. internal contours)
|
||||
unless contour.hole?
|
||||
|
||||
puts '-' * 80
|
||||
puts "BOUNDING RECT FOUND"
|
||||
puts '-' * 80
|
||||
|
||||
# You can detect the "bounding rectangle" which is always oriented horizontally and vertically
|
||||
box = contour.bounding_rect
|
||||
puts "found external contour with bounding rectangle from #{box.top_left.x},#{box.top_left.y} to #{box.bottom_right.x},#{box.bottom_right.y}"
|
||||
|
||||
# The contour area can be computed:
|
||||
puts "that contour encloses an area of #{contour.contour_area} square pixels"
|
||||
|
||||
# .. as can be the length of the contour
|
||||
puts "that contour is #{contour.arc_length} pixels long "
|
||||
|
||||
# Draw that bounding rectangle
|
||||
cvmat.rectangle! box.top_left, box.bottom_right, :color => OpenCV::CvColor::Black
|
||||
|
||||
# You can also detect the "minimal rectangle" which has an angle, width, height and center coordinates
|
||||
# and is not neccessarily horizonally or vertically aligned.
|
||||
# The corner of the rectangle with the lowest y and x position is the anchor (see image here: http://bit.ly/lT1XvB)
|
||||
# The zero angle position is always straight up.
|
||||
# Positive angle values are clockwise and negative values counter clockwise (so -60 means 60 degree counter clockwise)
|
||||
box = contour.min_area_rect2
|
||||
puts "found minimal rectangle with its center at (#{box.center.x.round},#{box.center.y.round}), width of #{box.size.width.round}px, height of #{box.size.height.round} and an angle of #{box.angle.round} degree"
|
||||
end
|
||||
contour = contour.h_next
|
||||
end
|
||||
|
||||
# And save the image
|
||||
puts "\nSaving image with bounding rectangles"
|
||||
cvmat.save_image("rotated-boxes-with-detected-bounding-rectangles.jpg")
|
|
@ -1,139 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# This file shows the different retrieval modes for contour detection
|
||||
#
|
||||
require "opencv"
|
||||
|
||||
# Load image
|
||||
# The structure of the image is "explained" in bitmap-contours-with-labels.png
|
||||
cvmat = OpenCV::CvMat.load("bitmap-contours.png")
|
||||
|
||||
# "find_contours" does only operate on bitmap images (black/white)
|
||||
mat = OpenCV::CvMat.new(cvmat.rows, cvmat.cols, :cv8u, 1)
|
||||
(cvmat.rows * cvmat.cols).times do |i|
|
||||
mat[i] = (cvmat[i][0] <= 128) ? OpenCV::CvScalar.new(0) : OpenCV::CvScalar.new(255)
|
||||
end
|
||||
|
||||
# find_contours takes two parameters:
|
||||
# 1. Retrieval mode (:mode, defines the structure of the contour sequence returned)
|
||||
# - CV_RETR_LIST (default)
|
||||
# - CV_RETR_EXTERNAL
|
||||
# - CV_RETR_CCOMP
|
||||
# - CV_RETR_TREE
|
||||
# 2. Retrieval Method (:method, how the contours are approximated)
|
||||
# - CV_CHAIN_CODE
|
||||
# - CV_CHAIN_APPROX_NONE
|
||||
# - CV_CHAIN_APPROX_SIMPLE (default)
|
||||
# - CV_CHAIN_APPROX_TC89_L1
|
||||
# - CV_CHAIN_APPROX_T89_KCOS
|
||||
# - CV_LINK_RUNS
|
||||
|
||||
#
|
||||
# The default: CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE
|
||||
# This produces a flat list of contours that can be traversed with .h_next and .h_prev
|
||||
#
|
||||
puts "Detecting using CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE"
|
||||
contour = mat.find_contours(:mode => OpenCV::CV_RETR_LIST, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
||||
cindex=1
|
||||
|
||||
while contour
|
||||
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.h_next
|
||||
cindex+=1
|
||||
end
|
||||
|
||||
#
|
||||
# CV_RETR_EXTERNAL retrieves only the outer most non "hole" contour
|
||||
#
|
||||
puts '-'*80
|
||||
puts "Detecting using CV_RETR_EXTERNAL and CV_CHAIN_APPROX_SIMPLE"
|
||||
contour = mat.find_contours(:mode => OpenCV::CV_RETR_EXTERNAL, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
||||
cindex=1
|
||||
|
||||
while contour
|
||||
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.h_next
|
||||
cindex+=1
|
||||
end
|
||||
|
||||
#
|
||||
# CV_RETR_CCOMP organizes the contours in a two level deep stack
|
||||
# The first level holds the contours
|
||||
# The second level contains the holes of the contours in level 1
|
||||
#
|
||||
# C00001 <-> C00000 <-> C000 <-> C0
|
||||
# | |
|
||||
# V V
|
||||
# H0000 H00
|
||||
#
|
||||
puts '-'*80
|
||||
puts "Detecting using CV_RETR_CCOMP and CV_CHAIN_APPROX_SIMPLE"
|
||||
contour = mat.find_contours(:mode => OpenCV::CV_RETR_CCOMP, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
||||
|
||||
# C00001
|
||||
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.h_next
|
||||
|
||||
# C00000
|
||||
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.h_next
|
||||
|
||||
# C000
|
||||
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour_down = contour.v_next
|
||||
|
||||
# H0000
|
||||
puts "Contour #4 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
||||
contour = contour.h_next
|
||||
|
||||
# C0
|
||||
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour_down = contour.v_next
|
||||
|
||||
# H00
|
||||
puts "Contour #6 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
||||
|
||||
#
|
||||
# CV_RETR_TREE manages the contours in a tree structure
|
||||
# This reconstructs the complete hierarchy of contours and holes that the image displayed
|
||||
#
|
||||
# C0
|
||||
# |
|
||||
# V
|
||||
# H00
|
||||
# |
|
||||
# V
|
||||
# C000
|
||||
# |
|
||||
# V
|
||||
# H0000-------+
|
||||
# | |
|
||||
# V V
|
||||
# C00000 C00001
|
||||
#
|
||||
puts '-'*80
|
||||
puts "Detecting using CV_RETR_TREE and CV_CHAIN_APPROX_SIMPLE"
|
||||
contour = mat.find_contours(:mode => OpenCV::CV_RETR_TREE, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
||||
|
||||
# C0
|
||||
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.v_next
|
||||
|
||||
# H00
|
||||
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.v_next
|
||||
|
||||
# C000
|
||||
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.v_next
|
||||
|
||||
# H0000
|
||||
puts "Contour #4 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour = contour.v_next
|
||||
|
||||
# C00000
|
||||
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
||||
contour_right = contour.h_next
|
||||
|
||||
# C00001
|
||||
puts "Contour #6 is #{contour_right.contour_area} px^2 (width: #{contour_right.bounding_rect.width}, height: #{contour_right.bounding_rect.height}, type: #{(contour_right.hole?)?"hole":"contour"})"
|
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB |
|
@ -1,47 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# convexhull.rb
|
||||
# Draw contours and convexity defect points to captured image
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
include OpenCV
|
||||
|
||||
window = GUI::Window.new("convexhull")
|
||||
capture = CvCapture::open
|
||||
|
||||
accuracy = 1
|
||||
t = window.set_trackbar("accuracy", 10, 1) { |v|
|
||||
accuracy = v
|
||||
}
|
||||
|
||||
circle_options = { :color => CvColor::Blue, :line_type => :aa, :thickness => -1 }
|
||||
|
||||
loop do
|
||||
image = capture.query
|
||||
|
||||
# Calculate contours from a binary image
|
||||
gray = image.BGR2GRAY
|
||||
bin = gray.threshold(0x44, 0xFF, :binary)
|
||||
contours = bin.find_contours
|
||||
|
||||
while contours
|
||||
# Draw contours
|
||||
poly = contours.approx(:accuracy => accuracy)
|
||||
begin
|
||||
image.draw_contours!(poly, CvColor::Red, CvColor::Black, 2,
|
||||
:thickness => 2, :line_type => :aa)
|
||||
end while (poly = poly.h_next)
|
||||
|
||||
# Draw convexity defects
|
||||
hull = contours.convex_hull2(true, false)
|
||||
contours.convexity_defects(hull).each { |cd|
|
||||
image.circle!(cd.start, 3, circle_options)
|
||||
image.circle!(cd.depth_point, 3, circle_options)
|
||||
image.circle!(cd.end, 3, circle_options)
|
||||
}
|
||||
contours = contours.h_next
|
||||
end
|
||||
|
||||
window.show image
|
||||
exit if GUI::wait_key(1)
|
||||
end
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# face_detect.rb
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
|
||||
include OpenCV
|
||||
|
||||
window = GUI::Window.new("face detect")
|
||||
capture = CvCapture.open
|
||||
detector = CvHaarClassifierCascade::load("./data/haarcascades/haarcascade_frontalface_alt.xml")
|
||||
|
||||
loop {
|
||||
image = capture.query
|
||||
detector.detect_objects(image).each { |rect|
|
||||
image.rectangle! rect.top_left, rect.bottom_right, :color => CvColor::Red
|
||||
}
|
||||
window.show image
|
||||
break if GUI::wait_key(100)
|
||||
}
|
||||
|
15
examples/facedetect.rb
Normal file
15
examples/facedetect.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'opencv'
|
||||
|
||||
m = Cv::imread('images/lenna.jpg', -1)
|
||||
classifier = Cv::CascadeClassifier.new('haarcascade_frontalface_alt.xml')
|
||||
rects = classifier.detect_multi_scale(m)
|
||||
color = Cv::Scalar.new(0, 255, 255)
|
||||
rects.each do |r|
|
||||
pt1 = Cv::Point.new(r.x, r.y)
|
||||
pt2 = Cv::Point.new(r.x + r.width, r.y + r.height)
|
||||
m.rectangle!(pt1, pt2, color, thickness: 3, line_type: Cv::CV_AA)
|
||||
end
|
||||
|
||||
w = Cv::Window.new('Face detect')
|
||||
w.show(m)
|
||||
Cv::wait_key
|
|
@ -1,43 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# This is a tiny script to help you creating a CSV file from a face
|
||||
# database with a similar hierarchie:
|
||||
#
|
||||
# philipp@mango:~/facerec/data/at$ tree
|
||||
# .
|
||||
# |-- README
|
||||
# |-- s1
|
||||
# | |-- 1.pgm
|
||||
# | |-- ...
|
||||
# | |-- 10.pgm
|
||||
# |-- s2
|
||||
# | |-- 1.pgm
|
||||
# | |-- ...
|
||||
# | |-- 10.pgm
|
||||
# ...
|
||||
# |-- s40
|
||||
# | |-- 1.pgm
|
||||
# | |-- ...
|
||||
# | |-- 10.pgm
|
||||
#
|
||||
# See http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html
|
||||
#
|
||||
if ARGV.size != 1
|
||||
puts "usage: ruby #{__FILE__} <base_path>"
|
||||
exit
|
||||
end
|
||||
|
||||
BASE_PATH = ARGV[0]
|
||||
SEPARATOR = ';'
|
||||
|
||||
label = 0
|
||||
Dir.glob("#{BASE_PATH}/*").each { |dir|
|
||||
if FileTest::directory? dir
|
||||
Dir.glob("#{dir}/*") { |filename|
|
||||
puts "#{filename}#{SEPARATOR}#{label}"
|
||||
}
|
||||
label += 1
|
||||
end
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# Eigenfaces sample in ruby-opencv, equivalent to http://docs.opencv.org/trunk/_downloads/facerec_eigenfaces.cpp
|
||||
# See http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
def norm_0_255(src)
|
||||
dst = nil
|
||||
case src.channel
|
||||
when 1
|
||||
dst = src.normalize(0, 255, CV_NORM_MINMAX, CV_8UC1)
|
||||
when 2
|
||||
dst = src.normalize(0, 255, CV_NORM_MINMAX, CV_8UC3)
|
||||
else
|
||||
dst = src.copy
|
||||
end
|
||||
|
||||
dst
|
||||
end
|
||||
|
||||
def read_csv(filename, sepalator = ';')
|
||||
images = []
|
||||
labels = []
|
||||
open(filename, 'r') { |f|
|
||||
f.each { |line|
|
||||
path, label = line.chomp.split(sepalator)
|
||||
images << CvMat.load(path, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
labels << label.to_i
|
||||
}
|
||||
}
|
||||
|
||||
[images, labels]
|
||||
end
|
||||
|
||||
if ARGV.size < 1
|
||||
puts "usage: ruby #{__FILE__} <csv.ext> <output_folder>"
|
||||
exit 1
|
||||
end
|
||||
fn_csv = ARGV.shift
|
||||
output_folder = ARGV.shift
|
||||
|
||||
images, labels = read_csv(fn_csv);
|
||||
|
||||
height = images[0].rows;
|
||||
|
||||
# The following lines simply get the last images from your dataset and remove it
|
||||
# from the vector. This is done, so that the training data (which we learn the
|
||||
# cv::FaceRecognizer on) and the test data we test the model with, do not overlap.
|
||||
test_sample = images.pop
|
||||
test_label = labels.pop
|
||||
|
||||
# The following lines create an Eigenfaces model for
|
||||
# face recognition and train it with the images and
|
||||
# labels read from the given CSV file.
|
||||
# This here is a full PCA, if you just want to keep
|
||||
# 10 principal components (read Eigenfaces), then call
|
||||
# the factory method like this:
|
||||
#
|
||||
# EigenFaces.new(10)
|
||||
#
|
||||
# If you want to create a FaceRecognizer with a
|
||||
# confidence threshold (e.g. 123.0), call it with:
|
||||
#
|
||||
# EigenFaces.new(10, 123.0)
|
||||
#
|
||||
# If you want to use _all_ Eigenfaces and have a threshold,
|
||||
# then call the method like this:
|
||||
#
|
||||
# EigenFaces.new(0, 123.0)
|
||||
#
|
||||
model = EigenFaces.new
|
||||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
puts "Predicted class: #{predicted_label} / Actual class: #{test_label}"
|
||||
|
||||
eigenvalues = model.get_mat('eigenvalues')
|
||||
w = model.get_mat('eigenvectors');
|
||||
mean = model.get_mat('mean')
|
||||
|
||||
if output_folder
|
||||
norm_0_255(mean.reshape(1, images[0].rows)).save("#{output_folder}/mean.png")
|
||||
else
|
||||
w1 = GUI::Window.new('Predicted')
|
||||
w2 = GUI::Window.new('Actual')
|
||||
w3 = GUI::Window.new('mean')
|
||||
|
||||
w1.show images[predicted_label]
|
||||
w2.show images[test_label]
|
||||
w3.show norm_0_255(mean.reshape(1, images[0].rows))
|
||||
end
|
||||
|
||||
# Display or save the Eigenfaces:
|
||||
[w.cols, 10].min.times { |i|
|
||||
puts "Eigenvalue ##{i} = #{eigenvalues[i][0]}"
|
||||
ev = w.get_cols(i).clone()
|
||||
grayscale = norm_0_255(ev.reshape(1, height))
|
||||
|
||||
# Show the image & apply a Jet colormap for better sensing.
|
||||
cgrayscale = grayscale.apply_color_map(COLORMAP_JET)
|
||||
if output_folder
|
||||
norm_0_255(cgrayscale).save("#{output_folder}/eigenface_#{i}.png")
|
||||
else
|
||||
w4 = GUI::Window.new("eigenface_#{i}")
|
||||
w4.show norm_0_255(cgrayscale)
|
||||
end
|
||||
}
|
||||
|
||||
[w.cols, 10].min.step([w.cols, 300].min, 15) { |num_components|
|
||||
# slice the eigenvectors from the model
|
||||
evs = w.get_cols(0..num_components)
|
||||
projection = images[0].reshape(1, 1).subspace_project(evs, mean)
|
||||
reconstruction = projection.subspace_reconstruct(evs, mean)
|
||||
|
||||
# Normalize the result:
|
||||
reconstruction = norm_0_255(reconstruction.reshape(1, images[0].rows))
|
||||
|
||||
# Display or save:
|
||||
if output_folder
|
||||
norm_0_255(reconstruction).save("#{output_folder}/eigenface_reconstruction_#{num_components}.png")
|
||||
else
|
||||
w5 = GUI::Window.new("eigenface_reconstruction_#{num_components}")
|
||||
w5.show norm_0_255(reconstruction)
|
||||
end
|
||||
}
|
||||
|
||||
GUI::wait_key unless output_folder
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# Fisherfaces sample in ruby-opencv, equivalent to http://docs.opencv.org/trunk/_downloads/facerec_fisherfaces.cpp
|
||||
# See http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
def norm_0_255(src)
|
||||
dst = nil
|
||||
case src.channel
|
||||
when 1
|
||||
dst = src.normalize(0, 255, CV_NORM_MINMAX, CV_8UC1)
|
||||
when 2
|
||||
dst = src.normalize(0, 255, CV_NORM_MINMAX, CV_8UC3)
|
||||
else
|
||||
dst = src.copy
|
||||
end
|
||||
|
||||
dst
|
||||
end
|
||||
|
||||
def read_csv(filename, sepalator = ';')
|
||||
images = []
|
||||
labels = []
|
||||
open(filename, 'r') { |f|
|
||||
f.each { |line|
|
||||
path, label = line.chomp.split(sepalator)
|
||||
images << CvMat.load(path, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
labels << label.to_i
|
||||
}
|
||||
}
|
||||
|
||||
[images, labels]
|
||||
end
|
||||
|
||||
if ARGV.size < 1
|
||||
puts "usage: ruby #{__FILE__} <csv.ext> <output_folder>"
|
||||
exit 1
|
||||
end
|
||||
fn_csv = ARGV.shift
|
||||
output_folder = ARGV.shift
|
||||
|
||||
images, labels = read_csv(fn_csv);
|
||||
|
||||
height = images[0].rows;
|
||||
|
||||
# The following lines simply get the last images from your dataset and remove it
|
||||
# from the vector. This is done, so that the training data (which we learn the
|
||||
# cv::FaceRecognizer on) and the test data we test the model with, do not overlap.
|
||||
test_sample = images.pop
|
||||
test_label = labels.pop
|
||||
|
||||
# The following lines create an Fisherfaces model for
|
||||
# face recognition and train it with the images and
|
||||
# labels read from the given CSV file.
|
||||
# If you just want to keep 10 Fisherfaces, then call
|
||||
# the factory method like this:
|
||||
#
|
||||
# FisherFaces.new(10)
|
||||
#
|
||||
# However it is not useful to discard Fisherfaces! Please
|
||||
# always try to use _all_ available Fisherfaces for
|
||||
# classification.
|
||||
#
|
||||
# If you want to create a FaceRecognizer with a
|
||||
# confidence threshold (e.g. 123.0) and use _all_
|
||||
# Fisherfaces, then call it with:
|
||||
#
|
||||
# FisherFaces.new(0, 123.0);
|
||||
#
|
||||
model = FisherFaces.new
|
||||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
puts "Predicted class: #{predicted_label} / Actual class: #{test_label}"
|
||||
|
||||
eigenvalues = model.get_mat('eigenvalues')
|
||||
w = model.get_mat('eigenvectors');
|
||||
mean = model.get_mat('mean')
|
||||
|
||||
if output_folder
|
||||
norm_0_255(mean.reshape(1, images[0].rows)).save("#{output_folder}/mean.png")
|
||||
else
|
||||
w1 = GUI::Window.new('Predicted')
|
||||
w2 = GUI::Window.new('Actual')
|
||||
w3 = GUI::Window.new('mean')
|
||||
|
||||
w1.show images[predicted_label]
|
||||
w2.show images[test_label]
|
||||
w3.show norm_0_255(mean.reshape(1, images[0].rows))
|
||||
end
|
||||
|
||||
# Display or save the first, at most 16 Fisherfaces
|
||||
[w.cols, 16].min.times { |i|
|
||||
puts "Eigenvalue ##{i} = #{eigenvalues[i][0]}"
|
||||
ev = w.get_cols(i).clone()
|
||||
grayscale = norm_0_255(ev.reshape(1, height))
|
||||
|
||||
# Show the image & apply a Bone colormap for better sensing.
|
||||
cgrayscale = grayscale.apply_color_map(COLORMAP_BONE)
|
||||
if output_folder
|
||||
norm_0_255(cgrayscale).save("#{output_folder}/fisherface_#{i}.png")
|
||||
else
|
||||
w4 = GUI::Window.new("fisherface_#{i}")
|
||||
w4.show norm_0_255(cgrayscale)
|
||||
end
|
||||
}
|
||||
|
||||
[w.cols, 16].min.times { |num_component|
|
||||
# Slice the Fisherface from the model
|
||||
ev = w.get_cols(num_component)
|
||||
projection = images[0].reshape(1, 1).subspace_project(ev, mean)
|
||||
reconstruction = projection.subspace_reconstruct(ev, mean)
|
||||
|
||||
# Normalize the result:
|
||||
reconstruction = norm_0_255(reconstruction.reshape(1, images[0].rows))
|
||||
|
||||
# Display or save:
|
||||
if output_folder
|
||||
norm_0_255(reconstruction).save("#{output_folder}/fisherface_reconstruction_#{num_component}.png")
|
||||
else
|
||||
w5 = GUI::Window.new("fisherface_reconstruction_#{num_component}")
|
||||
w5.show norm_0_255(reconstruction)
|
||||
end
|
||||
}
|
||||
|
||||
GUI::wait_key unless output_folder
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# LBPH sample in ruby-opencv, equivalent to http://docs.opencv.org/trunk/_downloads/facerec_lbph.cpp
|
||||
# See http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
def read_csv(filename, sepalator = ';')
|
||||
images = []
|
||||
labels = []
|
||||
open(filename, 'r') { |f|
|
||||
f.each { |line|
|
||||
path, label = line.chomp.split(sepalator)
|
||||
images << CvMat.load(path, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
labels << label.to_i
|
||||
}
|
||||
}
|
||||
|
||||
[images, labels]
|
||||
end
|
||||
|
||||
# Check for valid command line arguments, print usage
|
||||
# if no arguments were given.
|
||||
if ARGV.size < 1
|
||||
puts "usage: ruby #{__FILE__} <csv.ext>"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# Get the path to your CSV.
|
||||
fn_csv = ARGV.shift
|
||||
|
||||
# Read in the data. This can fail if no valid
|
||||
# input filename is given.
|
||||
images, labels = read_csv(fn_csv);
|
||||
|
||||
# Quit if there are not enough images for this demo.
|
||||
raise 'This demo needs at least 2 images to work. Please add more images to your data set!' if images.size <= 1
|
||||
|
||||
# Get the height from the first image. We'll need this
|
||||
# later in code to reshape the images to their original size:
|
||||
height = images[0].rows;
|
||||
|
||||
# The following lines simply get the last images from
|
||||
# your dataset and remove it from the vector. This is
|
||||
# done, so that the training data (which we learn the
|
||||
# cv::FaceRecognizer on) and the test data we test
|
||||
# the model with, do not overlap.
|
||||
test_sample = images.pop
|
||||
test_label = labels.pop
|
||||
|
||||
# The following lines create an LBPH model for
|
||||
# face recognition and train it with the images and
|
||||
# labels read from the given CSV file.
|
||||
#
|
||||
# The LBPHFaceRecognizer uses Extended Local Binary Patterns
|
||||
# (it's probably configurable with other operators at a later
|
||||
# point), and has the following default values
|
||||
#
|
||||
# radius = 1
|
||||
# neighbors = 8
|
||||
# grid_x = 8
|
||||
# grid_y = 8
|
||||
#
|
||||
# So if you want a LBPH FaceRecognizer using a radius of
|
||||
# 2 and 16 neighbors, call the factory method with:
|
||||
#
|
||||
# LBPH.new(2, 16);
|
||||
#
|
||||
# And if you want a threshold (e.g. 123.0) call it with its default values:
|
||||
#
|
||||
# LBPH.new(1,8,8,8,123.0)
|
||||
#
|
||||
model = LBPH.new
|
||||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
# To get the confidence of a prediction call the model with:
|
||||
#
|
||||
# predicted_label = -1;
|
||||
# confidence = 0.0;
|
||||
# model.predict(test_sample, predicted_label, confidence)
|
||||
#
|
||||
puts "Predicted class: #{predicted_label} / Actual class: #{test_label}"
|
||||
|
||||
# Sometimes you'll need to get/set internal model data,
|
||||
# which isn't exposed by the public FaceRecognizer.
|
||||
# Since each FaceRecognizer is derived from a Algorithm,
|
||||
# you can query the data.
|
||||
#
|
||||
# First we'll use it to set the threshold of the FaceRecognizer
|
||||
# to 0.0 without retraining the model. This can be useful if
|
||||
# you are evaluating the model:
|
||||
model.set_double('threshold', 0.0);
|
||||
|
||||
# Now the threshold of this model is set to 0.0. A prediction
|
||||
# now returns -1, as it's impossible to have a distance below it
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
puts "Predicted class = #{predicted_label}"
|
||||
|
||||
# Show some informations about the model, as there's no cool
|
||||
# Model data to display as in Eigenfaces/Fisherfaces.
|
||||
# Due to efficiency reasons the LBP images are not stored
|
||||
# within the model:
|
||||
puts 'Model Information:'
|
||||
model_info = "\tLBPH(radius=#{model.get_int('radius')}, neighbors=#{model.get_int('neighbors')}, grid_x=#{model.get_int('grid_x')}, grid_y=#{model.get_int('grid_y')}, threshold=#{model.get_double('threshold')})"
|
||||
puts model_info
|
||||
|
||||
# We could get the histograms for example:
|
||||
histgrams = model.get_matvector('histograms');
|
||||
|
||||
# But should I really visualize it? Probably the length is interesting:
|
||||
puts "Size of the histograms: #{histgrams[0].dims.reduce(&:*)}"
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
# Face recognition with ruby-opencv
|
||||
|
||||
This is a face recognition sample with ruby-opencv, which equivalent to the following OpenCV's tutorial.
|
||||
|
||||
[Face Recognition with OpenCV](http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html)
|
||||
|
||||
|
||||
## Running samples
|
||||
|
||||
### 1. Get AT&T Facedatabase
|
||||
|
||||
Get AT&T Facedatabase from http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html and unzip it.
|
||||
|
||||
```sh
|
||||
$ wget http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip
|
||||
$ unzip att_faces.zip
|
||||
```
|
||||
|
||||
### 2. Prepare the data
|
||||
|
||||
Create a CSV file to run samples.
|
||||
|
||||
```sh
|
||||
$ ruby create_csv.rb att_faces > at.txt
|
||||
```
|
||||
|
||||
You will get a CSV file which contains lines composed of a filename followed by a ; followed by the label (as integer number).
|
||||
|
||||
```sh
|
||||
$ cat at.txt
|
||||
att_faces/s34/2.pgm;0
|
||||
att_faces/s34/3.pgm;0
|
||||
att_faces/s34/8.pgm;0
|
||||
att_faces/s34/4.pgm;0
|
||||
att_faces/s34/5.pgm;0
|
||||
att_faces/s34/10.pgm;0
|
||||
att_faces/s34/9.pgm;0
|
||||
att_faces/s34/7.pgm;0
|
||||
att_faces/s34/6.pgm;0
|
||||
att_faces/s34/1.pgm;0
|
||||
...
|
||||
```
|
||||
|
||||
### 3. Run sample codes
|
||||
|
||||
#### Eigenfaces
|
||||
|
||||
```sh
|
||||
$ mkdir output-eigenfaces
|
||||
$ ruby facerec_eigenfaces.rb at.txt output-eigenfaces
|
||||
```
|
||||
|
||||
You will get the predicted class, actual class and eignvalues shown in console.
|
||||
|
||||
```sh
|
||||
Predicted class: 39 / Actual class: 39
|
||||
Eigenvalue #0 = 2823424.500638128
|
||||
Eigenvalue #1 = 2062015.3818895558
|
||||
Eigenvalue #2 = 1090171.0771557507
|
||||
Eigenvalue #3 = 892019.3644237233
|
||||
Eigenvalue #4 = 818537.7917991373
|
||||
Eigenvalue #5 = 539058.2364753223
|
||||
Eigenvalue #6 = 390359.3231975121
|
||||
Eigenvalue #7 = 373809.5486713626
|
||||
Eigenvalue #8 = 314658.94374918053
|
||||
Eigenvalue #9 = 288764.63018440653
|
||||
```
|
||||
|
||||
The result images will be stored in **output-eigenfaces** .
|
||||
|
||||
|
||||
#### Fisherfaces
|
||||
|
||||
```sh
|
||||
$ mkdir output-fisherfaces
|
||||
$ ruby facerec_fisherfaces.rb at.txt output-fisherfaces
|
||||
```
|
||||
|
||||
You will get the predicted class, actual class and eignvalues like Eigenfaces sample.
|
||||
|
||||
The result images will be stored in **output-fisherfaces** .
|
||||
|
||||
|
||||
#### Local Binary Patterns Histograms
|
||||
|
||||
```sh
|
||||
$ ruby facerec_lbph.rb at.txt
|
||||
```
|
||||
|
||||
You will get the predicted class, actual class, model information and size of the histgrams.
|
||||
|
||||
```
|
||||
Predicted class: 39 / Actual class: 39
|
||||
Predicted class = -1
|
||||
Model Information:
|
||||
LBPH(radius=1, neighbors=8, grid_x=8, grid_y=8, threshold=0.0)
|
||||
Size of the histograms: 16384
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
### The Database of Faces
|
||||
|
||||
The Database of Faces, formerly The ORL Database of Faces, contains a set of face images taken between April 1992 and April 1994. The database was used in the context of a face recognition project carried out in collaboration with the Speech, Vision and Robotics Group of the Cambridge University Engineering Department.
|
||||
|
||||
There are ten different images of each of 40 distinct subjects. For some subjects, the images were taken at different times, varying the lighting, facial expressions (open / closed eyes, smiling / not smiling) and facial details (glasses / no glasses). All the images were taken against a dark homogeneous background with the subjects in an upright, frontal position (with tolerance for some side movement).
|
||||
|
||||
The files are in PGM format. The size of each image is 92x112 pixels, with 256 grey levels per pixel. The images are organised in 40 directories (one for each subject), which have names of the form sX, where X indicates the subject number (between 1 and 40). In each of these directories, there are ten different images of that subject, which have names of the form Y.pgm, where Y is the image number for that subject (between 1 and 10).
|
||||
|
||||
A copy of the database can be retrieved from: http://www.cl.cam.ac.uk/research/dtg/attarchive/pub/data/att_faces.zip.
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# A Demo Ruby/OpenCV Implementation of SURF
|
||||
# See https://code.ros.org/trac/opencv/browser/tags/2.3.1/opencv/samples/c/find_obj.cpp
|
||||
require 'opencv'
|
||||
require 'benchmark'
|
||||
include OpenCV
|
||||
|
||||
def compare_surf_descriptors(d1, d2, best, length)
|
||||
raise ArgumentError unless (length % 4) == 0
|
||||
total_cost = 0
|
||||
0.step(length - 1, 4) { |i|
|
||||
t0 = d1[i] - d2[i]
|
||||
t1 = d1[i + 1] - d2[i + 1]
|
||||
t2 = d1[i + 2] - d2[i + 2]
|
||||
t3 = d1[i + 3] - d2[i + 3]
|
||||
total_cost += t0 * t0 + t1 * t1 + t2 * t2 + t3 * t3
|
||||
break if total_cost > best
|
||||
}
|
||||
total_cost
|
||||
end
|
||||
|
||||
def naive_nearest_neighbor(vec, laplacian, model_keypoints, model_descriptors)
|
||||
length = model_descriptors[0].size
|
||||
neighbor = nil
|
||||
dist1 = 1e6
|
||||
dist2 = 1e6
|
||||
|
||||
model_descriptors.size.times { |i|
|
||||
kp = model_keypoints[i]
|
||||
mvec = model_descriptors[i]
|
||||
next if laplacian != kp.laplacian
|
||||
|
||||
d = compare_surf_descriptors(vec, mvec, dist2, length)
|
||||
if d < dist1
|
||||
dist2 = dist1
|
||||
dist1 = d
|
||||
neighbor = i
|
||||
elsif d < dist2
|
||||
dist2 = d
|
||||
end
|
||||
}
|
||||
|
||||
return (dist1 < 0.6 * dist2) ? neighbor : nil
|
||||
end
|
||||
|
||||
def find_pairs(object_keypoints, object_descriptors,
|
||||
image_keypoints, image_descriptors)
|
||||
ptpairs = []
|
||||
object_descriptors.size.times { |i|
|
||||
kp = object_keypoints[i]
|
||||
descriptor = object_descriptors[i]
|
||||
nearest_neighbor = naive_nearest_neighbor(descriptor, kp.laplacian, image_keypoints, image_descriptors)
|
||||
unless nearest_neighbor.nil?
|
||||
ptpairs << i
|
||||
ptpairs << nearest_neighbor
|
||||
end
|
||||
}
|
||||
ptpairs
|
||||
end
|
||||
|
||||
def locate_planar_object(object_keypoints, object_descriptors,
|
||||
image_keypoints, image_descriptors, src_corners)
|
||||
ptpairs = find_pairs(object_keypoints, object_descriptors, image_keypoints, image_descriptors)
|
||||
n = ptpairs.size / 2
|
||||
return nil if n < 4
|
||||
|
||||
pt1 = []
|
||||
pt2 = []
|
||||
n.times { |i|
|
||||
pt1 << object_keypoints[ptpairs[i * 2]].pt
|
||||
pt2 << image_keypoints[ptpairs[i * 2 + 1]].pt
|
||||
}
|
||||
|
||||
_pt1 = CvMat.new(1, n, CV_32F, 2)
|
||||
_pt2 = CvMat.new(1, n, CV_32F, 2)
|
||||
_pt1.set_data(pt1)
|
||||
_pt2.set_data(pt2)
|
||||
h = CvMat.find_homography(_pt1, _pt2, :ransac, 5)
|
||||
|
||||
dst_corners = []
|
||||
4.times { |i|
|
||||
x = src_corners[i].x
|
||||
y = src_corners[i].y
|
||||
z = 1.0 / (h[6][0] * x + h[7][0] * y + h[8][0])
|
||||
x = (h[0][0] * x + h[1][0] * y + h[2][0]) * z
|
||||
y = (h[3][0] * x + h[4][0] * y + h[5][0]) * z
|
||||
dst_corners << CvPoint.new(x.to_i, y.to_i)
|
||||
}
|
||||
|
||||
dst_corners
|
||||
end
|
||||
|
||||
|
||||
##### Main #####
|
||||
puts 'This program demonstrated the use of the SURF Detector and Descriptor using'
|
||||
puts 'brute force matching on planar objects.'
|
||||
puts 'Usage:'
|
||||
puts "ruby #{__FILE__} <object_filename> <scene_filename>, default is box.png and box_in_scene.png"
|
||||
puts
|
||||
|
||||
object_filename = (ARGV.size == 2) ? ARGV[0] : 'images/box.png'
|
||||
scene_filename = (ARGV.size == 2) ? ARGV[1] : 'images/box_in_scene.png'
|
||||
|
||||
object, image = nil, nil
|
||||
begin
|
||||
object = IplImage.load(object_filename, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
image = IplImage.load(scene_filename, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
rescue
|
||||
puts "Can not load #{object_filename} and/or #{scene_filename}"
|
||||
puts "Usage: ruby #{__FILE__} [<object_filename> <scene_filename>]"
|
||||
exit
|
||||
end
|
||||
object_color = object.GRAY2BGR
|
||||
|
||||
param = CvSURFParams.new(1500)
|
||||
|
||||
object_keypoints, object_descriptors = nil, nil
|
||||
image_keypoints, image_descriptors = nil, nil
|
||||
tms = Benchmark.measure {
|
||||
object_keypoints, object_descriptors = object.extract_surf(param)
|
||||
puts "Object Descriptors: #{object_descriptors.size}"
|
||||
|
||||
image_keypoints, image_descriptors = image.extract_surf(param)
|
||||
puts "Image Descriptors: #{image_descriptors.size}"
|
||||
}
|
||||
puts "Extraction time = #{tms.real * 1000} ms"
|
||||
|
||||
correspond = IplImage.new(image.width, object.height + image.height, CV_8U, 1);
|
||||
correspond.set_roi(CvRect.new(0, 0, object.width, object.height))
|
||||
object.copy(correspond)
|
||||
correspond.set_roi(CvRect.new(0, object.height, image.width, image.height))
|
||||
image.copy(correspond)
|
||||
correspond.reset_roi
|
||||
|
||||
src_corners = [CvPoint.new(0, 0), CvPoint.new(object.width, 0),
|
||||
CvPoint.new(object.width, object.height), CvPoint.new(0, object.height)]
|
||||
dst_corners = locate_planar_object(object_keypoints, object_descriptors,
|
||||
image_keypoints, image_descriptors, src_corners)
|
||||
|
||||
correspond = correspond.GRAY2BGR
|
||||
if dst_corners
|
||||
4.times { |i|
|
||||
r1 = dst_corners[i % 4]
|
||||
r2 = dst_corners[(i + 1) % 4]
|
||||
correspond.line!(CvPoint.new(r1.x, r1.y + object.height), CvPoint.new(r2.x, r2.y + object.height),
|
||||
:color => CvColor::Red, :thickness => 2, :line_type => :aa)
|
||||
}
|
||||
end
|
||||
|
||||
ptpairs = find_pairs(object_keypoints, object_descriptors, image_keypoints, image_descriptors)
|
||||
|
||||
0.step(ptpairs.size - 1, 2) { |i|
|
||||
r1 = object_keypoints[ptpairs[i]]
|
||||
r2 = image_keypoints[ptpairs[i + 1]]
|
||||
correspond.line!(r1.pt, CvPoint.new(r2.pt.x, r2.pt.y + object.height),
|
||||
:color => CvColor::Red, :line_type => :aa)
|
||||
}
|
||||
|
||||
object_keypoints.each { |r|
|
||||
radius = (r.size * 1.2 / 9.0 * 2).to_i
|
||||
object_color.circle!(r.pt, radius, :color => CvColor::Red, :line_type => :aa)
|
||||
}
|
||||
|
||||
GUI::Window.new('Object Correspond').show correspond
|
||||
GUI::Window.new('Object').show object_color
|
||||
GUI::wait_key
|
||||
|
24350
examples/haarcascade_frontalface_alt.xml
Normal file
24350
examples/haarcascade_frontalface_alt.xml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# houghcircle.rb
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
include OpenCV
|
||||
|
||||
original_window = GUI::Window.new "original"
|
||||
hough_window = GUI::Window.new "hough circles"
|
||||
|
||||
image = IplImage::load "images/stuff.jpg"
|
||||
gray = image.BGR2GRAY
|
||||
|
||||
result = image.clone
|
||||
original_window.show image
|
||||
detect = gray.hough_circles(CV_HOUGH_GRADIENT, 2.0, 10, 200, 50)
|
||||
puts detect.size
|
||||
detect.each{|circle|
|
||||
puts "#{circle.center.x},#{circle.center.y} - #{circle.radius}"
|
||||
result.circle! circle.center, circle.radius, :color => CvColor::Red, :thickness => 3
|
||||
}
|
||||
hough_window.show result
|
||||
GUI::wait_key
|
|
@ -1,57 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# inpaint.rb
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
include OpenCV
|
||||
|
||||
puts <<EOS
|
||||
Inpainting sample
|
||||
|
||||
Usage:
|
||||
'dilate' bar - Adjust mask to inpaint (Non-black areas indicate the area that needs to be inpainted).
|
||||
'radius' bar - Adjust radius of a circular neighborhood of each point inpainted.
|
||||
'n' key - Inpaint using Navier-Stokes based method
|
||||
't' key - Inpaint using Alexandru Telea's method
|
||||
'c' key - Clear the inpaint window
|
||||
'ESC' key - exit"
|
||||
EOS
|
||||
|
||||
owindow = GUI::Window.new('original')
|
||||
mwindow = GUI::Window.new('mask')
|
||||
iwindow = GUI::Window.new('inpaint')
|
||||
|
||||
image = IplImage::load('images/inpaint.png')
|
||||
noimage = image.zero
|
||||
b, g, r = image.split
|
||||
original_mask = r.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV) & b.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV)
|
||||
mask = original_mask.copy
|
||||
|
||||
num_dilate = 3
|
||||
mwindow.set_trackbar("dilate", 10, num_dilate) { |v|
|
||||
num_dilate = v
|
||||
mask = original_mask.dilate(nil, num_dilate)
|
||||
mwindow.show mask
|
||||
}
|
||||
|
||||
radius = 5
|
||||
mwindow.set_trackbar("radius", 10, radius) { |v|
|
||||
radius = v
|
||||
}
|
||||
|
||||
owindow.show image
|
||||
mwindow.show mask
|
||||
iwindow.show noimage
|
||||
|
||||
while key = GUI::wait_key
|
||||
case key.chr
|
||||
when "\e" # esc
|
||||
exit
|
||||
when "n"
|
||||
iwindow.show image.inpaint(:ns, mask, radius)
|
||||
when "t"
|
||||
iwindow.show image.inpaint(:telea, mask, radius)
|
||||
when "c"
|
||||
iwindow.show noimage
|
||||
end
|
||||
end
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
|
||||
# A sample of matching SURF feature points using kd-tree
|
||||
# See http://tech.groups.yahoo.com/group/OpenCV/message/62318
|
||||
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
USE_EXTENDED_DESCRIPTOR = true
|
||||
THRESHOLD = 1500
|
||||
DESCRIPTOR_SIZE = USE_EXTENDED_DESCRIPTOR ? 128 : 64
|
||||
|
||||
img1 = CvMat.load('images/lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
img2 = CvMat.load('images/lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
|
||||
puts 'Extracting features from img1 using SURF...'
|
||||
param = CvSURFParams.new(THRESHOLD, USE_EXTENDED_DESCRIPTOR)
|
||||
kp1, desc1 = img1.extract_surf(param)
|
||||
puts "found #{kp1.size} keypoints from img1"
|
||||
|
||||
puts 'Extracting features from img2 using SURF...'
|
||||
kp2, desc2 = img2.extract_surf(param)
|
||||
puts "found #{kp2.size} keypoints from img2"
|
||||
|
||||
puts 'Matching keypoints...'
|
||||
desc1mat = CvMat.new(kp1.size, DESCRIPTOR_SIZE, :cv32f, 1)
|
||||
desc2mat = CvMat.new(kp2.size, DESCRIPTOR_SIZE, :cv32f, 1)
|
||||
desc1.each_with_index { |desc, i|
|
||||
desc.each_with_index { |d, j|
|
||||
desc1mat[i, j] = CvScalar.new(d)
|
||||
}
|
||||
}
|
||||
desc2.each_with_index { |desc, i|
|
||||
desc.each_with_index { |d, j|
|
||||
desc2mat[i, j] = CvScalar.new(d)
|
||||
}
|
||||
}
|
||||
|
||||
feature_tree = CvFeatureTree.new(desc1mat)
|
||||
results, distances = feature_tree.find_features(desc2mat, 1, 250)
|
||||
|
||||
reverse_lookup = []
|
||||
reverse_lookup_dist = []
|
||||
kp1.size.times { |i|
|
||||
reverse_lookup << -1
|
||||
reverse_lookup_dist << Float::MAX
|
||||
}
|
||||
|
||||
match_count = 0
|
||||
kp2.size.times { |j|
|
||||
i = results[j][0].to_i
|
||||
d = distances[j][0]
|
||||
if (d < reverse_lookup_dist[i])
|
||||
match_count += 1 if reverse_lookup_dist[i] == Float::MAX
|
||||
reverse_lookup[i] = j
|
||||
reverse_lookup_dist[i] = d
|
||||
end
|
||||
}
|
||||
puts "found #{match_count} putative correspondences"
|
||||
|
||||
points1 = []
|
||||
points2 = []
|
||||
kp2.size.times { |j|
|
||||
i = results[j][0].to_i
|
||||
if (j == reverse_lookup[i])
|
||||
points1 << kp1[i].pt
|
||||
points2 << kp2[j].pt
|
||||
end
|
||||
}
|
||||
|
||||
width = img1.cols + img2.cols
|
||||
height = (img1.rows > img2.rows) ? img1.rows : img2.rows
|
||||
correspond = IplImage.new(width, height, :cv8u, 1);
|
||||
correspond.set_roi(CvRect.new(0, 0, img1.cols, img1.rows))
|
||||
img1.copy(correspond)
|
||||
correspond.set_roi(CvRect.new(img1.cols, 0, img1.cols + img2.cols, img2.rows))
|
||||
img2.copy(correspond)
|
||||
correspond.reset_roi
|
||||
|
||||
points1.zip(points2) { |pt1, pt2|
|
||||
pt2.x += img1.cols
|
||||
correspond.line!(pt1, pt2, :color => CvColor::White)
|
||||
}
|
||||
|
||||
GUI::Window.new('Object Correspond').show correspond
|
||||
GUI::wait_key
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# A demo of Ruby/OpenCV's match_template function
|
||||
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
puts 'This program demonstrates the match_template function'
|
||||
puts 'Usage:'
|
||||
puts "ruby #{__FILE__} <template_filename> <match_filename>"
|
||||
puts
|
||||
|
||||
template_filename = (ARGV.size == 2) ? ARGV[0] : File.expand_path(File.dirname(__FILE__) + '/images/lena-eyes.jpg')
|
||||
match_image_filename = (ARGV.size == 2) ? ARGV[1] : File.expand_path(File.dirname(__FILE__) + '/images/lena-256x256.jpg')
|
||||
|
||||
template = CvMat.load(template_filename)
|
||||
match_image = CvMat.load(match_image_filename)
|
||||
result = match_image.match_template(template, :sqdiff_normed)
|
||||
|
||||
pt1 = result.min_max_loc[2] # minimum location
|
||||
pt2 = CvPoint.new(pt1.x + template.width, pt1.y + template.height)
|
||||
match_image.rectangle!(pt1, pt2, :color => CvColor::Black, :thickness => 3)
|
||||
|
||||
window = GUI::Window.new('Display window') # Create a window for display.
|
||||
window.show(match_image) # Show our image inside it.
|
||||
GUI::wait_key # Wait for a keystroke in the window.
|
80
examples/paint.rb
Executable file → Normal file
80
examples/paint.rb
Executable file → Normal file
|
@ -1,70 +1,30 @@
|
|||
#!/usr/bin/env ruby
|
||||
# paint.rb
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
require 'opencv'
|
||||
|
||||
include OpenCV
|
||||
w = Cv::Window.new('Paint')
|
||||
canvas = Cv::Mat.new(500, 500, Cv::CV_8UC3).set_to(Cv::Scalar.new(255, 255, 255))
|
||||
w.show(canvas)
|
||||
|
||||
window = GUI::Window.new("free canvas")
|
||||
canvas = CvMat.new(500, 500, CV_8U, 3).fill!(CvColor::White) # create white canvas
|
||||
window.show canvas
|
||||
|
||||
colors = CvColor::constants.collect{ |i| i.to_s }
|
||||
|
||||
usage =<<USAGE
|
||||
[mouse]
|
||||
drag - draw
|
||||
right button - fill by color
|
||||
[keyborad]
|
||||
1 to 9 - change thickness of line
|
||||
type color name - change color
|
||||
esc - exit
|
||||
USAGE
|
||||
puts usage
|
||||
|
||||
# drawing option
|
||||
# Drawing option
|
||||
opt = {
|
||||
:color => CvColor::Black,
|
||||
:tickness => 1
|
||||
color: Cv::Scalar.new(0),
|
||||
tickness: 1,
|
||||
line_type: Cv::CV_AA
|
||||
}
|
||||
|
||||
point = nil
|
||||
window.on_mouse{ |m|
|
||||
case m.event
|
||||
when :move
|
||||
if m.left_button?
|
||||
canvas.line!(point, m, opt) if point
|
||||
point = m
|
||||
w.set_mouse_callback { |event, x, y, flags|
|
||||
case event
|
||||
when Cv::EVENT_MOUSEMOVE
|
||||
if flags & Cv::EVENT_FLAG_LBUTTON > 0
|
||||
p2 = Cv::Point.new(x, y)
|
||||
canvas.line!(point, p2, opt[:color], opt) if point
|
||||
point = p2
|
||||
end
|
||||
when :left_button_down
|
||||
canvas.line!(m, m, opt)
|
||||
point = m
|
||||
when :left_button_up
|
||||
point = nil
|
||||
when :right_button_down
|
||||
mask = canvas.flood_fill!(m, opt[:color])
|
||||
when Cv::EVENT_LBUTTONDOWN
|
||||
point = Cv::Point.new(x, y)
|
||||
canvas.line!(point, point, opt[:color], opt)
|
||||
end
|
||||
window.show canvas
|
||||
w.show(canvas)
|
||||
}
|
||||
|
||||
color_name = ''
|
||||
while key = GUI.wait_key
|
||||
next if key < 0 or key > 255
|
||||
case key.chr
|
||||
when "\e" # [esc] - exit
|
||||
exit
|
||||
when '1'..'9'
|
||||
puts "change thickness to #{key.chr.to_i}."
|
||||
opt[:thickness] = key.chr.to_i
|
||||
when /[A-Za-z]/
|
||||
color_name << key.chr
|
||||
choice = colors.find_all{ |i| i =~ /\A#{color_name}/i }
|
||||
if choice.size == 1
|
||||
color,= choice
|
||||
puts "change color to #{color}."
|
||||
opt[:color] = CvColor::const_get(color)
|
||||
end
|
||||
color_name = '' if choice.size < 2
|
||||
end
|
||||
end
|
||||
|
||||
Cv::wait_key
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# snake.rb
|
||||
require "rubygems"
|
||||
require "opencv"
|
||||
include OpenCV
|
||||
|
||||
puts <<USAGE
|
||||
usage:
|
||||
left-click: set a point
|
||||
right-click: do snake
|
||||
USAGE
|
||||
|
||||
window = GUI::Window.new "snake demo"
|
||||
image = CvMat.new(256, 256, :cv8u, 1).clear!
|
||||
image.circle!(CvPoint.new(128,128), 40, :color => CvColor::White, :thickness => -1)
|
||||
display = image.GRAY2BGR
|
||||
|
||||
window.show display
|
||||
|
||||
points = []
|
||||
|
||||
window.on_mouse{|mouse|
|
||||
case mouse.event
|
||||
when :left_button_down
|
||||
display.circle!(mouse, 1, :color => CvColor::Red, :thickness => 2)
|
||||
puts "set point (#{mouse.x},#{mouse.y})"
|
||||
points << CvPoint.new(mouse.x, mouse.y)
|
||||
window.show display
|
||||
when :right_button_down
|
||||
if points.length < 3
|
||||
puts "please set more point!"
|
||||
next
|
||||
end
|
||||
snake_points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
|
||||
display = image.GRAY2BGR
|
||||
display.poly_line!([snake_points], :color => CvColor::Red, :is_closed => true, :thickness => 2)
|
||||
window.show display
|
||||
points.clear
|
||||
end
|
||||
}
|
||||
|
||||
GUI::wait_key
|
||||
|
22
examples/video.rb
Normal file
22
examples/video.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'opencv'
|
||||
|
||||
capture = Cv::VideoCapture.new
|
||||
w = Cv::Window.new('video')
|
||||
|
||||
classifier = Cv::CascadeClassifier.new
|
||||
classifier.load('haarcascade_frontalface_alt.xml')
|
||||
color = Cv::Scalar.new(0, 255, 255)
|
||||
|
||||
loop do
|
||||
m = capture.read
|
||||
rects = classifier.detect_multi_scale(m)
|
||||
rects.each do |r|
|
||||
pt1 = Cv::Point.new(r.x, r.y)
|
||||
pt2 = Cv::Point.new(r.x + r.width, r.y + r.height)
|
||||
m.rectangle!(pt1, pt2, color, thickness: 3, line_type: Cv::CV_AA)
|
||||
end
|
||||
|
||||
w.show(m)
|
||||
break if Cv::wait_key(10) > 0
|
||||
end
|
||||
|
|
@ -1,291 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
algorithm.cpp -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2013 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#include <stdio.h>
|
||||
#include "algorithm.h"
|
||||
/*
|
||||
* Document-class: OpenCV::Algorithm
|
||||
*
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_ALGORITHM
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_int(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
try {
|
||||
ALGORITHM(self)->setInt(StringValueCStr(parameter), NUM2INT(value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_double(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
try {
|
||||
ALGORITHM(self)->setDouble(StringValueCStr(parameter), NUM2DBL(value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_bool(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
try {
|
||||
bool val = TRUE_OR_FALSE(value) ? true : false;
|
||||
ALGORITHM(self)->setBool(StringValueCStr(parameter), val);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_string(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
Check_Type(value, T_STRING);
|
||||
try {
|
||||
ALGORITHM(self)->setString(StringValueCStr(parameter), StringValueCStr(value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_mat(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
try {
|
||||
CvMat* val = CVMAT_WITH_CHECK(value);
|
||||
cv::Mat mat(val);
|
||||
ALGORITHM(self)->setMat(StringValueCStr(parameter), mat);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_matvector(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
Check_Type(value, T_ARRAY);
|
||||
try {
|
||||
long len = RARRAY_LEN(value);
|
||||
VALUE* value_ptr = RARRAY_PTR(value);
|
||||
std::vector<cv::Mat> mat_vector;
|
||||
for (int i = 0; i < len; i++) {
|
||||
CvMat* val = CVMAT_WITH_CHECK(value_ptr[i]);
|
||||
cv::Mat mat(val);
|
||||
mat_vector.push_back(mat);
|
||||
}
|
||||
ALGORITHM(self)->setMatVector(StringValueCStr(parameter), mat_vector);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_algorithm(VALUE self, VALUE parameter, VALUE value)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
try {
|
||||
ALGORITHM(self)->setAlgorithm(StringValueCStr(parameter), ALGORITHM(value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
||||
VALUE
|
||||
rb_get_int(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
int value = 0;
|
||||
try {
|
||||
value = ALGORITHM(self)->getInt(StringValueCStr(parameter));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return INT2NUM(value);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_double(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
double value = 0.0;
|
||||
try {
|
||||
value = ALGORITHM(self)->getDouble(StringValueCStr(parameter));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return DBL2NUM(value);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_bool(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
bool value = false;
|
||||
try {
|
||||
value = ALGORITHM(self)->getBool(StringValueCStr(parameter));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return value ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_string(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
std::string value = "";
|
||||
try {
|
||||
value = ALGORITHM(self)->getString(StringValueCStr(parameter));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return rb_str_new_cstr(value.c_str());
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_mat(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
VALUE mat = Qnil;
|
||||
try {
|
||||
cv::Mat value = ALGORITHM(self)->getMat(StringValueCStr(parameter));
|
||||
cv::Size size = value.size();
|
||||
mat = cCvMat::new_object(size.height, size.width, value.type());
|
||||
cv::Mat dst(CVMAT(mat));
|
||||
value.copyTo(dst);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_matvector(VALUE self, VALUE parameter)
|
||||
{
|
||||
Check_Type(parameter, T_STRING);
|
||||
VALUE array = Qnil;
|
||||
try {
|
||||
std::vector<cv::Mat> value = ALGORITHM(self)->getMatVector(StringValueCStr(parameter));
|
||||
int len = value.size();
|
||||
array = rb_ary_new2(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
cv::Mat m = value[i];
|
||||
cv::Size size = m.size();
|
||||
VALUE mat = cCvMat::new_object(size.height, size.width, m.type());
|
||||
cv::Mat dst(CVMAT(mat));
|
||||
m.copyTo(dst);
|
||||
rb_ary_store(array, i, mat);
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_name(VALUE self)
|
||||
{
|
||||
VALUE name = Qnil;
|
||||
try {
|
||||
name = rb_str_new_cstr(ALGORITHM(self)->name().c_str());
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "Algorithm", rb_cObject);
|
||||
rb_define_method(rb_klass, "set_int", RUBY_METHOD_FUNC(rb_set_int), 2);
|
||||
rb_define_method(rb_klass, "set_double", RUBY_METHOD_FUNC(rb_set_double), 2);
|
||||
rb_define_method(rb_klass, "set_bool", RUBY_METHOD_FUNC(rb_set_bool), 2);
|
||||
rb_define_method(rb_klass, "set_string", RUBY_METHOD_FUNC(rb_set_string), 2);
|
||||
rb_define_method(rb_klass, "set_mat", RUBY_METHOD_FUNC(rb_set_mat), 2);
|
||||
rb_define_method(rb_klass, "set_matvector", RUBY_METHOD_FUNC(rb_set_matvector), 2);
|
||||
rb_define_method(rb_klass, "set_algorithm", RUBY_METHOD_FUNC(rb_set_algorithm), 2);
|
||||
|
||||
rb_define_method(rb_klass, "get_int", RUBY_METHOD_FUNC(rb_get_int), 1);
|
||||
rb_define_method(rb_klass, "get_double", RUBY_METHOD_FUNC(rb_get_double), 1);
|
||||
rb_define_method(rb_klass, "get_bool", RUBY_METHOD_FUNC(rb_get_bool), 1);
|
||||
rb_define_method(rb_klass, "get_string", RUBY_METHOD_FUNC(rb_get_string), 1);
|
||||
rb_define_method(rb_klass, "get_mat", RUBY_METHOD_FUNC(rb_get_mat), 1);
|
||||
rb_define_method(rb_klass, "get_matvector", RUBY_METHOD_FUNC(rb_get_matvector), 1);
|
||||
|
||||
rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_ALGORITM
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
algorithm.h
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2013 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_ALGORITHM_H
|
||||
#define RUBY_OPENCV_ALGORITHM_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_ALGORITHM namespace cAlgorithm {
|
||||
#define __NAMESPACE_END_ALGORITM }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_ALGORITHM
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
__NAMESPACE_END_ALGORITM
|
||||
|
||||
inline cv::Algorithm*
|
||||
ALGORITHM(VALUE object)
|
||||
{
|
||||
cv::Algorithm *ptr;
|
||||
Data_Get_Struct(object, cv::Algorithm, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_ALGORITHM_H
|
||||
|
138
ext/opencv/cascadeclassifier.cpp
Normal file
138
ext/opencv/cascadeclassifier.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
#include "opencv.hpp"
|
||||
#include "mat.hpp"
|
||||
#include "size.hpp"
|
||||
#include "rect.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
/*
|
||||
* Document-class: OpenCV::CascadeClassifier
|
||||
*/
|
||||
namespace rubyopencv {
|
||||
namespace CascadeClassifier {
|
||||
void free_cascadeclassifier(void* ptr);
|
||||
size_t memsize_cascadeclassifier(const void* ptr);
|
||||
|
||||
VALUE rb_klass = Qnil;
|
||||
rb_data_type_t opencv_cascadeclassifier_type = {
|
||||
"CascadeClassifier",
|
||||
{ 0, free_cascadeclassifier, memsize_cascadeclassifier, 0 },
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
void free_cascadeclassifier(void* ptr) {
|
||||
delete (cv::CascadeClassifier*)ptr;
|
||||
}
|
||||
|
||||
size_t memsize_cascadeclassifier(const void* ptr) {
|
||||
return sizeof(cv::CascadeClassifier);
|
||||
}
|
||||
|
||||
cv::CascadeClassifier* obj2cascadeclassifier(VALUE obj) {
|
||||
cv::CascadeClassifier* ptr = NULL;
|
||||
TypedData_Get_Struct(obj, cv::CascadeClassifier, &opencv_cascadeclassifier_type, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
VALUE rb_allocate(VALUE klass) {
|
||||
cv::CascadeClassifier* ptr = new cv::CascadeClassifier();
|
||||
return TypedData_Wrap_Struct(klass, &opencv_cascadeclassifier_type, ptr);
|
||||
}
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self) {
|
||||
VALUE filename;
|
||||
rb_scan_args(argc, argv, "01", &filename);
|
||||
|
||||
cv::CascadeClassifier* selfptr = obj2cascadeclassifier(self);
|
||||
if (!NIL_P(filename)) {
|
||||
selfptr->load(StringValueCStr(filename));
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
VALUE rb_load(VALUE self, VALUE filename) {
|
||||
cv::CascadeClassifier* selfptr = obj2cascadeclassifier(self);
|
||||
bool ret = selfptr->load(StringValueCStr(filename));
|
||||
|
||||
return ret ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
|
||||
*
|
||||
* @overload detect_multi_scale(image, options = nil)
|
||||
* @param image [Mat] Matrix of the type CV_8U containing an image where objects are detected.
|
||||
* @param options [Hash] Options
|
||||
* @option options [Number] :scale_factor
|
||||
* Parameter specifying how much the image size is reduced at each image scale.
|
||||
* @option options [Integer] :min_neighbors
|
||||
* Parameter specifying how many neighbors each candidate rectangle should have to retain it.
|
||||
* @option options [Size] :min_size
|
||||
* Minimum possible object size. Objects smaller than that are ignored.
|
||||
* @option options [Size] :max_size
|
||||
* Maximum possible object size. Objects larger than that are ignored.
|
||||
* @return [Array<Rect>] Detected objects as a list of rectangles.
|
||||
* @opencv_func cv::CascadeClassifier::detectMultiScale
|
||||
*/
|
||||
VALUE rb_detect_multi_scale(int argc, VALUE *argv, VALUE self) {
|
||||
VALUE image, options;
|
||||
|
||||
rb_scan_args(argc, argv, "11", &image, &options);
|
||||
|
||||
cv::CascadeClassifier* selfptr = obj2cascadeclassifier(self);
|
||||
std::vector<cv::Rect> objects;
|
||||
try {
|
||||
cv::Mat* m = Mat::obj2mat(image);
|
||||
if (NIL_P(options)) {
|
||||
selfptr->detectMultiScale(*m, objects);
|
||||
}
|
||||
else {
|
||||
Check_Type(options, T_HASH);
|
||||
double scale_factor = NUM2DBL_DEFAULT(HASH_LOOKUP(options, "scale_factor"), 1.1);
|
||||
int min_neighbors = NUM2INT_DEFAULT(HASH_LOOKUP(options, "min_neighbors"), 3);
|
||||
cv::Size min_size;
|
||||
cv::Size max_size;
|
||||
|
||||
VALUE tmp = Qnil;
|
||||
tmp = rb_hash_lookup(options, ID2SYM(rb_intern("min_size")));
|
||||
if (!NIL_P(tmp)) {
|
||||
min_size = *(Size::obj2size(tmp));
|
||||
}
|
||||
tmp = rb_hash_lookup(options, ID2SYM(rb_intern("max_size")));
|
||||
if (!NIL_P(tmp)) {
|
||||
max_size = *(Size::obj2size(tmp));
|
||||
}
|
||||
selfptr->detectMultiScale(*m, objects, scale_factor, min_neighbors, 0, min_size, max_size);
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
Error::raise(e);
|
||||
}
|
||||
|
||||
const long size = objects.size();
|
||||
VALUE detected_objects = rb_ary_new_capa(size);
|
||||
for (long i = 0; i < size; i++) {
|
||||
VALUE v = Rect::rect2obj(objects[i]);
|
||||
rb_ary_store(detected_objects, i, v);
|
||||
}
|
||||
|
||||
return detected_objects;
|
||||
}
|
||||
|
||||
void init() {
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CascadeClassifier", rb_cData);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
|
||||
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
|
||||
rb_define_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
|
||||
rb_define_method(rb_klass, "detect_multi_scale", RUBY_METHOD_FUNC(rb_detect_multi_scale), -1);
|
||||
}
|
||||
}
|
||||
}
|
13
ext/opencv/cascadeclassifier.hpp
Normal file
13
ext/opencv/cascadeclassifier.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef RUBY_OPENCV_CASCADECLASSIFIER_H
|
||||
#define RUBY_OPENCV_CASCADECLASSIFIER_H
|
||||
|
||||
/*
|
||||
* Document-class: OpenCV::CascadeClassifier
|
||||
*/
|
||||
namespace rubyopencv {
|
||||
namespace CascadeClassifier {
|
||||
void init();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // RUBY_OPENCV_CASCADECLASSIFIER_H
|
|
@ -1,127 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
curve.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "curve.h"
|
||||
/*
|
||||
* Document-class: OpenCV::Curve
|
||||
*
|
||||
* Curve sequence
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CURVE
|
||||
|
||||
VALUE module;
|
||||
|
||||
VALUE
|
||||
rb_module()
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the curve is closed, return true. Otherwise return false.
|
||||
* @overload closed?
|
||||
* @return [Boolean] Closed or not
|
||||
* @opencv_func CV_IS_SEQ_CLOSED
|
||||
*/
|
||||
VALUE
|
||||
rb_closed_q(VALUE self)
|
||||
{
|
||||
return CV_IS_SEQ_CLOSED(CVSEQ(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the curve is convex, return true. Otherwise return false.
|
||||
* @overload convex?
|
||||
* @return [Boolean] Convex or not
|
||||
* @opencv_func CV_IS_SEQ_CONVEX
|
||||
*/
|
||||
VALUE
|
||||
rb_convex_q(VALUE self)
|
||||
{
|
||||
return CV_IS_SEQ_CONVEX(CVSEQ(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the curve is hole(inner contour), return true. Otherwise return false.
|
||||
* @overload hole?
|
||||
* @return [Boolean] Hole or not
|
||||
* @opencv_func CV_IS_SEQ_HOLE
|
||||
*/
|
||||
VALUE
|
||||
rb_hole_q(VALUE self)
|
||||
{
|
||||
return CV_IS_SEQ_HOLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the curve is simple, return true. Otherwise return false.
|
||||
* @overload simple?
|
||||
* @return [Boolean] Simple or not
|
||||
* @opencv_func CV_IS_SEQ_SIMPLE
|
||||
*/
|
||||
VALUE
|
||||
rb_simple_q(VALUE self)
|
||||
{
|
||||
return CV_IS_SEQ_SIMPLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates length of a curve
|
||||
* @overload arc_length(slice = nil, is_closed = nil)
|
||||
* @param slice [Range,CvSlice,nil] Starting and ending points of the curve.
|
||||
* By default, the whole curve length is calculated.
|
||||
* @param is_closed [Boolean,nil] Indicates whether the curve is closed or not.
|
||||
* There are 3 cases:
|
||||
* * is_closed = true - the curve is assumed to be unclosed.
|
||||
* * is_closed = false - the curve is assumed to be closed.
|
||||
* * is_closed = nil (default) use self#closed?
|
||||
* @return [Number] Length of the curve
|
||||
* @opencv_func cvArcLength
|
||||
*/
|
||||
VALUE
|
||||
rb_arc_length(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE slice, is_closed;
|
||||
rb_scan_args(argc, argv, "02", &slice, &is_closed);
|
||||
double length = 0;
|
||||
try {
|
||||
length = cvArcLength(CVARR(self),
|
||||
NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
|
||||
TRUE_OR_FALSE(is_closed, -1));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(length);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_module()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (module)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
module = rb_define_module_under(opencv, "Curve");
|
||||
rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
||||
rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
|
||||
rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
|
||||
rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
|
||||
rb_define_method(module, "arc_length", RUBY_METHOD_FUNC(rb_arc_length), -1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CURVE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
curve.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSEQ_CURVE_H
|
||||
#define RUBY_OPENCV_CVSEQ_CURVE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CURVE namespace mCurve {
|
||||
#define __NAMESPACE_END_CURVE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CURVE
|
||||
|
||||
VALUE rb_module();
|
||||
|
||||
void init_ruby_module();
|
||||
|
||||
VALUE rb_closed_q(VALUE self);
|
||||
VALUE rb_convex_q(VALUE self);
|
||||
VALUE rb_hole_q(VALUE self);
|
||||
VALUE rb_simple_q(VALUE self);
|
||||
VALUE rb_arc_length(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
__NAMESPACE_END_CURVE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSEQ_CURVE_H
|
|
@ -1,64 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvavgcomp.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvavgcomp.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvAvgComp
|
||||
*
|
||||
* CvRect with parameter "neighbors"
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_AVGCOMP
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvAvgComp *ptr;
|
||||
return Data_Make_Struct(klass, CvAvgComp, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return neighbors
|
||||
* @overload neighbors
|
||||
* @return [Integer] neighbors
|
||||
*/
|
||||
VALUE
|
||||
rb_neighbors(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVAVGCOMP(self)->neighbors);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
VALUE cvrect = rb_define_class_under(opencv, "CvRect", rb_cObject);
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv(), cvrect = cCvRect::rb_class();
|
||||
rb_klass = rb_define_class_under(opencv, "CvAvgComp", cvrect);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "neighbors", RUBY_METHOD_FUNC(rb_neighbors), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_AVGCOMP
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,39 +0,0 @@
|
|||
/**********************************************************************
|
||||
|
||||
cvavgcomp.h
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
**********************************************************************/
|
||||
#ifndef RUBY_OPENCV_AVGCOMP_H
|
||||
#define RUBY_OPENCV_AVGCOMP_H
|
||||
|
||||
#define __NAMESPACE_BEGIN_AVGCOMP namespace cCvAvgComp {
|
||||
#define __NAMESPACE_END_AVGCOMP }
|
||||
|
||||
#include <opencv.h>
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_AVGCOMP
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_neighbors(VALUE self);
|
||||
|
||||
__NAMESPACE_END_AVGCOMP
|
||||
|
||||
inline CvAvgComp *CVAVGCOMP(VALUE object){
|
||||
CvAvgComp *ptr;
|
||||
Data_Get_Struct(object, CvAvgComp, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
|
||||
#endif // RUBY_OPENCV_AVGCOMP_H
|
|
@ -1,195 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvbox2d.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvbox2d.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvBox2D
|
||||
*
|
||||
* Stores coordinates of a rotated rectangle.
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVBOX2D
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvBox2D *ptr;
|
||||
return Data_Make_Struct(klass, CvBox2D, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a box
|
||||
* @overload new(center=nil, size=nil, angle=nil)
|
||||
* @param center [CvPoint2D32f,nil] Center of the box
|
||||
* @param size [CvSize,nil] Size of the box
|
||||
* @param angle [Number,nil] Angle between the horizontal axis and the first side in degrees
|
||||
* @return [CvBox2D] New box
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE center, size, angle;
|
||||
CvBox2D* self_ptr = CVBOX2D(self);
|
||||
rb_scan_args(argc, argv, "03", ¢er, &size, &angle);
|
||||
|
||||
if (!NIL_P(center)) {
|
||||
self_ptr->center = VALUE_TO_CVPOINT2D32F(center);
|
||||
}
|
||||
if (!NIL_P(size)) {
|
||||
self_ptr->size = VALUE_TO_CVSIZE2D32F(size);
|
||||
self_ptr->angle = NUM2DBL(angle);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns center point of the box
|
||||
* @overload center
|
||||
* @return [CvPoint2D32f] Center of the box
|
||||
*/
|
||||
VALUE
|
||||
rb_center(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set center point of the box
|
||||
* @overload center=value
|
||||
* @param value [CvPoint2D32f] Center of the box
|
||||
* @return [CvBox2D] self
|
||||
*/
|
||||
VALUE
|
||||
rb_set_center(VALUE self, VALUE value)
|
||||
{
|
||||
CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns size of the box
|
||||
* @overload size
|
||||
* @return [CvSize2D32f] Size of the box
|
||||
*/
|
||||
VALUE
|
||||
rb_size(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set size of the box
|
||||
* @overload size=value
|
||||
* @param value [CvSize2D32f] Size of the box
|
||||
* @return [CvBox2D] self
|
||||
*/
|
||||
VALUE
|
||||
rb_set_size(VALUE self, VALUE value)
|
||||
{
|
||||
CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns angle of the box
|
||||
* @overload angle
|
||||
* @return [Float] Angle of the box
|
||||
*/
|
||||
VALUE
|
||||
rb_angle(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVBOX2D(self)->angle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set angle of the box
|
||||
* @overload angle=value
|
||||
* @param value [Number] Angle of the box
|
||||
* @return [CvBox2D] self
|
||||
*/
|
||||
VALUE
|
||||
rb_set_angle(VALUE self, VALUE value)
|
||||
{
|
||||
CVBOX2D(self)->angle = NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find box vertices
|
||||
* @overload points
|
||||
* @return [Array<CvPoint2D32f>] Vertices of the box
|
||||
* @opencv_func cvBoxPoints
|
||||
*/
|
||||
VALUE
|
||||
rb_points(VALUE self)
|
||||
{
|
||||
const int n = 4;
|
||||
CvPoint2D32f p[n];
|
||||
try {
|
||||
cvBoxPoints(*CVBOX2D(self), p);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
VALUE points = rb_ary_new2(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
return rb_allocate(cCvBox2D::rb_class());
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvBox2D box)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVBOX2D(object) = box;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvBox2D", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
||||
rb_define_method(rb_klass, "center=", RUBY_METHOD_FUNC(rb_set_center), 1);
|
||||
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
|
||||
rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
|
||||
rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
|
||||
rb_define_method(rb_klass, "angle=", RUBY_METHOD_FUNC(rb_set_angle), 1);
|
||||
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVBOX2D
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,61 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvbox2d.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVBOX2D_H
|
||||
#define RUBY_OPENCV_CVBOX2D_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVBOX2D namespace cCvBox2D {
|
||||
#define __NAMESPACE_END_CVBOX2D }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVBOX2D
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_center(VALUE self);
|
||||
VALUE rb_set_center(VALUE self, VALUE value);
|
||||
VALUE rb_size(VALUE self);
|
||||
VALUE rb_set_size(VALUE self, VALUE value);
|
||||
VALUE rb_angle(VALUE self);
|
||||
VALUE rb_set_angle(VALUE self, VALUE value);
|
||||
VALUE rb_points(VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
VALUE new_object(CvBox2D box);
|
||||
|
||||
__NAMESPACE_END_CVBOX2D
|
||||
|
||||
inline CvBox2D*
|
||||
CVBOX2D(VALUE object){
|
||||
CvBox2D *ptr;
|
||||
Data_Get_Struct(object, CvBox2D, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvBox2D
|
||||
VALUE_TO_CVBOX2D(VALUE object){
|
||||
if (rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
|
||||
return *CVBOX2D(object);
|
||||
}
|
||||
else {
|
||||
raise_typeerror(object, cCvBox2D::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVBOX2D_H
|
|
@ -1,607 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcapture.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvcapture.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvCapture
|
||||
*
|
||||
* Class for video capturing from video files or cameras
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCAPTURE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
void
|
||||
cvcapture_free(void *ptr)
|
||||
{
|
||||
if (ptr)
|
||||
cvReleaseCapture((CvCapture**)&ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open video file or a capturing device for video capturing
|
||||
* @scope class
|
||||
* @overload open(dev = nil)
|
||||
* @param dev [String,Fixnum,Simbol,nil] Video capturing device
|
||||
* * If dev is a string (i.e "stream.avi"), reads video stream from a file.
|
||||
* * If dev is a number or symbol (included in CvCapture::INTERFACE), reads video stream from a device.
|
||||
* * If dev is a nil, same as CvCapture.open(:any)
|
||||
* @return [CvCapture] Opened CvCapture instance
|
||||
* @opencv_func cvCaptureFromCAM
|
||||
* @opencv_func cvCaptureFromFile
|
||||
*/
|
||||
VALUE
|
||||
rb_open(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE device;
|
||||
rb_scan_args(argc, argv, "01", &device);
|
||||
CvCapture *capture = 0;
|
||||
try {
|
||||
switch (TYPE(device)) {
|
||||
case T_STRING:
|
||||
capture = cvCaptureFromFile(StringValueCStr(device));
|
||||
break;
|
||||
case T_FIXNUM:
|
||||
capture = cvCaptureFromCAM(FIX2INT(device));
|
||||
break;
|
||||
case T_SYMBOL: {
|
||||
VALUE cap_index = rb_hash_lookup(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
|
||||
if (NIL_P(cap_index))
|
||||
rb_raise(rb_eArgError, "undefined interface.");
|
||||
capture = cvCaptureFromCAM(NUM2INT(cap_index));
|
||||
break;
|
||||
}
|
||||
case T_NIL:
|
||||
capture = cvCaptureFromCAM(CV_CAP_ANY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
if (!capture)
|
||||
rb_raise(rb_eStandardError, "Invalid capture format.");
|
||||
return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, capture);
|
||||
}
|
||||
|
||||
/*
|
||||
* Grabs the next frame from video file or capturing device.
|
||||
* @overload grab
|
||||
* @return [Boolean] If grabbing a frame successed, returns true, otherwise returns false.
|
||||
* @opencv_func cvGrabFrame
|
||||
*/
|
||||
VALUE
|
||||
rb_grab(VALUE self)
|
||||
{
|
||||
int grab = 0;
|
||||
try {
|
||||
grab = cvGrabFrame(CVCAPTURE(self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return grab ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes and returns the grabbed video frame.
|
||||
* @overload retrieve
|
||||
* @return [IplImage] Grabbed video frame
|
||||
* @return [nil] Failed to grabbing a frame
|
||||
* @opencv_func cvRetrieveFrame
|
||||
*/
|
||||
VALUE
|
||||
rb_retrieve(VALUE self)
|
||||
{
|
||||
VALUE image = Qnil;
|
||||
IplImage *frame = NULL;
|
||||
try {
|
||||
if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
|
||||
return Qnil;
|
||||
}
|
||||
image = cIplImage::new_object(frame->width, frame->height,
|
||||
CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
|
||||
if (frame->origin == IPL_ORIGIN_TL) {
|
||||
cvCopy(frame, CVARR(image));
|
||||
}
|
||||
else {
|
||||
cvFlip(frame, CVARR(image));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return image;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Grabs, decodes and returns the next video frame.
|
||||
* @overload query
|
||||
* @return [IplImage] Next video frame
|
||||
* @return [nil] Failed to read next video frame
|
||||
* @opencv_func cvQueryFrame
|
||||
*/
|
||||
VALUE
|
||||
rb_query(VALUE self)
|
||||
{
|
||||
VALUE image = Qnil;
|
||||
IplImage *frame = NULL;
|
||||
try {
|
||||
if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
|
||||
return Qnil;
|
||||
}
|
||||
image = cIplImage::new_object(frame->width, frame->height,
|
||||
CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
|
||||
if (frame->origin == IPL_ORIGIN_TL) {
|
||||
cvCopy(frame, CVARR(image));
|
||||
}
|
||||
else {
|
||||
cvFlip(frame, CVARR(image));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_capture_property(VALUE self, int id)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvGetCaptureProperty(CVCAPTURE(self), id);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_set_capture_property(VALUE self, int id, VALUE value)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvSetCaptureProperty(CVCAPTURE(self), id, NUM2DBL(value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get film current position in milliseconds or video capture timestamp.
|
||||
* @overload millisecond
|
||||
* @return [Number] Current position of the video file in milliseconds or video capture timestamp
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_MSEC)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_millisecond(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_POS_MSEC);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set film current position in milliseconds or video capture timestamp.
|
||||
* @overload millisecond=value
|
||||
* @param value [Number] Position in milliseconds or video capture timestamp.
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_MSEC)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_millisecond(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_POS_MSEC, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get 0-based index of the frame to be decoded/captured next
|
||||
* @overload frames
|
||||
* @return [Number] 0-based index of the frame to be decoded/captured next
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_FRAMES)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_frames(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_POS_FRAMES);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set 0-based index of the frame to be decoded/captured next
|
||||
* @overload frames=value
|
||||
* @param value [Number] 0-based index of the frame to be decoded/captured next
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_FRAMES)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_frames(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_POS_FRAMES, value);
|
||||
}
|
||||
/*
|
||||
* Get relative position of video file
|
||||
* @overload avi_ratio
|
||||
* @return [Number] Relative position of video file (0: Start of the film, 1: End of the film)
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_AVI_RATIO)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_avi_ratio(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO);
|
||||
}
|
||||
/*
|
||||
* Set relative position of video file
|
||||
* @overload avi_ratio=value
|
||||
* @param value [Number] Relative position of video file (0: Start of the film, 1: End of the film)
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_AVI_RATIO)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_avi_ratio(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get size of frames in the video stream.
|
||||
* @overload size
|
||||
* @return [Size] Size of frames in the video stream.
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_size(VALUE self)
|
||||
{
|
||||
CvSize size;
|
||||
try {
|
||||
CvCapture* self_ptr = CVCAPTURE(self);
|
||||
size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
|
||||
(int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvSize::new_object(size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set size of frames in the video stream.
|
||||
* @overload size=value
|
||||
* @param value [CvSize] Size of frames
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_size(VALUE self, VALUE value)
|
||||
{
|
||||
double result = 0;
|
||||
CvSize size = VALUE_TO_CVSIZE(value);
|
||||
try {
|
||||
CvCapture* self_ptr = CVCAPTURE(self);
|
||||
cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH, size.width);
|
||||
result = cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT, size.height);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return DBL2NUM(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get width of frames in the video stream.
|
||||
* @overload width
|
||||
* @return [Number] Width of frames in the video stream.
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_FRAME_WIDTH)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_width(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_WIDTH);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set width of frames in the video stream.
|
||||
* @overload width=value
|
||||
* @param value [Number] Width of frames
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_width(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_FRAME_WIDTH, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get height of frames in the video stream.
|
||||
* @overload height
|
||||
* @return [Number] Height of frames in the video stream.
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_HEIGHT)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_height(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set height of frames in the video stream.
|
||||
* @overload height=value
|
||||
* @param value [Number] Height of frames
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_HEIGHT)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_height(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get frame rate
|
||||
* @overload fps
|
||||
* @return [Number] Frame rate
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FPS)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_fps(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_FPS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set frame rate
|
||||
* @overload fps=value
|
||||
* @param value [Number] Frame rate
|
||||
* @return [Number]
|
||||
* @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FPS)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_fps(VALUE self, VALUE value)
|
||||
{
|
||||
return rb_set_capture_property(self, CV_CAP_PROP_FPS, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get 4 character code of codec. see http://www.fourcc.org/
|
||||
* @overload fourcc
|
||||
* @return [Number] Codec code
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FOURCC)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_fourcc(VALUE self)
|
||||
{
|
||||
char str[4];
|
||||
double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
|
||||
sprintf(str, "%s", (char*)&fourcc);
|
||||
return rb_str_new2(str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get number of frames in video file.
|
||||
* @overload frame_count
|
||||
* @return [Number] Number of frames
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_COUNT)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_frame_count(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_COUNT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get format of images returned by CvCapture#retrieve
|
||||
* @overload format
|
||||
* @return [Number] format
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FORMAT)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_format(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_FORMAT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a backend-specific value indicating the current capture mode
|
||||
* @overload mode
|
||||
* @return [Number] Backend-specific value indicating the current capture mode
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_MODE)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_mode(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_MODE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get brightness of the image (only for cameras)
|
||||
* @overload brightness
|
||||
* @return [Number] Brightness
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_BRIGHTNESS)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_brightness(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_BRIGHTNESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get contrast of the image (only for cameras)
|
||||
* @overload contrast
|
||||
* @return [Number] Contrast
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_CONTRAST)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_contrast(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_CONTRAST);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get saturation of the image (only for cameras)
|
||||
* @overload saturation
|
||||
* @return [Number] Saturation
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_SATURATION)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_saturation(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_SATURATION);
|
||||
}
|
||||
/*
|
||||
* Get hue of the image (only for cameras)
|
||||
* @overload hue
|
||||
* @return [Number] Hue
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_HUE)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_hue(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_HUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get gain of the image (only for cameras)
|
||||
* @overload gain
|
||||
* @return [Number] Gain
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_GAIN)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_gain(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_GAIN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get exposure (only for cameras)
|
||||
* @overload exposure
|
||||
* @return [Number] Exposure
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_EXPOSURE)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_exposure(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_EXPOSURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get boolean flags indicating whether images should be converted to RGB
|
||||
* @overload convert_rgb
|
||||
* @return [Boolean] Whether images should be converted to RGB
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_CONVERT_RGB)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_convert_rgb(VALUE self)
|
||||
{
|
||||
int flag = 0;
|
||||
try {
|
||||
flag = (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_CONVERT_RGB);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return flag ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
|
||||
* @overload rectification
|
||||
* @return [Number] Rectification flag
|
||||
* @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_RECTIFICATION)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_rectification(VALUE self)
|
||||
{
|
||||
return rb_get_capture_property(self, CV_CAP_PROP_RECTIFICATION);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvCapture", rb_cData);
|
||||
|
||||
VALUE video_interface = rb_hash_new();
|
||||
/*
|
||||
* :any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394,
|
||||
* :stereo, :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime
|
||||
*/
|
||||
rb_define_const(rb_klass, "INTERFACE", video_interface);
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));
|
||||
rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
|
||||
|
||||
rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
|
||||
|
||||
rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
|
||||
rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
|
||||
rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);
|
||||
rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_get_millisecond), 0);
|
||||
rb_define_method(rb_klass, "millisecond=", RUBY_METHOD_FUNC(rb_set_millisecond), 1);
|
||||
rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_get_frames), 0);
|
||||
rb_define_method(rb_klass, "frames=", RUBY_METHOD_FUNC(rb_set_frames), 1);
|
||||
rb_define_method(rb_klass, "avi_ratio", RUBY_METHOD_FUNC(rb_get_avi_ratio), 0);
|
||||
rb_define_method(rb_klass, "avi_ratio=", RUBY_METHOD_FUNC(rb_set_avi_ratio), 1);
|
||||
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_get_size), 0);
|
||||
rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
|
||||
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_get_width), 0);
|
||||
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
||||
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_get_height), 0);
|
||||
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
||||
rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_get_fps), 0);
|
||||
rb_define_method(rb_klass, "fps=", RUBY_METHOD_FUNC(rb_set_fps), 1);
|
||||
rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_get_fourcc), 0);
|
||||
rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_get_frame_count), 0);
|
||||
rb_define_method(rb_klass, "format", RUBY_METHOD_FUNC(rb_get_format), 0);
|
||||
rb_define_method(rb_klass, "mode", RUBY_METHOD_FUNC(rb_get_mode), 0);
|
||||
rb_define_method(rb_klass, "brightness", RUBY_METHOD_FUNC(rb_get_brightness), 0);
|
||||
rb_define_method(rb_klass, "contrast", RUBY_METHOD_FUNC(rb_get_contrast), 0);
|
||||
rb_define_method(rb_klass, "saturation", RUBY_METHOD_FUNC(rb_get_saturation), 0);
|
||||
rb_define_method(rb_klass, "hue", RUBY_METHOD_FUNC(rb_get_hue), 0);
|
||||
rb_define_method(rb_klass, "gain", RUBY_METHOD_FUNC(rb_get_gain), 0);
|
||||
rb_define_method(rb_klass, "exposure", RUBY_METHOD_FUNC(rb_get_exposure), 0);
|
||||
rb_define_method(rb_klass, "convert_rgb", RUBY_METHOD_FUNC(rb_get_convert_rgb), 0);
|
||||
rb_define_method(rb_klass, "rectification", RUBY_METHOD_FUNC(rb_get_rectification), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCAPTURE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcapture.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCAPTURE_H
|
||||
#define RUBY_OPENCV_CVCAPTURE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCAPTURE namespace cCvCapture {
|
||||
#define __NAMESPACE_END_CVCAPTURE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCAPTURE
|
||||
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
void cvcapture_free(void *ptr);
|
||||
VALUE rb_open(int argc, VALUE *argv, VALUE klass);
|
||||
|
||||
VALUE rb_grab(VALUE self);
|
||||
VALUE rb_retrieve(VALUE self);
|
||||
VALUE rb_query(VALUE self);
|
||||
|
||||
VALUE rb_get_millisecond(VALUE self);
|
||||
VALUE rb_set_millisecond(VALUE self, VALUE value);
|
||||
VALUE rb_get_frames(VALUE self);
|
||||
VALUE rb_set_frames(VALUE self, VALUE value);
|
||||
VALUE rb_get_avi_ratio(VALUE self);
|
||||
VALUE rb_set_avi_ratio(VALUE self, VALUE value);
|
||||
VALUE rb_get_size(VALUE self);
|
||||
VALUE rb_set_size(VALUE self, VALUE value);
|
||||
VALUE rb_get_width(VALUE self);
|
||||
VALUE rb_set_width(VALUE self, VALUE value);
|
||||
VALUE rb_get_height(VALUE self);
|
||||
VALUE rb_set_height(VALUE self, VALUE value);
|
||||
VALUE rb_get_fps(VALUE self);
|
||||
VALUE rb_set_fps(VALUE self, VALUE value);
|
||||
VALUE rb_get_fourcc(VALUE self);
|
||||
VALUE rb_get_frame_count(VALUE self);
|
||||
VALUE rb_get_format(VALUE self);
|
||||
VALUE rb_get_mode(VALUE self);
|
||||
VALUE rb_get_brightness(VALUE self);
|
||||
VALUE rb_get_contrast(VALUE self);
|
||||
VALUE rb_get_saturation(VALUE self);
|
||||
VALUE rb_get_hue(VALUE self);
|
||||
VALUE rb_get_gain(VALUE self);
|
||||
VALUE rb_get_exposure(VALUE self);
|
||||
VALUE rb_get_convert_rgb(VALUE self);
|
||||
VALUE rb_get_rectification(VALUE self);
|
||||
|
||||
__NAMESPACE_END_CVCAPTURE
|
||||
|
||||
|
||||
inline CvCapture*
|
||||
CVCAPTURE(VALUE object) {
|
||||
CvCapture *ptr;
|
||||
Data_Get_Struct(object, CvCapture, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCAPTURE_H
|
|
@ -1,233 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvchain.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvchain.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvChain
|
||||
*
|
||||
* Freeman chain code
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCHAIN
|
||||
|
||||
#define APPROX_CHAIN_OPTION(op) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
|
||||
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_HASH(op, "method"), CV_CHAIN_APPROX_SIMPLE)
|
||||
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_HASH(op, "parameter"))
|
||||
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_HASH(op, "minimal_perimeter"))
|
||||
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new chain code
|
||||
* @overload new(storage=nil)
|
||||
* @param storage [CvMemStorage,nil] Sequence location (If storage is nil, allocates a new storage automatically)
|
||||
* @return [CvChain] New CvChain instance
|
||||
* @opencv_func cvCreateSeq (seq_flags=CV_SEQ_ELTYPE_CODE)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvMemStorage *storage;
|
||||
VALUE storage_value;
|
||||
if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
|
||||
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
||||
storage = CVMEMSTORAGE(storage_value);
|
||||
}
|
||||
else
|
||||
storage = rb_cvCreateMemStorage(0);
|
||||
try {
|
||||
DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
|
||||
sizeof(int), storage);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
CvSeq* self_ptr = CVSEQ(self);
|
||||
cCvSeq::register_elem_class(self_ptr, rb_cFixnum);
|
||||
register_root_object(self_ptr, storage_value);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns Freeman chain code origin
|
||||
* @overload origin
|
||||
* @return [CvPoint] Origin of the chain code
|
||||
*/
|
||||
VALUE
|
||||
rb_origin(VALUE self)
|
||||
{
|
||||
return cCvPoint::new_object(CVCHAIN(self)->origin);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set Freeman chain code origin
|
||||
* @overload origin=value
|
||||
* @param value [CvPoint] Origin of the chain code
|
||||
* @return [CvChain] self
|
||||
*/
|
||||
VALUE
|
||||
rb_set_origin(VALUE self, VALUE origin)
|
||||
{
|
||||
CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the chain codes
|
||||
* @overload codes
|
||||
* @return [Array<Fixnum>] Chain codes
|
||||
* @opencv_func cvStartReadChainPoints
|
||||
* @opencv_func CV_READ_SEQ_ELEM
|
||||
*/
|
||||
VALUE
|
||||
rb_codes(VALUE self)
|
||||
{
|
||||
CvChain *chain = CVCHAIN(self);
|
||||
CvChainPtReader reader;
|
||||
int total = chain->total;
|
||||
VALUE ary = rb_ary_new2(total);
|
||||
try {
|
||||
cvStartReadChainPoints(chain, &reader);
|
||||
for (int i = 0; i < total; ++i) {
|
||||
CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
|
||||
rb_ary_store(ary, i, INT2FIX(reader.code));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the points of the chain codes
|
||||
* @overload points
|
||||
* @return [Array<CvPoint>] Points of the chain codes
|
||||
* @opencv_func cvStartReadChainPoints
|
||||
* @opencv_func CV_READ_CHAIN_POINT
|
||||
*/
|
||||
VALUE
|
||||
rb_points(VALUE self)
|
||||
{
|
||||
CvChain *chain = CVCHAIN(self);
|
||||
CvChainPtReader reader;
|
||||
CvPoint p = chain->origin;
|
||||
int total = chain->total;
|
||||
VALUE ary = rb_ary_new2(total);
|
||||
try {
|
||||
cvStartReadChainPoints(chain, &reader);
|
||||
for (int i = 0; i < total; ++i) {
|
||||
CV_READ_CHAIN_POINT(p, reader);
|
||||
rb_ary_store(ary, i, cCvPoint::new_object(p));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
|
||||
/*
|
||||
* Approximates Freeman chains with a polygonal curve
|
||||
* @overload approx_chain(options)
|
||||
* @param options [Hash] Parameters
|
||||
* @option options [Symbol] :method Approximation method (see the description of CvMat#find_contours)
|
||||
* @option options [Number] :minimal_perimeter Approximates only those contours whose perimeters
|
||||
* are not less than minimal_perimeter. Other chains are removed from the resulting structure.
|
||||
* @option options [Boolean] :recursive Recursion flag. If it is true, the function approximates
|
||||
* all chains that can be obtained from chain by using the h_next or v_next links.
|
||||
* Otherwise, the single input chain is approximated.
|
||||
* @return [CvSeq<CvPoint>] Polygonal curve
|
||||
* @opencv_func cvApproxChains
|
||||
*/
|
||||
VALUE
|
||||
rb_approx_chains(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE approx_chain_option;
|
||||
rb_scan_args(argc, argv, "01", &approx_chain_option);
|
||||
|
||||
approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
|
||||
VALUE storage = cCvMemStorage::new_object();
|
||||
CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
|
||||
APPROX_CHAIN_METHOD(approx_chain_option),
|
||||
APPROX_CHAIN_PARAMETER(approx_chain_option),
|
||||
APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
|
||||
APPROX_CHAIN_RECURSIVE(approx_chain_option));
|
||||
|
||||
if (seq && seq->total > 0) {
|
||||
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
VALUE storage = cCvMemStorage::new_object();
|
||||
CvSeq *seq = NULL;
|
||||
try {
|
||||
seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(int), CVMEMSTORAGE(storage));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
VALUE cvseq = rb_define_class_under(opencv, "CvSeq");
|
||||
VALUE curve = rb_define_module_under(opencv, "Curve");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
VALUE cvseq = cCvSeq::rb_class();
|
||||
VALUE curve = mCurve::rb_module();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvChain", cvseq);
|
||||
rb_include_module(rb_klass, curve);
|
||||
VALUE approx_chain_option = rb_hash_new();
|
||||
rb_define_const(rb_klass, "APPROX_CHAIN_OPTION", approx_chain_option);
|
||||
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("approx_simple")));
|
||||
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("parameter")), rb_float_new(0));
|
||||
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("minimal_perimeter")), INT2FIX(0));
|
||||
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
||||
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
|
||||
rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 1);
|
||||
rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
|
||||
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
||||
rb_define_method(rb_klass, "approx_chains", RUBY_METHOD_FUNC(rb_approx_chains), -1);
|
||||
rb_define_alias(rb_klass, "approx", "approx_chains");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCHAIN
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,46 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvchain.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCHAIN_H
|
||||
#define RUBY_OPENCV_CVCHAIN_H
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCHAIN namespace cCvChain {
|
||||
#define __NAMESPACE_END_CVCHAIN }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCHAIN
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_origin(VALUE self);
|
||||
VALUE rb_set_origin(VALUE self, VALUE origin);
|
||||
VALUE rb_codes(VALUE self);
|
||||
VALUE rb_points(VALUE self);
|
||||
VALUE rb_approx_chains(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
|
||||
__NAMESPACE_END_CVCHAIN
|
||||
|
||||
inline CvChain*
|
||||
CVCHAIN(VALUE object){
|
||||
CvChain *ptr;
|
||||
Data_Get_Struct(object, CvChain, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCHAIN_H
|
|
@ -1,126 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcircle32f.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvcircle32f.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvCircle32f
|
||||
*
|
||||
* Combination of center and radius.
|
||||
*
|
||||
* see CvMat#hough_circles
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCIRCLE32F
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvCircle32f *ptr;
|
||||
return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns center point of the circle
|
||||
* @overload center
|
||||
* @return [CvPoint2D32f] Center point of the circle
|
||||
*/
|
||||
VALUE
|
||||
rb_center(VALUE self)
|
||||
{
|
||||
return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns radius of the circle
|
||||
* @overload radius
|
||||
* @return [Number] Radius of the circle
|
||||
*/
|
||||
VALUE
|
||||
rb_radius(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVCIRCLE32F(self)->radius);
|
||||
}
|
||||
|
||||
/*
|
||||
* Accesses to parameters of the circle by array-like interface ([X-coordinate, Y-coordinate, radius])
|
||||
* @overload []
|
||||
* @param index [Integer] Index
|
||||
* @return [Number] X-coordinate, Y-coordinate or radius of the circle
|
||||
*/
|
||||
VALUE
|
||||
rb_aref(VALUE self, VALUE index)
|
||||
{
|
||||
switch (NUM2INT(index)) {
|
||||
case 0:
|
||||
return DBL2NUM(CVCIRCLE32F(self)->center.x);
|
||||
break;
|
||||
case 1:
|
||||
return DBL2NUM(CVCIRCLE32F(self)->center.y);
|
||||
break;
|
||||
case 2:
|
||||
return DBL2NUM(CVCIRCLE32F(self)->radius);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eIndexError, "index should be 0...3");
|
||||
break;
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns parameters of the circle as an array which contains [center<CvPoint2D32f>, radius<Number>]
|
||||
* @overload to_ary
|
||||
* @return [Array<CvPoint2D32f,Number>] An array which contains [center, radius]
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(2, rb_center(self), rb_radius(self));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvCircle32f circle32f)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVCIRCLE32F(object) = circle32f;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
||||
rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
|
||||
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCIRCLE32F
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,52 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcircle32f.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCIRCLE32F_H
|
||||
#define RUBY_OPENCV_CVCIRCLE32F_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCIRCLE32F namespace cCvCircle32f {
|
||||
#define __NAMESPACE_END_CVCIRCLE32F }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
|
||||
typedef struct CvCircle32f {
|
||||
CvPoint2D32f center;
|
||||
float radius;
|
||||
} CvCircle32f;
|
||||
|
||||
__NAMESPACE_BEGIN_CVCIRCLE32F
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_center(VALUE self);
|
||||
VALUE rb_radius(VALUE self);
|
||||
VALUE rb_aref(VALUE self, VALUE index);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object(CvCircle32f circle32f);
|
||||
|
||||
__NAMESPACE_END_CVCIRCLE32F
|
||||
|
||||
inline CvCircle32f*
|
||||
CVCIRCLE32F(VALUE object)
|
||||
{
|
||||
CvCircle32f *ptr;
|
||||
Data_Get_Struct(object, CvCircle32f, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCIRCLE32F_H
|
|
@ -1,156 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvconnectedcomp.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvconnectedcomp.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvConnectedComp
|
||||
*
|
||||
* Connected component
|
||||
* see CvMat#flood_fill
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONNECTEDCOMP
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvConnectedComp *ptr;
|
||||
return Data_Make_Struct(klass, CvConnectedComp, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
* @overload new(area = nil, value = nil, rect = nil, contour = nil)
|
||||
* @param area [Number] Area of the segmented component
|
||||
* @param value [CvScalar] Average color of the connected component
|
||||
* @param rect [CvRect] ROI of the segmented component
|
||||
* @param contour [CvSeq] Optional component boundary
|
||||
* @return [CvConnectedComp] self
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE area, value, rect, contour;
|
||||
rb_scan_args(argc, argv, "04", &area, &value, &rect, &contour);
|
||||
|
||||
if (!NIL_P(area))
|
||||
CVCONNECTEDCOMP(self)->area = NUM2DBL(area);
|
||||
if (!NIL_P(value))
|
||||
CVCONNECTEDCOMP(self)->value = *CVSCALAR(value);
|
||||
if (!NIL_P(rect))
|
||||
CVCONNECTEDCOMP(self)->rect = *CVRECT(rect);
|
||||
if (!NIL_P(contour))
|
||||
CVCONNECTEDCOMP(self)->contour = CVSEQ(contour);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns area of connected component
|
||||
* @overload area
|
||||
* @return [Number] Area of the connected component
|
||||
*/
|
||||
VALUE
|
||||
rb_area(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVCONNECTEDCOMP(self)->area);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return average color of the connected component.
|
||||
* @overload value
|
||||
* @return [CvScalar] Average color of the connected component
|
||||
*/
|
||||
VALUE
|
||||
rb_value(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvScalar::rb_class(), &CVCONNECTEDCOMP(self)->value, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return ROI of the segmented component
|
||||
* @overload rect
|
||||
* @return [CvRect] ROI of the segmented component
|
||||
*/
|
||||
VALUE
|
||||
rb_rect(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvRect::rb_class(), &CVCONNECTEDCOMP(self)->rect, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set ROI of the segmented component
|
||||
* @overload rect=value
|
||||
* @param value [CvRect] ROI to set
|
||||
* @return [CvRect] ROI of the segmented component
|
||||
*/
|
||||
VALUE
|
||||
rb_set_rect(VALUE self, VALUE rect)
|
||||
{
|
||||
CVCONNECTEDCOMP(self)->rect = VALUE_TO_CVRECT(rect);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns optional component boundary
|
||||
* @overload contour
|
||||
* @return [CvContour] Optional component boundary
|
||||
*/
|
||||
VALUE
|
||||
rb_contour(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvContour::rb_class(), &CVCONNECTEDCOMP(self)->contour, self);
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
return rb_allocate(rb_klass);
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvConnectedComp comp)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVCONNECTEDCOMP(object) = comp;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvConnectedComp", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "area", RUBY_METHOD_FUNC(rb_area), 0);
|
||||
rb_define_method(rb_klass, "value", RUBY_METHOD_FUNC(rb_value), 0);
|
||||
rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
|
||||
rb_define_method(rb_klass, "rect=", RUBY_METHOD_FUNC(rb_set_rect), 1);
|
||||
rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCONNECTEDCOMP
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,49 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvconnectedcomp.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCONNECTEDCOMP_H
|
||||
#define RUBY_OPENCV_CVCONNECTEDCOMP_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCONNECTEDCOMP namespace cCvConnectedComp {
|
||||
#define __NAMESPACE_END_CVCONNECTEDCOMP }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONNECTEDCOMP
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_area(VALUE self);
|
||||
VALUE rb_value(VALUE self);
|
||||
VALUE rb_rect(VALUE self);
|
||||
VALUE rb_set_rect(VALUE self, VALUE rect);
|
||||
VALUE rb_contour(VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
VALUE new_object(CvConnectedComp comp);
|
||||
|
||||
__NAMESPACE_END_CVCONNECTEDCOMP
|
||||
|
||||
inline CvConnectedComp*
|
||||
CVCONNECTEDCOMP(VALUE object)
|
||||
{
|
||||
CvConnectedComp *ptr;
|
||||
Data_Get_Struct(object, CvConnectedComp, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCONNECTEDCOMP_H
|
|
@ -1,350 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcontour.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvcontour.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvContour
|
||||
*
|
||||
* Contour
|
||||
*
|
||||
* @see CvMat#find_contours
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONTOUR
|
||||
|
||||
#define APPROX_POLY_OPTION(op) rb_get_option_table(rb_klass, "APPROX_OPTION", op)
|
||||
#define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", LOOKUP_HASH(op, "method"), CV_POLY_APPROX_DP)
|
||||
#define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_HASH(op, "accuracy"))
|
||||
#define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
void cvcontour_free(void *ptr);
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*
|
||||
* @overload new(seq_flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_GENERIC, storage = nil)
|
||||
* @param [Fixnum] seq_flags Flags of the created sequence, which are combinations of
|
||||
* the element types and sequence types.
|
||||
* - Element type:
|
||||
* - <tt>CV_SEQ_ELTYPE_POINT</tt>: {CvPoint}
|
||||
* - <tt>CV_32FC2</tt>: {CvPoint2D32f}
|
||||
* - <tt>CV_SEQ_ELTYPE_POINT3D</tt>: {CvPoint3D32f}
|
||||
* - <tt>CV_SEQ_ELTYPE_INDEX</tt>: Fixnum
|
||||
* - <tt>CV_SEQ_ELTYPE_CODE</tt>: Fixnum (Freeman code)
|
||||
* - Sequence type:
|
||||
* - <tt>CV_SEQ_KIND_GENERIC</tt>: Generic sequence
|
||||
* - <tt>CV_SEQ_KIND_CURVE</tt>: Curve
|
||||
* @param [CvMemStorage] storage Sequence location
|
||||
* @return [CvContour] self
|
||||
* @opencv_func cvCreateSeq
|
||||
* @example
|
||||
* seq = CvContour.new(CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_CURVE)
|
||||
* seq << CvPoint.new(1, 2)
|
||||
* seq << 3 #=> TypeError
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE seq_flags_value, storage_value;
|
||||
rb_scan_args(argc, argv, "02", &seq_flags_value, &storage_value);
|
||||
|
||||
int seq_flags = 0;
|
||||
if (NIL_P(seq_flags_value)) {
|
||||
seq_flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_GENERIC;
|
||||
}
|
||||
else {
|
||||
Check_Type(seq_flags_value, T_FIXNUM);
|
||||
seq_flags = FIX2INT(seq_flags_value);
|
||||
}
|
||||
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
||||
|
||||
try {
|
||||
DATA_PTR(self) = (CvContour*)cCvSeq::create_seq(seq_flags, sizeof(CvContour), storage_value);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns bounding box of the contour
|
||||
* @overload rect
|
||||
* @return [CvRect] Bounding box of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_rect(VALUE self)
|
||||
{
|
||||
return cCvRect::new_object(CVCONTOUR(self)->rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns color of the contour
|
||||
* @overload color
|
||||
* @return [Number] Color of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_color(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVCONTOUR(self)->color);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set color of the contour
|
||||
* @overload color=value
|
||||
* @param value [Number] Color of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_set_color(VALUE self, VALUE color)
|
||||
{
|
||||
CVCONTOUR(self)->color = NUM2INT(color);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns reserved region values of the contour
|
||||
* @overload reserved
|
||||
* @return [Array<Number>] Reserved region values of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_reserved(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(3,
|
||||
INT2NUM(CVCONTOUR(self)->reserved[0]),
|
||||
INT2NUM(CVCONTOUR(self)->reserved[1]),
|
||||
INT2NUM(CVCONTOUR(self)->reserved[2]));
|
||||
}
|
||||
|
||||
/*
|
||||
* Approximates polygonal curves with desired precision
|
||||
* @overload approx_poly(options)
|
||||
* @param options [Hash] Parameters
|
||||
* @option options [Symbol] :method Approximation method (default :dp)
|
||||
* * :dp - Douglas-Peucker algorithm.
|
||||
* @option options [Number] :accuracy Parameter specifying the approximation accuracy.
|
||||
* This is the maximum distance between the original curve and its approximation.
|
||||
* @option options [Boolean] :recursive Recursion flag. If true, the function approximates
|
||||
* all the contours accessible from curve by h_next and v_next links.
|
||||
* @return [CvContour] Result of the approximation
|
||||
* @return [nil] Approximation faied
|
||||
* @opencv_func cvApproxPoly
|
||||
*/
|
||||
VALUE
|
||||
rb_approx_poly(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE approx_poly_option;
|
||||
rb_scan_args(argc, argv, "01", &approx_poly_option);
|
||||
approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
|
||||
VALUE storage = cCvMemStorage::new_object();
|
||||
CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
|
||||
APPROX_POLY_METHOD(approx_poly_option),
|
||||
APPROX_POLY_ACCURACY(approx_poly_option),
|
||||
APPROX_POLY_RECURSIVE(approx_poly_option));
|
||||
|
||||
if (contour && contour->total > 0) {
|
||||
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates up-right bounding rectangle of point set.
|
||||
* @overload bounding_rect
|
||||
* @return [CvRect] Bounding rectangle
|
||||
* @opencv_func cvBoundingRect
|
||||
*/
|
||||
VALUE
|
||||
rb_bounding_rect(VALUE self)
|
||||
{
|
||||
CvRect rect;
|
||||
try {
|
||||
rect = cvBoundingRect(CVCONTOUR(self), 1);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvRect::new_object(rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates hierarchical representation of contour
|
||||
* @overload create_tree(threshold = 0.0)
|
||||
* @param threshold [Number] If <= 0, the method creates full binary tree representation.
|
||||
* If > 0, the method creates representation with the precision threshold.
|
||||
* @return [CvContourTree] Hierarchical representation of the contour
|
||||
* @opencv_func cvCreateContourTree
|
||||
*/
|
||||
VALUE
|
||||
rb_create_tree(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE threshold, storage;
|
||||
rb_scan_args(argc, argv, "01", &threshold);
|
||||
storage = cCvMemStorage::new_object();
|
||||
CvContourTree *tree = NULL;
|
||||
try {
|
||||
tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
|
||||
}
|
||||
|
||||
/*
|
||||
* Performs a point-in-contour test.
|
||||
* The method determines whether the point is inside a contour, outside,
|
||||
* or lies on an edge (or coincides with a vertex).
|
||||
* @overload in?(point)
|
||||
* @param point [CvPoint2D32f] Point tested against the contour
|
||||
* @return [Boolean] If the point is inside, returns true. If outside, returns false.
|
||||
* If lies on an edge, returns nil.
|
||||
* @opencv_func cvPointPolygonTest
|
||||
*/
|
||||
VALUE
|
||||
rb_in_q(VALUE self, VALUE point)
|
||||
{
|
||||
double n = 0;
|
||||
try {
|
||||
n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates distance between a point and the nearest contour edgex
|
||||
* @overload measure_distance(point)
|
||||
* @param point [CvPoint2D32f] Point tested against the contour
|
||||
* @return Signed distance between the point and the nearest contour edge
|
||||
* @opencv_func cvPointPolygonTest
|
||||
*/
|
||||
VALUE
|
||||
rb_measure_distance(VALUE self, VALUE point)
|
||||
{
|
||||
double distance = 0;
|
||||
try {
|
||||
distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(distance);
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
|
||||
* @overload point_polygon_test(point, measure_dist)
|
||||
* @param point [CvPoint2D32f] Point tested against the contour
|
||||
* @param measure_dist [Boolean] If true, the method estimates the signed distance from the point to
|
||||
* the nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.
|
||||
* @return [Number] When measure_dist = false, the return value is +1, -1 and 0, respectively.
|
||||
* When measure_dist = true, it is a signed distance between the point and the nearest contour edge.
|
||||
* @opencv_func cvPointPolygonTest
|
||||
*/
|
||||
VALUE
|
||||
rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
|
||||
{
|
||||
int measure_dist_flag;
|
||||
|
||||
if (measure_dist == Qtrue)
|
||||
measure_dist_flag = 1;
|
||||
else if (measure_dist == Qfalse)
|
||||
measure_dist_flag = 0;
|
||||
else
|
||||
measure_dist_flag = NUM2INT(measure_dist);
|
||||
|
||||
double dist = Qnil;
|
||||
try {
|
||||
dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
/* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
|
||||
if ((!measure_dist_flag) && ((int)dist) != 0)
|
||||
dist = (dist > 0) ? 1 : -1;
|
||||
|
||||
return rb_float_new(dist);
|
||||
}
|
||||
|
||||
VALUE new_object()
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
rb_initialize(0, NULL, object);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
VALUE cvseq = rb_define_class_under(opencv, "CvSeq");
|
||||
VALUE curve = rb_define_module_under(opencv, "Curve");
|
||||
VALUE pointset = rb_define_module_under(opencv, "PointSet");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
VALUE cvseq = cCvSeq::rb_class();
|
||||
VALUE curve = mCurve::rb_module();
|
||||
VALUE pointset = mPointSet::rb_module();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvContour", cvseq);
|
||||
rb_include_module(rb_klass, curve);
|
||||
rb_include_module(rb_klass, pointset);
|
||||
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
|
||||
VALUE approx_option = rb_hash_new();
|
||||
rb_define_const(rb_klass, "APPROX_OPTION", approx_option);
|
||||
rb_hash_aset(approx_option, ID2SYM(rb_intern("method")), INT2FIX(CV_POLY_APPROX_DP));
|
||||
rb_hash_aset(approx_option, ID2SYM(rb_intern("accuracy")), rb_float_new(1.0));
|
||||
rb_hash_aset(approx_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
||||
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
|
||||
rb_define_method(rb_klass, "color", RUBY_METHOD_FUNC(rb_color), 0);
|
||||
rb_define_method(rb_klass, "color=", RUBY_METHOD_FUNC(rb_set_color), 1);
|
||||
rb_define_method(rb_klass, "reserved", RUBY_METHOD_FUNC(rb_reserved), 0);
|
||||
rb_define_method(rb_klass, "approx_poly", RUBY_METHOD_FUNC(rb_approx_poly), -1);
|
||||
rb_define_alias(rb_klass, "approx", "approx_poly");
|
||||
rb_define_method(rb_klass, "bounding_rect", RUBY_METHOD_FUNC(rb_bounding_rect), 0);
|
||||
rb_define_method(rb_klass, "create_tree", RUBY_METHOD_FUNC(rb_create_tree), -1);
|
||||
rb_define_method(rb_klass, "in?", RUBY_METHOD_FUNC(rb_in_q), 1);
|
||||
rb_define_method(rb_klass, "measure_distance", RUBY_METHOD_FUNC(rb_measure_distance), 1);
|
||||
rb_define_method(rb_klass, "point_polygon_test", RUBY_METHOD_FUNC(rb_point_polygon_test), 2);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCONTOUR
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcontour.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCONTOUR_H
|
||||
#define RUBY_OPENCV_CVCONTOUR_H
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCONTOUR namespace cCvContour {
|
||||
#define __NAMESPACE_END_CVCONTOUR }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONTOUR
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rect(VALUE self);
|
||||
VALUE rb_color(VALUE self);
|
||||
VALUE rb_set_color(VALUE self, VALUE color);
|
||||
VALUE rb_reserved(VALUE self);
|
||||
VALUE rb_approx_poly(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_bounding_rect(VALUE self);
|
||||
VALUE rb_create_tree(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_in_q(VALUE self, VALUE point);
|
||||
VALUE rb_measure_distance(VALUE self, VALUE point);
|
||||
VALUE rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist);
|
||||
|
||||
VALUE new_object();
|
||||
__NAMESPACE_END_CVCONTOUR
|
||||
|
||||
inline CvContour*
|
||||
CVCONTOUR(VALUE object){
|
||||
CvContour *ptr;
|
||||
Data_Get_Struct(object, CvContour, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCONTOUR_H
|
|
@ -1,96 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcontourtree.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvcontour.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvContourTree
|
||||
*
|
||||
* Contour tree
|
||||
*
|
||||
* @see CvContour#create_tree
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONTOURTREE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the first point of the binary tree root segment
|
||||
* @overload p1
|
||||
* @return [CvPoint] First point of the binary tree root segment
|
||||
*/
|
||||
VALUE
|
||||
rb_p1(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p1, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the last point of the binary tree root segment
|
||||
* @overload p2
|
||||
* @return [CvPoint] Last point of the binary tree root segment
|
||||
*/
|
||||
VALUE
|
||||
rb_p2(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p2, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Restores the contour from its binary tree representation.
|
||||
*
|
||||
* The parameter +criteria+ determines the accuracy and/or the number of tree levels
|
||||
* used for reconstruction, so it is possible to build approximated contour.
|
||||
* @overload contour(criteria = 0)
|
||||
* @param criteria [Integer] Criteria, where to stop reconstruction
|
||||
* @return [CvContour] Contour tree
|
||||
* @opencv_func cvContourFromContourTree
|
||||
*/
|
||||
VALUE
|
||||
rb_contour(VALUE self, VALUE criteria)
|
||||
{
|
||||
VALUE storage = cCvMemStorage::new_object();
|
||||
CvSeq *contour = NULL;
|
||||
try {
|
||||
contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
|
||||
VALUE_TO_CVTERMCRITERIA(criteria));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
VALUE cvseq = rb_define_class_under(opencv, "CvSeq");
|
||||
#endif
|
||||
if (rb_klass)
|
||||
return;
|
||||
VALUE opencv = rb_module_opencv();
|
||||
VALUE cvseq = cCvSeq::rb_class();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvContourTree", cvseq);
|
||||
rb_define_method(rb_klass, "p1", RUBY_METHOD_FUNC(rb_p1), 0);
|
||||
rb_define_method(rb_klass, "p2", RUBY_METHOD_FUNC(rb_p2), 0);
|
||||
rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCONTOURTREE
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,41 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvcontourtree.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCONTOURTREE_H
|
||||
#define RUBY_OPENCV_CVCONTOURTREE_H
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCONTOURTREE namespace cCvContourTree {
|
||||
#define __NAMESPACE_END_CVCONTOURTREE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONTOURTREE
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_p1(VALUE self);
|
||||
VALUE rb_p2(VALUE self);
|
||||
VALUE rb_contour(VALUE self, VALUE criteria);
|
||||
|
||||
VALUE new_object();
|
||||
|
||||
__NAMESPACE_END_CVCONTOURTREE
|
||||
|
||||
inline CvContourTree*
|
||||
CVCONTOURTREE(VALUE object){
|
||||
CvContourTree *ptr;
|
||||
Data_Get_Struct(object, CvContourTree, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCONTOUR_H
|
|
@ -1,92 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvconvexitydefect.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvconvexitydefect.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvConvexityDefect
|
||||
*
|
||||
* Convexity defect
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONVEXITYDEFECT
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the point of the contour where the defect begins
|
||||
* @overload start
|
||||
* @return [CvPoint] Start point of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_start(VALUE self)
|
||||
{
|
||||
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->start);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the point of the contour where the defect ends
|
||||
* @overload end
|
||||
* @return [CvPoint] End point of the contour
|
||||
*/
|
||||
VALUE
|
||||
rb_end(VALUE self)
|
||||
{
|
||||
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->end);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the farthest from the convex hull point within the defect
|
||||
* @overload depth_point
|
||||
* @return [CvPoint] The farthest from the convex hull point within the defect
|
||||
*/
|
||||
VALUE
|
||||
rb_depth_point(VALUE self)
|
||||
{
|
||||
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->depth_point);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns distance between the farthest point and the convex hull
|
||||
* @overload depth
|
||||
* @return [Number] Distance between the farthest point and the convex hull
|
||||
*/
|
||||
VALUE
|
||||
rb_depth(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVCONVEXITYDEFECT(self)->depth);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvConvexityDefect", rb_cObject);
|
||||
rb_define_method(rb_klass, "start", RUBY_METHOD_FUNC(rb_start), 0);
|
||||
rb_define_method(rb_klass, "end", RUBY_METHOD_FUNC(rb_end), 0);
|
||||
rb_define_method(rb_klass, "depth_point", RUBY_METHOD_FUNC(rb_depth_point), 0);
|
||||
rb_define_method(rb_klass, "depth", RUBY_METHOD_FUNC(rb_depth), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVCONVEXITYDEFECT
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,42 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvconvexitydefect.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVCONVEXITYDEFECT_H
|
||||
#define RUBY_OPENCV_CVCONVEXITYDEFECT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVCONVEXITYDEFECT namespace cCvConvexityDefect {
|
||||
#define __NAMESPACE_END_CVCONVEXITYDEFECT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVCONVEXITYDEFECT
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_start(VALUE self);
|
||||
VALUE rb_end(VALUE self);
|
||||
VALUE rb_depth_point(VALUE self);
|
||||
VALUE rb_depth(VALUE self);
|
||||
|
||||
__NAMESPACE_END_CVCONVEXITYDEFECT
|
||||
|
||||
inline CvConvexityDefect*
|
||||
CVCONVEXITYDEFECT(VALUE object)
|
||||
{
|
||||
CvConvexityDefect *ptr;
|
||||
Data_Get_Struct(object, CvConvexityDefect, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVCONVEXITYDEFECT_H
|
|
@ -1,115 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cverror.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cverror.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvError
|
||||
*
|
||||
* OpenCV errors
|
||||
*/
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVERROR
|
||||
|
||||
st_table *cv_error = st_init_numtable();
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
void
|
||||
REGISTER_CVERROR(const char* object_name, int error_code)
|
||||
{
|
||||
st_insert(cv_error, (st_data_t)error_code,
|
||||
(st_data_t)rb_define_class_under(rb_module_opencv(), object_name, rb_klass));
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
by_code(int error_code)
|
||||
{
|
||||
VALUE klass = 0;
|
||||
st_lookup(cv_error, (st_data_t)error_code, (st_data_t*)&klass);
|
||||
return klass ? klass : rb_eStandardError;
|
||||
}
|
||||
|
||||
void
|
||||
raise(cv::Exception e)
|
||||
{
|
||||
rb_raise(by_code(e.code), "%s", e.what());
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvError", rb_eStandardError);
|
||||
REGISTER_CVERROR("CvStsBackTrace", CV_StsBackTrace);
|
||||
REGISTER_CVERROR("CvStsError", CV_StsError);
|
||||
REGISTER_CVERROR("CvStsInternal", CV_StsInternal);
|
||||
REGISTER_CVERROR("CvStsNoMem", CV_StsNoMem);
|
||||
REGISTER_CVERROR("CvStsBadArg", CV_StsBadArg);
|
||||
REGISTER_CVERROR("CvStsBadFunc", CV_StsBadFunc);
|
||||
REGISTER_CVERROR("CvStsNoConv", CV_StsNoConv);
|
||||
REGISTER_CVERROR("CvStsAutoTrace", CV_StsAutoTrace);
|
||||
REGISTER_CVERROR("CvHeaderIsNull", CV_HeaderIsNull);
|
||||
REGISTER_CVERROR("CvBadImageSize", CV_BadImageSize);
|
||||
REGISTER_CVERROR("CvBadOffset", CV_BadOffset);
|
||||
REGISTER_CVERROR("CvBadDataPtr", CV_BadDataPtr);
|
||||
REGISTER_CVERROR("CvBadStep", CV_BadStep);
|
||||
REGISTER_CVERROR("CvBadModelOrChSeq", CV_BadModelOrChSeq);
|
||||
REGISTER_CVERROR("CvBadNumChannels", CV_BadNumChannels);
|
||||
REGISTER_CVERROR("CvBadNumChannel1U", CV_BadNumChannel1U);
|
||||
REGISTER_CVERROR("CvBadDepth", CV_BadDepth);
|
||||
REGISTER_CVERROR("CvBadAlphaChannel", CV_BadAlphaChannel);
|
||||
REGISTER_CVERROR("CvBadOrder", CV_BadOrder);
|
||||
REGISTER_CVERROR("CvBadOrigin", CV_BadOrigin);
|
||||
REGISTER_CVERROR("CvBadAlign", CV_BadAlign);
|
||||
REGISTER_CVERROR("CvBadCallBack", CV_BadCallBack);
|
||||
REGISTER_CVERROR("CvBadTileSize", CV_BadTileSize);
|
||||
REGISTER_CVERROR("CvBadCOI", CV_BadCOI);
|
||||
REGISTER_CVERROR("CvBadROISize", CV_BadROISize);
|
||||
REGISTER_CVERROR("CvMaskIsTiled", CV_MaskIsTiled);
|
||||
REGISTER_CVERROR("CvStsNullPtr", CV_StsNullPtr);
|
||||
REGISTER_CVERROR("CvStsVecLengthErr", CV_StsVecLengthErr);
|
||||
REGISTER_CVERROR("CvStsFilterStructContentErr", CV_StsFilterStructContentErr);
|
||||
REGISTER_CVERROR("CvStsKernelStructContentErr", CV_StsKernelStructContentErr);
|
||||
REGISTER_CVERROR("CvStsFilterOffsetErr", CV_StsFilterOffsetErr);
|
||||
REGISTER_CVERROR("CvStsBadSize", CV_StsBadSize);
|
||||
REGISTER_CVERROR("CvStsDivByZero", CV_StsDivByZero);
|
||||
REGISTER_CVERROR("CvStsInplaceNotSupported", CV_StsInplaceNotSupported);
|
||||
REGISTER_CVERROR("CvStsObjectNotFound", CV_StsObjectNotFound);
|
||||
REGISTER_CVERROR("CvStsUnmatchedFormats", CV_StsUnmatchedFormats);
|
||||
REGISTER_CVERROR("CvStsBadFlag", CV_StsBadFlag);
|
||||
REGISTER_CVERROR("CvStsBadPoint", CV_StsBadPoint);
|
||||
REGISTER_CVERROR("CvStsBadMask", CV_StsBadMask);
|
||||
REGISTER_CVERROR("CvStsUnmatchedSizes", CV_StsUnmatchedSizes);
|
||||
REGISTER_CVERROR("CvStsUnsupportedFormat", CV_StsUnsupportedFormat);
|
||||
REGISTER_CVERROR("CvStsOutOfRange", CV_StsOutOfRange);
|
||||
REGISTER_CVERROR("CvStsParseError", CV_StsParseError);
|
||||
REGISTER_CVERROR("CvStsNotImplemented", CV_StsNotImplemented);
|
||||
REGISTER_CVERROR("CvStsBadMemBlock", CV_StsBadMemBlock);
|
||||
REGISTER_CVERROR("CvStsAssert", CV_StsAssert);
|
||||
REGISTER_CVERROR("CvGpuNotSupported", CV_GpuNotSupported);
|
||||
REGISTER_CVERROR("CvGpuApiCallError", CV_GpuApiCallError);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVERROR
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,28 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cverror.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVERROR_H
|
||||
#define RUBY_OPENCV_CVERROR_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVERROR namespace cCvError {
|
||||
#define __NAMESPACE_END_CVERROR }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVERROR
|
||||
|
||||
void init_ruby_class();
|
||||
VALUE by_code(int error_code);
|
||||
void raise(cv::Exception e);
|
||||
|
||||
__NAMESPACE_END_CVERROR
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVERROR_H
|
|
@ -1,123 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvfeaturetree.cpp -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#include "cvfeaturetree.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvFeatureTree
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVFEATURETREE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
void
|
||||
mark_feature_tree(void *ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
VALUE desc = ((CvFeatureTreeWrap*)ptr)->desc;
|
||||
rb_gc_mark(desc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_release_feature_tree(void *ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
CvFeatureTree* ft = ((CvFeatureTreeWrap*)ptr)->feature_tree;
|
||||
cvReleaseFeatureTree(ft);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvFeatureTreeWrap* ptr;
|
||||
return Data_Make_Struct(klass, CvFeatureTreeWrap, mark_feature_tree,
|
||||
rb_release_feature_tree, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new kd-tree
|
||||
* @overload new(desc)
|
||||
* @param desc [CvMat] Descriptors
|
||||
* @return [CvFeatureTree] self
|
||||
* @opencv_func cvCreateKDTree
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(VALUE self, VALUE desc)
|
||||
{
|
||||
CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
|
||||
CvFeatureTreeWrap* self_ptr = (CvFeatureTreeWrap*)DATA_PTR(self);
|
||||
free(self_ptr);
|
||||
self_ptr = ALLOC(CvFeatureTreeWrap);
|
||||
try {
|
||||
self_ptr->feature_tree = cvCreateKDTree(desc_mat);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
self_ptr->desc = desc;
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find features from kd-tree
|
||||
* @overload find_features(desc, k, emax)
|
||||
* @param desc [CvMat] m x d matrix of (row-)vectors to find the nearest neighbors of.
|
||||
* @param k [Integer] The number of neighbors to find.
|
||||
* @param emax [Integer] The maximum number of leaves to visit.
|
||||
* @return [Array] Array of [results, dist]
|
||||
* - results: m x k set of row indices of matching vectors (referring to matrix passed to cvCreateFeatureTree). Contains -1 in some columns if fewer than k neighbors found.
|
||||
* - dist: m x k matrix of distances to k nearest neighbors.
|
||||
* @opencv_func cvFindFeatures
|
||||
*/
|
||||
VALUE
|
||||
rb_find_features(VALUE self, VALUE desc, VALUE k, VALUE emax)
|
||||
{
|
||||
CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
|
||||
int _k = NUM2INT(k);
|
||||
VALUE results = cCvMat::new_object(desc_mat->rows, _k, CV_32SC1);
|
||||
VALUE dist = cCvMat::new_object(desc_mat->rows, _k, CV_64FC1);
|
||||
try {
|
||||
cvFindFeatures(CVFEATURETREE(self), desc_mat, CVMAT(results), CVMAT(dist), _k, NUM2INT(emax));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_assoc_new(results, dist);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvFeatureTree", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), 1);
|
||||
|
||||
rb_define_method(rb_klass, "find_features", RUBY_METHOD_FUNC(rb_find_features), 3);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
__NAMESPACE_END_CVFEATURETREE
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvfeaturetree.h -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVFEATURETREE_H
|
||||
#define RUBY_OPENCV_CVFEATURETREE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVFEATURETREE namespace cCvFeatureTree {
|
||||
#define __NAMESPACE_END_CVFEATURETREE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVFEATURETREE
|
||||
|
||||
VALUE rb_class();
|
||||
void init_ruby_class();
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(VALUE self, VALUE desc);
|
||||
VALUE rb_find_features(VALUE self, VALUE desc, VALUE k, VALUE emax);
|
||||
|
||||
__NAMESPACE_END_CVFEATURETREE
|
||||
|
||||
typedef struct _CvFeatureTreeWrap {
|
||||
CvFeatureTree* feature_tree;
|
||||
VALUE desc;
|
||||
} CvFeatureTreeWrap;
|
||||
|
||||
inline CvFeatureTree*
|
||||
CVFEATURETREE(VALUE object)
|
||||
{
|
||||
CvFeatureTreeWrap* ptr;
|
||||
Data_Get_Struct(object, CvFeatureTreeWrap, ptr);
|
||||
return ptr->feature_tree;
|
||||
}
|
||||
|
||||
inline CvFeatureTree*
|
||||
CVFEATURETREE_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvFeatureTree::rb_class()))
|
||||
raise_typeerror(object, cCvFeatureTree::rb_class());
|
||||
return CVFEATURETREE(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVFEATURETREE
|
||||
|
||||
|
||||
|
|
@ -1,228 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvfont.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvfont.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvFont
|
||||
*
|
||||
* Font structure that can be passed to text rendering functions.
|
||||
* see CvMat#put_text, CvMat#put_text!
|
||||
*/
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVFONT
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
int
|
||||
rb_font_option_line_type(VALUE font_option)
|
||||
{
|
||||
VALUE line_type = LOOKUP_HASH(font_option, "line_type");
|
||||
if (FIXNUM_P(line_type)) {
|
||||
return FIX2INT(line_type);
|
||||
}
|
||||
else if (line_type == ID2SYM(rb_intern("aa"))) {
|
||||
return CV_AA;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvFont *ptr;
|
||||
return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create font object
|
||||
* @overload new(face, font_option = nil)
|
||||
* @param face [Symbol] Font name identifier. Only a subset of Hershey fonts (http://sources.isc.org/utils/misc/hershey-font.txt) are supported now:
|
||||
* - :simplex - normal size sans-serif font
|
||||
* - :plain - small size sans-serif font
|
||||
* - :duplex - normal size sans-serif font (more complex than :simplex)
|
||||
* - :complex - normal size serif font
|
||||
* - :triplex - normal size serif font (more complex than :complex)
|
||||
* - :complex_small - smaller version of :complex
|
||||
* - :script_simplex - hand-writing style font
|
||||
* - :script_complex - more complex variant of :script_simplex
|
||||
*
|
||||
* @param font_option [Hash] should be Hash include these keys.
|
||||
* @option font_option [Number] :hscale Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type. If equal to 0.5, the characters are of half the original width.
|
||||
* @option font_option [Number] :vscale Vertical scale. If equal to 1.0, the characters have the original height depending on the font type. If equal to 0.5, the characters are of half the original height.
|
||||
* @option font_option [Number] :shear Approximate tangent of the character slope relative to the vertical line. Zero value means a non-italic font, 1.0f means ~45 degree slope, etc.
|
||||
* @option font_option [Number] :thickness Thickness of the text strokes.
|
||||
* @option font_option [Number] :line_type Type of the strokes, see CvMat#Line description.
|
||||
* @option font_option [Number] :italic If value is not nil or false that means italic or oblique font.
|
||||
*
|
||||
* @example Create Font
|
||||
* OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
|
||||
* # create 2x bigger than normal, italic type font.
|
||||
*
|
||||
* @opencv_func cvInitFont
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE face, font_option;
|
||||
rb_scan_args(argc, argv, "11", &face, &font_option);
|
||||
Check_Type(face, T_SYMBOL);
|
||||
face = rb_hash_lookup(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
|
||||
if (NIL_P(face)) {
|
||||
rb_raise(rb_eArgError, "undefined face.");
|
||||
}
|
||||
font_option = FONT_OPTION(font_option);
|
||||
|
||||
int font_face = NUM2INT(face);
|
||||
if (FO_ITALIC(font_option)) {
|
||||
font_face |= CV_FONT_ITALIC;
|
||||
}
|
||||
try {
|
||||
cvInitFont(CVFONT(self),
|
||||
font_face,
|
||||
FO_HSCALE(font_option),
|
||||
FO_VSCALE(font_option),
|
||||
FO_SHEAR(font_option),
|
||||
FO_THICKNESS(font_option),
|
||||
FO_LINE_TYPE(font_option));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns font face
|
||||
* @overload face
|
||||
* @return [Fixnum] Font face
|
||||
*/
|
||||
VALUE
|
||||
rb_face(VALUE self)
|
||||
{
|
||||
return INT2FIX(CVFONT(self)->font_face);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hscale
|
||||
* @overload hscale
|
||||
* @return [Number] hscale
|
||||
*/
|
||||
VALUE
|
||||
rb_hscale(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVFONT(self)->hscale);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns vscale
|
||||
* @overload vscale
|
||||
* @return [Number] vscale
|
||||
*/
|
||||
VALUE
|
||||
rb_vscale(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVFONT(self)->vscale);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns shear
|
||||
* @overload shear
|
||||
* @return [Number] shear
|
||||
*/
|
||||
VALUE
|
||||
rb_shear(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVFONT(self)->shear);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns thickness
|
||||
* @overload thickness
|
||||
* @return [Fixnum] thickness
|
||||
*/
|
||||
VALUE
|
||||
rb_thickness(VALUE self)
|
||||
{
|
||||
return INT2FIX(CVFONT(self)->thickness);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns line type
|
||||
* @overload line_type
|
||||
* @return [Fixnum] line_type
|
||||
*/
|
||||
VALUE
|
||||
rb_line_type(VALUE self)
|
||||
{
|
||||
return INT2FIX(CVFONT(self)->line_type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns italic or not
|
||||
* @overload italic
|
||||
* @return [Boolean] self is italic or not
|
||||
*/
|
||||
VALUE
|
||||
rb_italic(VALUE self)
|
||||
{
|
||||
return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
VALUE face = rb_hash_new();
|
||||
rb_define_const(rb_klass, "FACE", face);
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
|
||||
rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
|
||||
|
||||
VALUE default_option = rb_hash_new();
|
||||
rb_define_const(rb_klass, "FONT_OPTION", default_option);
|
||||
rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
|
||||
rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
|
||||
rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
|
||||
rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
|
||||
rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
|
||||
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);
|
||||
rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);
|
||||
rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);
|
||||
rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);
|
||||
rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);
|
||||
rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);
|
||||
rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVFONT
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,64 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvfont.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVFONT_H
|
||||
#define RUBY_OPENCV_CVFONT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVFONT namespace cCvFont {
|
||||
#define __NAMESPACE_END_CVFONT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVFONT
|
||||
|
||||
#define FONT_OPTION(op) rb_get_option_table(rb_klass, "FONT_OPTION", op)
|
||||
#define FO_ITALIC(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "italic"))
|
||||
#define FO_HSCALE(op) NUM2DBL(LOOKUP_HASH(op, "hscale"))
|
||||
#define FO_VSCALE(op) NUM2DBL(LOOKUP_HASH(op, "vscale"))
|
||||
#define FO_SHEAR(op) NUM2DBL(LOOKUP_HASH(op, "shear"))
|
||||
#define FO_THICKNESS(op) NUM2INT(LOOKUP_HASH(op, "thickness"))
|
||||
#define FO_LINE_TYPE(op) rb_font_option_line_type(op)
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_face(VALUE self);
|
||||
VALUE rb_hscale(VALUE self);
|
||||
VALUE rb_vscale(VALUE self);
|
||||
VALUE rb_shear(VALUE self);
|
||||
VALUE rb_thickness(VALUE self);
|
||||
VALUE rb_line_type(VALUE self);
|
||||
VALUE rb_italic(VALUE self);
|
||||
|
||||
__NAMESPACE_END_CVFONT
|
||||
|
||||
inline CvFont*
|
||||
CVFONT(VALUE object)
|
||||
{
|
||||
CvFont *ptr;
|
||||
Data_Get_Struct(object, CvFont, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvFont*
|
||||
CVFONT_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvFont::rb_class()))
|
||||
raise_typeerror(object, cCvFont::rb_class());
|
||||
return CVFONT(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVFONT_H
|
|
@ -1,148 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhaarclassifercascade.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvhaarclassifiercascade.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvHaarClassifierCascade
|
||||
*
|
||||
* Haar Feature-based Cascade Classifier for Object Detection
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
return OPENCV_OBJECT(klass, 0);
|
||||
}
|
||||
|
||||
void
|
||||
cvhaarclassifiercascade_free(void* ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)ptr;
|
||||
cvReleaseHaarClassifierCascade(&cascade);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Load trained cascade of haar classifers from file.
|
||||
*
|
||||
* @overload load(filename)
|
||||
* @param filename [String] Haar classifer file name
|
||||
* @return [CvHaarClassifierCascade] Object detector
|
||||
* @scope class
|
||||
* @opencv_func cvLoad
|
||||
*/
|
||||
VALUE
|
||||
rb_load(VALUE klass, VALUE path)
|
||||
{
|
||||
CvHaarClassifierCascade *cascade = NULL;
|
||||
try {
|
||||
cascade = (CvHaarClassifierCascade*)cvLoad(StringValueCStr(path), 0, 0, 0);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
if (!CV_IS_HAAR_CLASSIFIER(cascade))
|
||||
rb_raise(rb_eArgError, "invalid format haar classifier cascade file.");
|
||||
return Data_Wrap_Struct(klass, 0, cvhaarclassifiercascade_free, cascade);
|
||||
}
|
||||
|
||||
/*
|
||||
* Detects objects of different sizes in the input image.
|
||||
*
|
||||
* @overload detect_objects(image, options = nil)
|
||||
* @param image [CvMat,IplImage] Matrix of the type CV_8U containing an image where objects are detected.
|
||||
* @param options [Hash] Options
|
||||
* @option options [Number] :scale_factor
|
||||
* Parameter specifying how much the image size is reduced at each image scale.
|
||||
* @option options [Number] :storage
|
||||
* Memory storage to store the resultant sequence of the object candidate rectangles
|
||||
* @option options [Number] :min_neighbors
|
||||
* Parameter specifying how many neighbors each candidate rectangle should have to retain it.
|
||||
* @option options [CvSize] :min_size
|
||||
* Minimum possible object size. Objects smaller than that are ignored.
|
||||
* @option options [CvSize] :max_size
|
||||
* Maximum possible object size. Objects larger than that are ignored.
|
||||
* @return [CvSeq<CvAvgComp>] Detected objects as a list of rectangles
|
||||
* @opencv_func cvHaarDetectObjects
|
||||
*/
|
||||
VALUE
|
||||
rb_detect_objects(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE image, options;
|
||||
rb_scan_args(argc, argv, "11", &image, &options);
|
||||
|
||||
double scale_factor;
|
||||
int flags, min_neighbors;
|
||||
CvSize min_size, max_size;
|
||||
VALUE storage_val;
|
||||
if (NIL_P(options)) {
|
||||
scale_factor = 1.1;
|
||||
flags = 0;
|
||||
min_neighbors = 3;
|
||||
min_size = max_size = cvSize(0, 0);
|
||||
storage_val = cCvMemStorage::new_object();
|
||||
}
|
||||
else {
|
||||
scale_factor = IF_DBL(LOOKUP_HASH(options, "scale_factor"), 1.1);
|
||||
flags = IF_INT(LOOKUP_HASH(options, "flags"), 0);
|
||||
min_neighbors = IF_INT(LOOKUP_HASH(options, "min_neighbors"), 3);
|
||||
VALUE min_size_val = LOOKUP_HASH(options, "min_size");
|
||||
min_size = NIL_P(min_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(min_size_val);
|
||||
VALUE max_size_val = LOOKUP_HASH(options, "max_size");
|
||||
max_size = NIL_P(max_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(max_size_val);
|
||||
storage_val = CHECK_CVMEMSTORAGE(LOOKUP_HASH(options, "storage"));
|
||||
}
|
||||
|
||||
VALUE result = Qnil;
|
||||
try {
|
||||
CvSeq *seq = cvHaarDetectObjects(CVARR_WITH_CHECK(image), CVHAARCLASSIFIERCASCADE(self), CVMEMSTORAGE(storage_val),
|
||||
scale_factor, min_neighbors, flags, min_size, max_size);
|
||||
result = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvAvgComp::rb_class(), storage_val);
|
||||
if (rb_block_given_p()) {
|
||||
for(int i = 0; i < seq->total; ++i)
|
||||
rb_yield(REFER_OBJECT(cCvAvgComp::rb_class(), cvGetSeqElem(seq, i), storage_val));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvHaarClassifierCascade", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
|
||||
rb_define_method(rb_klass, "detect_objects", RUBY_METHOD_FUNC(rb_detect_objects), -1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVHAARCLASSIFERCASCADE
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,39 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhaarclassifiercascade.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
||||
#define RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade {
|
||||
#define __NAMESPACE_END_CVHAARCLASSIFERCASCADE }
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
|
||||
VALUE rb_load(VALUE klass, VALUE path);
|
||||
VALUE rb_detect_objects(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
__NAMESPACE_END_CVHAARCLASSIFERCASCADE
|
||||
inline CvHaarClassifierCascade*
|
||||
CVHAARCLASSIFIERCASCADE(VALUE object) {
|
||||
CvHaarClassifierCascade *ptr;
|
||||
Data_Get_Struct(object, CvHaarClassifierCascade, ptr);
|
||||
return ptr;
|
||||
}
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
|
@ -1,717 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhistogram.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2008 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvhistogram.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvHistogram
|
||||
*
|
||||
* Multi-dimensional histogram.
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHISTOGRAM
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
void
|
||||
release_hist(void* ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
try {
|
||||
cvReleaseHist((CvHistogram**)&ptr);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvHistogram* ptr = NULL;
|
||||
return Data_Wrap_Struct(klass, 0, release_hist, ptr);
|
||||
}
|
||||
|
||||
float*
|
||||
ary2fltptr(VALUE ary, float* buff)
|
||||
{
|
||||
Check_Type(ary, T_ARRAY);
|
||||
int size = RARRAY_LEN(ary);
|
||||
VALUE* ary_ptr = RARRAY_PTR(ary);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
buff[i] = NUM2DBL(ary_ptr[i]);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
int*
|
||||
ary2intptr(VALUE ary, int* buff)
|
||||
{
|
||||
Check_Type(ary, T_ARRAY);
|
||||
int size = RARRAY_LEN(ary);
|
||||
VALUE* ary_ptr = RARRAY_PTR(ary);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
buff[i] = NUM2INT(ary_ptr[i]);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a histogram
|
||||
* @overload new(dims, sizes, type, ranges=nil, uniform=true)
|
||||
* @param dims [Integer] Number of histogram dimensions
|
||||
* @param sizes [Array<Integer>] Array of the histogram dimension sizes
|
||||
* @param type [Integer]
|
||||
* Histogram representation format. CV_HIST_ARRAY means that the histogram data is represented
|
||||
* as a multi-dimensional dense array CvMatND. CV_HIST_SPARSE means that histogram data is
|
||||
* represented as a multi-dimensional sparse array CvSparseMat.
|
||||
* @param ranges [Array<Integer>]
|
||||
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
||||
* The ranges are used when the histogram is calculated or backprojected to determine which
|
||||
* histogram bin corresponds to which value/tuple of values from the input image(s).
|
||||
* @param uniform [Boolean] Uniformity flag.
|
||||
* @return [CvHistogram] Histogram
|
||||
* @opencv_func cvCreateHist
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE _dims, _sizes, _type, _ranges, _uniform;
|
||||
int uniform;
|
||||
int* sizes;
|
||||
float** ranges = NULL;
|
||||
|
||||
rb_scan_args(argc, argv, "32", &_dims, &_sizes, &_type, &_ranges, &_uniform);
|
||||
int sizes_len = RARRAY_LEN(_sizes);
|
||||
sizes = ALLOCA_N(int, sizes_len);
|
||||
|
||||
if (NIL_P(_ranges)) {
|
||||
sizes = ary2intptr(_sizes, sizes);
|
||||
ranges = NULL;
|
||||
}
|
||||
else {
|
||||
ranges = ALLOCA_N(float*, sizes_len);
|
||||
VALUE* range_ptr = RARRAY_PTR(_ranges);
|
||||
int i;
|
||||
for (i = 0; i < sizes_len; i++) {
|
||||
sizes[i] = NUM2INT(RARRAY_PTR(_sizes)[i]);
|
||||
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
|
||||
}
|
||||
}
|
||||
uniform = TRUE_OR_FALSE(_uniform, 1);
|
||||
|
||||
try {
|
||||
DATA_PTR(self) = cvCreateHist(NUM2INT(_dims), sizes, NUM2INT(_type), ranges, uniform);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns <tt>self</tt> is uniform histogram or not
|
||||
* @overload is_uniform?
|
||||
* @return [Boolean] Uniform or not
|
||||
* @opencv_func CV_IS_UNIFORM_HIST
|
||||
*/
|
||||
VALUE
|
||||
rb_is_uniform(VALUE self)
|
||||
{
|
||||
return CV_IS_UNIFORM_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns <tt>self</tt> is sparse histogram or not
|
||||
* @overload is_sparse?
|
||||
* @return [Boolean] Sparse or not
|
||||
* @opencv_func CV_IS_SPARSE_HIST
|
||||
*/
|
||||
VALUE
|
||||
rb_is_sparse(VALUE self)
|
||||
{
|
||||
return CV_IS_SPARSE_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns <tt>self</tt> has range or not
|
||||
* @overload has_range?
|
||||
* @return [Boolean] Has range or not
|
||||
* @opencv_func CV_HIST_HAS_RANGES
|
||||
*/
|
||||
VALUE
|
||||
rb_has_range(VALUE self)
|
||||
{
|
||||
return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates a histogram of a set of arrays.
|
||||
* @overload calc_hist(images, accumulate=nil, mask=nil)
|
||||
* @param images [Array<IplImage>]
|
||||
* Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
|
||||
* Each of them can have an arbitrary number of channels.
|
||||
* @param accumulate [Boolean]
|
||||
* Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated.
|
||||
* This feature enables you to compute a single histogram from several sets of arrays,
|
||||
* or to update the histogram in time.
|
||||
* @param mask [CvMat]
|
||||
* Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i].
|
||||
* The non-zero mask elements mark the array elements counted in the histogram.
|
||||
* @return [CvHistogram] Histogram of a set of arrays
|
||||
* @opencv_func cvCalcHist
|
||||
*/
|
||||
VALUE
|
||||
rb_calc_hist(int argc, VALUE* argv, VALUE self)
|
||||
{
|
||||
return rb_calc_hist_bang(argc, argv, rb_copy_hist(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates a histogram of a set of arrays.
|
||||
* @overload calc_hist!(images, accumulate=nil, mask=nil)
|
||||
* @see #calc_hist
|
||||
* @opencv_func cvCalcHist
|
||||
*/
|
||||
VALUE
|
||||
rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
|
||||
{
|
||||
VALUE images, accumulate, mask;
|
||||
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
|
||||
Check_Type(images, T_ARRAY);
|
||||
int num_images = RARRAY_LEN(images);
|
||||
if (num_images == 0) {
|
||||
rb_raise(rb_eArgError, "One or more arrays are required.");
|
||||
}
|
||||
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
||||
VALUE* images_ptr = RARRAY_PTR(images);
|
||||
for (int i = 0; i < num_images; i++) {
|
||||
img[i] = IPLIMAGE_WITH_CHECK(images_ptr[i]);
|
||||
}
|
||||
CvMat* m = NIL_P(mask) ? NULL : CVMAT_WITH_CHECK(mask);
|
||||
try {
|
||||
cvCalcHist(img, CVHISTOGRAM(self), TRUE_OR_FALSE(accumulate, 0), m);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Queries the value of the histogram bin.
|
||||
* @overload [](idx0)
|
||||
* @overload [](idx0, idx1)
|
||||
* @overload [](idx0, idx1, idx2)
|
||||
* @overload [](idx0, idx1, idx2, idx3, ...)
|
||||
* @param idx* [Integer] *-th index
|
||||
* @return [Number] The value of the specified bin of the 1D, 2D, 3D, or N-D histogram.
|
||||
* @opencv_func cvQueryHistValue_1D
|
||||
* @opencv_func cvQueryHistValue_2D
|
||||
* @opencv_func cvQueryHistValue_3D
|
||||
* @opencv_func cvQueryHistValue_nD
|
||||
*/
|
||||
VALUE
|
||||
rb_aref(VALUE self, VALUE args)
|
||||
{
|
||||
int num_idx = RARRAY_LEN(args);
|
||||
int* idx = ALLOCA_N(int, num_idx);
|
||||
VALUE* args_ptr = RARRAY_PTR(args);
|
||||
for (int i = 0; i < num_idx; i++) {
|
||||
idx[i] = NUM2INT(args_ptr[i]);
|
||||
}
|
||||
|
||||
float value = 0.0;
|
||||
CvHistogram* self_ptr = CVHISTOGRAM(self);
|
||||
try {
|
||||
switch (num_idx) {
|
||||
case 1:
|
||||
value = cvQueryHistValue_1D(self_ptr, idx[0]);
|
||||
break;
|
||||
case 2:
|
||||
value = cvQueryHistValue_2D(self_ptr, idx[0], idx[1]);
|
||||
break;
|
||||
case 3:
|
||||
value = cvQueryHistValue_3D(self_ptr, idx[0], idx[1], idx[2]);
|
||||
break;
|
||||
default:
|
||||
value = cvQueryHistValue_nD(self_ptr, idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return rb_float_new((double)value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds the minimum and maximum histogram bins.
|
||||
* @overload min_max_value
|
||||
* @return [Array]
|
||||
* [min_value, max_value, min_idx, max_idx]: Array of the minimum / maximum value of the histogram
|
||||
* and their coordinates.
|
||||
* - min_value: The minimum value of the histogram.
|
||||
* - max_value: The maximum value of the histogram.
|
||||
* - min_idx: The array of coordinates for the minimum.
|
||||
* - max_idx: The array of coordinates for the maximum.
|
||||
* @opencv_func cvGetMinMaxHistValue
|
||||
*/
|
||||
VALUE
|
||||
rb_min_max_value(VALUE self)
|
||||
{
|
||||
CvHistogram* self_ptr = CVHISTOGRAM(self);
|
||||
int dims = 0;
|
||||
float min_value = 0.0, max_value = 0.0;
|
||||
int *min_idx = NULL;
|
||||
int *max_idx = NULL;
|
||||
try {
|
||||
dims = cvGetDims(self_ptr->bins, NULL);
|
||||
min_idx = ALLOCA_N(int, dims);
|
||||
max_idx = ALLOCA_N(int, dims);
|
||||
cvGetMinMaxHistValue(CVHISTOGRAM(self), &min_value, &max_value, min_idx, max_idx);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
VALUE _min_idx = rb_ary_new2(dims);
|
||||
VALUE _max_idx = rb_ary_new2(dims);
|
||||
for (int i = 0; i < dims; i++) {
|
||||
rb_ary_store(_min_idx, i, INT2NUM(min_idx[i]));
|
||||
rb_ary_store(_max_idx, i, INT2NUM(max_idx[i]));
|
||||
}
|
||||
|
||||
return rb_ary_new3(4, rb_float_new((double)min_value), rb_float_new((double)max_value),
|
||||
_min_idx, _max_idx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns number of array dimensions
|
||||
* @overload [](idx0, idx1, ...)
|
||||
* @param idx* [Integer] *-th index
|
||||
* @return [Array<Integer, Array<Integer>>]
|
||||
* [dims, sizes]: Number of array dimensions and its sizes.
|
||||
* - dims (Integer): Number of array dimensions
|
||||
* - sizes (Array<Integer>): Vector of the array dimension sizes.
|
||||
* For 2D arrays the number of rows (height) goes first,
|
||||
* number of columns (width) next.
|
||||
* @opencv_func cvGetDims
|
||||
*/
|
||||
VALUE
|
||||
rb_dims(VALUE self)
|
||||
{
|
||||
VALUE _sizes = Qnil;
|
||||
int size[CV_MAX_DIM];
|
||||
int dims = 0;
|
||||
try {
|
||||
dims = cvGetDims(CVHISTOGRAM(self)->bins, size);
|
||||
_sizes = rb_ary_new2(dims);
|
||||
for (int i = 0; i < dims; ++i) {
|
||||
rb_ary_store(_sizes, i, INT2NUM(size[i]));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_assoc_new(INT2NUM(dims), _sizes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clones histogram
|
||||
* @overload copy_hist
|
||||
* @return [CvHistogram] Copy of the histogram
|
||||
* @opencv_func cvCopyHist
|
||||
*/
|
||||
VALUE
|
||||
rb_copy_hist(VALUE self)
|
||||
{
|
||||
CvHistogram* hist = NULL;
|
||||
try {
|
||||
cvCopyHist(CVHISTOGRAM(self), &hist);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return Data_Wrap_Struct(rb_klass, 0, release_hist, hist);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets all histogram bins to 0 in case of dense histogram
|
||||
* and removes all histogram bins in case of sparse array.
|
||||
* @overload clear_hist
|
||||
* @return [CvHistogram] Cleared histogram
|
||||
* @opencv_func cvClearHist
|
||||
*/
|
||||
VALUE
|
||||
rb_clear_hist(VALUE self)
|
||||
{
|
||||
return rb_clear_hist_bang(rb_copy_hist(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets all histogram bins to 0 in case of dense histogram
|
||||
* and removes all histogram bins in case of sparse array.
|
||||
* This method changes <tt>self</tt>.
|
||||
* @overload clear_hist!
|
||||
* @see #clear_hist
|
||||
* @return [CvHistogram] Cleared histogram
|
||||
* @opencv_func cvClearHist
|
||||
*/
|
||||
VALUE
|
||||
rb_clear_hist_bang(VALUE self)
|
||||
{
|
||||
try {
|
||||
cvClearHist(CVHISTOGRAM(self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns normalized the histogram bins by scaling them,
|
||||
* such that the sum of the bins becomes equal to <tt>factor</tt>.
|
||||
* @overload normalize(factor)
|
||||
* @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
|
||||
* @return [CvHistogram] Normalized histogram
|
||||
* @opencv_func cvNormalizeHist
|
||||
*/
|
||||
VALUE
|
||||
rb_normalize_hist(VALUE self, VALUE factor)
|
||||
{
|
||||
return rb_normalize_hist_bang(rb_copy_hist(self), factor);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns normalized the histogram bins by scaling them,
|
||||
* such that the sum of the bins becomes equal to <tt>factor</tt>.
|
||||
* This method changes <tt>self</tt>.
|
||||
* @overload normalize!(factor)
|
||||
* @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
|
||||
* @return [CvHistogram] Normalized histogram
|
||||
* @see #normalize
|
||||
* @opencv_func cvNormalizeHist
|
||||
*/
|
||||
VALUE
|
||||
rb_normalize_hist_bang(VALUE self, VALUE factor)
|
||||
{
|
||||
try {
|
||||
cvNormalizeHist(CVHISTOGRAM(self), NUM2DBL(factor));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns cleared histogram bins that are below the specified threshold.
|
||||
* @overload thresh_hist(threshold)
|
||||
* @param threshold [Number] Threshold value
|
||||
* @return [CvHistogram] Cleared histogram
|
||||
* @opencv_func cvThreshHist
|
||||
*/
|
||||
VALUE
|
||||
rb_thresh_hist(VALUE self, VALUE threshold)
|
||||
{
|
||||
return rb_thresh_hist_bang(rb_copy_hist(self), threshold);
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleares histogram bins that are below the specified threshold.
|
||||
* This method changes <tt>self</tt>.
|
||||
* @overload thresh_hist!(threshold)
|
||||
* @param threshold [Number] Threshold value
|
||||
* @return [CvHistogram] Cleared histogram
|
||||
* @see #thresh_hist
|
||||
* @opencv_func cvThreshHist
|
||||
*/
|
||||
VALUE
|
||||
rb_thresh_hist_bang(VALUE self, VALUE threshold)
|
||||
{
|
||||
try {
|
||||
cvThreshHist(CVHISTOGRAM(self), NUM2DBL(threshold));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the bounds of the histogram bins.
|
||||
* @overload set_hist_bin_ranges(ranges, uniform=true)
|
||||
* @param ranges [Array<Number>]
|
||||
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
||||
* The ranges are used when the histogram is calculated or backprojected to determine
|
||||
* which histogram bin corresponds to which value/tuple of values from the input image(s).
|
||||
* @param uniform [Boolean]
|
||||
* Uniformity flag.
|
||||
* @return [CvHistogram]
|
||||
* Histogram
|
||||
* @opencv_func cvSetHistBinRanges
|
||||
*/
|
||||
VALUE
|
||||
rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self)
|
||||
{
|
||||
return rb_set_hist_bin_ranges_bang(argc, argv, rb_copy_hist(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the bounds of the histogram bins. This method changes <tt>self</tt>.
|
||||
* @overload set_hist_bin_ranges!(ranges, uniform=true)
|
||||
* @param ranges [Array<Number>]
|
||||
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
||||
* The ranges are used when the histogram is calculated or backprojected to determine
|
||||
* which histogram bin corresponds to which value/tuple of values from the input image(s).
|
||||
* @param uniform [Boolean]
|
||||
* Uniformity flag.
|
||||
* @return [CvHistogram]
|
||||
* Histogram
|
||||
* @see #set_hist_bin_ranges
|
||||
* @opencv_func cvSetHistBinRanges
|
||||
*/
|
||||
VALUE
|
||||
rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
|
||||
{
|
||||
VALUE _ranges, _uniform;
|
||||
rb_scan_args(argc, argv, "11", &_ranges, &_uniform);
|
||||
Check_Type(_ranges, T_ARRAY);
|
||||
|
||||
int ranges_size = RARRAY_LEN(_ranges);
|
||||
float** ranges = ALLOCA_N(float*, ranges_size);
|
||||
VALUE* range_ptr = RARRAY_PTR(_ranges);
|
||||
for (int i = 0; i < ranges_size; ++i) {
|
||||
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
|
||||
}
|
||||
int uniform = TRUE_OR_FALSE(_uniform, 1);
|
||||
|
||||
try {
|
||||
cvSetHistBinRanges(CVHISTOGRAM(self), ranges, uniform);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates the back projection of a histogram.
|
||||
* @overload calc_back_project(images)
|
||||
* @param images [Array<IplImage>]
|
||||
* Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
|
||||
* Each of them can have an arbitrary number of channels.
|
||||
* @return [CvMat,IplImage]
|
||||
* Destination back projection array that is a single-channel array of the same size and depth
|
||||
* as the first element of <tt>images</tt>
|
||||
* @opencv_func cvCalcBackProject
|
||||
*/
|
||||
VALUE
|
||||
rb_calc_back_project(VALUE self, VALUE image)
|
||||
{
|
||||
Check_Type(image, T_ARRAY);
|
||||
int num_images = RARRAY_LEN(image);
|
||||
if (num_images == 0) {
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
||||
VALUE* image_ptr = RARRAY_PTR(image);
|
||||
for (int i = 0; i < num_images; ++i) {
|
||||
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
|
||||
}
|
||||
|
||||
CvSize size;
|
||||
size.width = img[0]->width;
|
||||
size.height = img[0]->height;
|
||||
VALUE back_project = cCvMat::new_mat_kind_object(size, image_ptr[0]);
|
||||
try {
|
||||
cvCalcBackProject(img, CVARR(back_project), CVHISTOGRAM(self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return back_project;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locates a template within an image by using a histogram comparison.
|
||||
* @overload calc_back_project_patch(images, patch_size, method, factor)
|
||||
* @param images [Array<IplImage>] Source arrays.
|
||||
* @param pach_size [CvSize] Size of the patch slid though the source image.
|
||||
* @param method [Integer]
|
||||
* Comparison method that could be one of the following:
|
||||
* - <tt>CV_COMP_CORREL</tt>: Correlation
|
||||
* - <tt>CV_COMP_CHISQR</tt>: Chi-Square
|
||||
* - <tt>CV_COMP_INTERSECT</tt>: Intersection
|
||||
* - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
|
||||
* - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
|
||||
* @param factor [Number]
|
||||
* Normalization factor for histograms that affects the normalization scale
|
||||
* of the destination image. Pass 1 if not sure.
|
||||
* @return [CvMat,IplImage] Destination image.
|
||||
* @opencv_func cvCalcBackProject
|
||||
*/
|
||||
VALUE
|
||||
rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor)
|
||||
{
|
||||
Check_Type(image, T_ARRAY);
|
||||
int num_images = RARRAY_LEN(image);
|
||||
if (num_images == 0) {
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
||||
VALUE* image_ptr = RARRAY_PTR(image);
|
||||
for (int i = 0; i < num_images; ++i) {
|
||||
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
|
||||
}
|
||||
|
||||
CvSize patchsize = VALUE_TO_CVSIZE(patch_size);
|
||||
CvSize dst_size;
|
||||
dst_size.width = img[0]->width - patchsize.width + 1;
|
||||
dst_size.height = img[0]->height - patchsize.height + 1;
|
||||
|
||||
VALUE dst = cCvMat::new_mat_kind_object(dst_size, image_ptr[0], CV_32F, 1);
|
||||
try {
|
||||
cvCalcBackProjectPatch(img, CVARR(dst), patchsize, CVHISTOGRAM(self),
|
||||
NUM2INT(method), NUM2DBL(factor));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares two histograms.
|
||||
* @overload compare_hist(hist1, hist2, method)
|
||||
* @param hist1 [CvHistogram] First compared histogram.
|
||||
* @param hist2 [CvHistogram] Second compared histogram of the same size as <tt>hist1</tt>.
|
||||
* @param method [Integer]
|
||||
* Comparison method that could be one of the following:
|
||||
* - <tt>CV_COMP_CORREL</tt>: Correlation
|
||||
* - <tt>CV_COMP_CHISQR</tt>: Chi-Square
|
||||
* - <tt>CV_COMP_INTERSECT</tt>: Intersection
|
||||
* - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
|
||||
* - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
|
||||
* @return [Number] Distance of the two histograms.
|
||||
* @scope class
|
||||
* @opencv_func cvCompareHist
|
||||
*/
|
||||
VALUE
|
||||
rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvCompareHist(CVHISTOGRAM_WITH_CHECK(hist1), CVHISTOGRAM_WITH_CHECK(hist2),
|
||||
NUM2INT(method));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Divides one histogram by another.
|
||||
* @overload calc_prob_density(hist1, hist2, scale=255)
|
||||
* @param hist1 [CvHistogram] First histogram (the divisor).
|
||||
* @param hist2 [CvHistogram] Second histogram.
|
||||
* @param scale [Number] Scale factor for the destination histogram.
|
||||
* @return [CvHistogram] Destination histogram.
|
||||
* @opencv_func cvCalcProbDensity
|
||||
*/
|
||||
VALUE
|
||||
rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
|
||||
{
|
||||
VALUE hist1, hist2, scale;
|
||||
rb_scan_args(argc, argv, "21", &hist1, &hist2, &scale);
|
||||
double s = NIL_P(scale) ? 255 : NUM2DBL(scale);
|
||||
|
||||
CvHistogram* hist1_ptr = CVHISTOGRAM_WITH_CHECK(hist1);
|
||||
VALUE dst_hist = rb_allocate(rb_klass);
|
||||
try {
|
||||
cvCopyHist(hist1_ptr, (CvHistogram**)&(DATA_PTR(dst_hist)));
|
||||
cvCalcProbDensity(hist1_ptr, CVHISTOGRAM_WITH_CHECK(hist2), CVHISTOGRAM(dst_hist), s);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return dst_hist;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
|
||||
rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
|
||||
rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
|
||||
rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
|
||||
rb_define_method(rb_klass, "calc_hist", RUBY_METHOD_FUNC(rb_calc_hist), -1);
|
||||
rb_define_method(rb_klass, "calc_hist!", RUBY_METHOD_FUNC(rb_calc_hist_bang), -1);
|
||||
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), -2);
|
||||
rb_define_alias(rb_klass, "query_hist_value", "[]");
|
||||
rb_define_method(rb_klass, "min_max_value", RUBY_METHOD_FUNC(rb_min_max_value), 0);
|
||||
rb_define_method(rb_klass, "copy_hist", RUBY_METHOD_FUNC(rb_copy_hist), 0);
|
||||
|
||||
rb_define_method(rb_klass, "clear_hist", RUBY_METHOD_FUNC(rb_clear_hist), 0);
|
||||
rb_define_alias(rb_klass, "clear", "clear_hist");
|
||||
rb_define_method(rb_klass, "clear_hist!", RUBY_METHOD_FUNC(rb_clear_hist_bang), 0);
|
||||
rb_define_alias(rb_klass, "clear!", "clear_hist!");
|
||||
|
||||
rb_define_method(rb_klass, "normalize_hist", RUBY_METHOD_FUNC(rb_normalize_hist), 1);
|
||||
rb_define_alias(rb_klass, "normalize", "normalize_hist");
|
||||
rb_define_method(rb_klass, "normalize_hist!", RUBY_METHOD_FUNC(rb_normalize_hist_bang), 1);
|
||||
rb_define_alias(rb_klass, "normalize!", "normalize_hist!");
|
||||
|
||||
rb_define_method(rb_klass, "thresh_hist", RUBY_METHOD_FUNC(rb_thresh_hist), 1);
|
||||
rb_define_alias(rb_klass, "thresh", "thresh_hist");
|
||||
rb_define_method(rb_klass, "thresh_hist!", RUBY_METHOD_FUNC(rb_thresh_hist_bang), 1);
|
||||
rb_define_alias(rb_klass, "thresh!", "thresh_hist!");
|
||||
|
||||
rb_define_method(rb_klass, "set_hist_bin_ranges", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges), -1);
|
||||
rb_define_method(rb_klass, "set_hist_bin_ranges!", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges_bang), -1);
|
||||
|
||||
rb_define_method(rb_klass, "calc_back_project", RUBY_METHOD_FUNC(rb_calc_back_project), 1);
|
||||
rb_define_method(rb_klass, "calc_back_project_patch", RUBY_METHOD_FUNC(rb_calc_back_project_patch), 4);
|
||||
|
||||
rb_define_singleton_method(rb_klass, "calc_prob_density", RUBY_METHOD_FUNC(rb_calc_prob_density), -1);
|
||||
rb_define_singleton_method(rb_klass, "compare_hist", RUBY_METHOD_FUNC(rb_compare_hist), 3);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVHISTOGRAM
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,73 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhistogram.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2008 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVHISTOGRAM_H
|
||||
#define RUBY_OPENCV_CVHISTOGRAM_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVHISTOGRAM namespace cCvHistogram {
|
||||
#define __NAMESPACE_END_CVHISTOGRAM }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHISTOGRAM
|
||||
|
||||
VALUE rb_class();
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_is_uniform(VALUE self);
|
||||
VALUE rb_is_sparse(VALUE self);
|
||||
VALUE rb_has_range(VALUE self);
|
||||
VALUE rb_calc_hist(int argc, VALUE* argv, VALUE self);
|
||||
VALUE rb_calc_hist_bang(int argc, VALUE* argv, VALUE self);
|
||||
VALUE rb_aref(VALUE self, VALUE args);
|
||||
VALUE rb_min_max_value(VALUE self);
|
||||
VALUE rb_dims(VALUE self);
|
||||
VALUE rb_copy_hist(VALUE self);
|
||||
|
||||
VALUE rb_clear_hist(VALUE self);
|
||||
VALUE rb_clear_hist_bang(VALUE self);
|
||||
|
||||
VALUE rb_normalize_hist(VALUE self, VALUE factor);
|
||||
VALUE rb_normalize_hist_bang(VALUE self, VALUE factor);
|
||||
VALUE rb_thresh_hist(VALUE self, VALUE threshold);
|
||||
VALUE rb_thresh_hist_bang(VALUE self, VALUE threshold);
|
||||
|
||||
VALUE rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self);
|
||||
VALUE rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self);
|
||||
|
||||
VALUE rb_calc_back_project(VALUE self, VALUE image);
|
||||
VALUE rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor);
|
||||
|
||||
VALUE rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method);
|
||||
VALUE rb_calc_prob_density(int argc, VALUE* argv, VALUE self);
|
||||
|
||||
__NAMESPACE_END_CVHISTOGRAM
|
||||
|
||||
inline CvHistogram*
|
||||
CVHISTOGRAM(VALUE object)
|
||||
{
|
||||
CvHistogram* ptr;
|
||||
Data_Get_Struct(object, CvHistogram, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvHistogram*
|
||||
CVHISTOGRAM_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvHistogram::rb_class()))
|
||||
raise_typeerror(object, cCvHistogram::rb_class());
|
||||
return CVHISTOGRAM(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVHISTOGRAM_H
|
|
@ -1,178 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhumoments.cpp -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#include "cvhumoments.h"
|
||||
|
||||
/*
|
||||
* Document-class: OpenCV::CvHuMoments
|
||||
*
|
||||
* Hu invariants
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHUMOMENTS
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvHuMoments *ptr;
|
||||
return Data_Make_Struct(klass, CvHuMoments, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates the seven Hu invariants
|
||||
* @overload new(src_moments)
|
||||
* @param src_moments [CvMoment] Input moments
|
||||
* @return [CvHuMoments] Output Hu invariants
|
||||
* @opencv_func cvGetHuMoments
|
||||
* @see http://en.wikipedia.org/wiki/Image_moment#Rotation_invariant_moments
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(VALUE self, VALUE src_moments)
|
||||
{
|
||||
try {
|
||||
cvGetHuMoments(CVMOMENTS(src_moments), CVHUMOMENTS(self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu1 invariant
|
||||
* @overload hu1
|
||||
* @return [Number] hu1 invariant
|
||||
*/
|
||||
VALUE rb_hu1(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu2 invariant
|
||||
* @overload hu2
|
||||
* @return [Number] hu2 invariant
|
||||
*/
|
||||
VALUE rb_hu2(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu3 invariant
|
||||
* @overload hu3
|
||||
* @return [Number] hu3 invariant
|
||||
*/
|
||||
VALUE rb_hu3(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu3);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu4 invariant
|
||||
* @overload hu4
|
||||
* @return [Number] hu4 invariant
|
||||
*/
|
||||
VALUE rb_hu4(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu4);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu5 invariant
|
||||
* @overload hu5
|
||||
* @return [Number] hu5 invariant
|
||||
*/
|
||||
VALUE rb_hu5(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu5);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu6 invariant
|
||||
* @overload hu6
|
||||
* @return [Number] hu6 invariant
|
||||
*/
|
||||
VALUE rb_hu6(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu6);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu7 invariant
|
||||
* @overload hu7
|
||||
* @return [Number] hu7 invariant
|
||||
*/
|
||||
VALUE rb_hu7(VALUE self) {
|
||||
return DBL2NUM(CVHUMOMENTS(self)->hu7);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hu invaliants as an Array
|
||||
* @overload to_ary
|
||||
* @return [Array<Number>] Hu invaliants
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
CvHuMoments *hu_moments = CVHUMOMENTS(self);
|
||||
return rb_ary_new3(7,
|
||||
rb_float_new(hu_moments->hu1),
|
||||
rb_float_new(hu_moments->hu2),
|
||||
rb_float_new(hu_moments->hu3),
|
||||
rb_float_new(hu_moments->hu4),
|
||||
rb_float_new(hu_moments->hu5),
|
||||
rb_float_new(hu_moments->hu6),
|
||||
rb_float_new(hu_moments->hu7));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvMoments *src_moments)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
try {
|
||||
cvGetHuMoments(src_moments, CVHUMOMENTS(object));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvHuMoments", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), 1);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
|
||||
rb_define_method(rb_klass, "hu1", RUBY_METHOD_FUNC(rb_hu1), 0);
|
||||
rb_define_method(rb_klass, "hu2", RUBY_METHOD_FUNC(rb_hu2), 0);
|
||||
rb_define_method(rb_klass, "hu3", RUBY_METHOD_FUNC(rb_hu3), 0);
|
||||
rb_define_method(rb_klass, "hu4", RUBY_METHOD_FUNC(rb_hu4), 0);
|
||||
rb_define_method(rb_klass, "hu5", RUBY_METHOD_FUNC(rb_hu5), 0);
|
||||
rb_define_method(rb_klass, "hu6", RUBY_METHOD_FUNC(rb_hu6), 0);
|
||||
rb_define_method(rb_klass, "hu7", RUBY_METHOD_FUNC(rb_hu7), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVHUMOMENTS
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,51 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvhumoments.h -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVHUMOMENTS_H
|
||||
#define RUBY_OPENCV_CVHUMOMENTS_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVHUMOMENTS namespace cCvHuMoments {
|
||||
#define __NAMESPACE_END_CVHUMOMENTS }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVHUMOMENTS
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(VALUE src_moments, VALUE self);
|
||||
|
||||
VALUE rb_hu1(VALUE self);
|
||||
VALUE rb_hu2(VALUE self);
|
||||
VALUE rb_hu3(VALUE self);
|
||||
VALUE rb_hu4(VALUE self);
|
||||
VALUE rb_hu5(VALUE self);
|
||||
VALUE rb_hu6(VALUE self);
|
||||
VALUE rb_hu7(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object(CvMoments *cvmoments);
|
||||
|
||||
__NAMESPACE_END_CVHUMOMENTS
|
||||
|
||||
inline CvHuMoments*
|
||||
CVHUMOMENTS(VALUE object)
|
||||
{
|
||||
CvHuMoments *ptr;
|
||||
Data_Get_Struct(object, CvHuMoments, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVHUMOMENTS_H
|
|
@ -1,159 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvline.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvline.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvLine
|
||||
*
|
||||
* Line parameters represented by a two-element (rho, theta)
|
||||
* for CvMat#hough_lines
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVLINE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvLine *ptr;
|
||||
return Data_Make_Struct(klass, CvLine, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns distance from the coordinate origin (0, 0)
|
||||
* @overload rho
|
||||
* @return [Number] Distance from the coordinate origin
|
||||
*/
|
||||
VALUE
|
||||
rb_rho(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVLINE(self)->rho);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set distance from the coordinate origin (0, 0)
|
||||
* @overload rho=(value)
|
||||
* @param value [Number] Distance from the coordinate origin
|
||||
*/
|
||||
VALUE
|
||||
rb_set_rho(VALUE self, VALUE rho)
|
||||
{
|
||||
CVLINE(self)->rho = NUM2DBL(rho);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns line rotation angle in radians
|
||||
* @overload theta
|
||||
* @return [Number] Line rotation angle in radians
|
||||
*/
|
||||
VALUE
|
||||
rb_theta(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVLINE(self)->theta);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set line rotation angle in radians
|
||||
* @overload theta=(value)
|
||||
* @param value [Number] Line rotation angle
|
||||
*/
|
||||
VALUE
|
||||
rb_set_theta(VALUE self, VALUE theta)
|
||||
{
|
||||
CVLINE(self)->theta = NUM2DBL(theta);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns value of rho, theta
|
||||
* @overload [](index)
|
||||
* @param index [Integer] Index
|
||||
* @return [Number] If index = 0, returns rho, else if index = 1, returns theta.
|
||||
*/
|
||||
VALUE
|
||||
rb_aref(VALUE self, VALUE index)
|
||||
{
|
||||
switch (NUM2INT(index)) {
|
||||
case 0:
|
||||
return DBL2NUM(CVLINE(self)->rho);
|
||||
break;
|
||||
case 1:
|
||||
return DBL2NUM(CVLINE(self)->theta);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eIndexError, "index should be 0...2");
|
||||
break;
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set value of rho, theta
|
||||
* @overload []=(index, value)
|
||||
* @param index [Integer] Index
|
||||
* @param value [Number] Value
|
||||
* @return [Number] If index = 0, set rho, else if index = 1, set theta.
|
||||
*/
|
||||
VALUE
|
||||
rb_aset(VALUE self, VALUE index, VALUE value)
|
||||
{
|
||||
switch (NUM2INT(index)) {
|
||||
case 0:
|
||||
CVLINE(self)->rho = NUM2DBL(value);
|
||||
break;
|
||||
case 1:
|
||||
CVLINE(self)->theta = NUM2DBL(value);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eIndexError, "index should be 0...2");
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvLine line)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVLINE(object) = line;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvLine", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "rho", RUBY_METHOD_FUNC(rb_rho), 0);
|
||||
rb_define_method(rb_klass, "rho=", RUBY_METHOD_FUNC(rb_set_rho), 1);
|
||||
rb_define_method(rb_klass, "theta", RUBY_METHOD_FUNC(rb_theta), 0);
|
||||
rb_define_method(rb_klass, "theta=", RUBY_METHOD_FUNC(rb_set_theta), 1);
|
||||
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
||||
rb_define_method(rb_klass, "[]=", RUBY_METHOD_FUNC(rb_aset), 2);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVLINE
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,54 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvline.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVLINE_H
|
||||
#define RUBY_OPENCV_CVLINE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVLINE namespace cCvLine {
|
||||
#define __NAMESPACE_END_CVLINE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
|
||||
typedef struct CvLine {
|
||||
float rho;
|
||||
float theta;
|
||||
} CvLine;
|
||||
|
||||
__NAMESPACE_BEGIN_CVLINE
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rho(VALUE self);
|
||||
VALUE rb_set_rho(VALUE self, VALUE rho);
|
||||
VALUE rb_theta(VALUE self);
|
||||
VALUE rb_set_theta(VALUE self, VALUE theta);
|
||||
VALUE rb_aref(VALUE self, VALUE index);
|
||||
VALUE rb_aset(VALUE self, VALUE index, VALUE value);
|
||||
|
||||
VALUE new_object(CvLine line);
|
||||
|
||||
__NAMESPACE_END_CVLINE
|
||||
|
||||
inline CvLine*
|
||||
CVLINE(VALUE object)
|
||||
{
|
||||
CvLine *ptr;
|
||||
Data_Get_Struct(object, CvLine, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVLINE_H
|
6086
ext/opencv/cvmat.cpp
6086
ext/opencv/cvmat.cpp
File diff suppressed because it is too large
Load diff
|
@ -1,290 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvmat.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVMAT_H
|
||||
#define RUBY_OPENCV_CVMAT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVMAT namespace cCvMat {
|
||||
#define __NAMESPACE_END_CVMAT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVMAT
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_load_imageM(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_encode_imageM(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_decode_imageM(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_method_missing(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_inside_q(VALUE self, VALUE object);
|
||||
VALUE rb_to_IplConvKernel(VALUE self, VALUE anchor);
|
||||
VALUE rb_create_mask(VALUE self);
|
||||
|
||||
VALUE rb_width(VALUE self);
|
||||
VALUE rb_height(VALUE self);
|
||||
VALUE rb_depth(VALUE self);
|
||||
VALUE rb_channel(VALUE self);
|
||||
VALUE rb_data(VALUE self);
|
||||
|
||||
VALUE rb_clone(VALUE self);
|
||||
VALUE rb_copy(int argc, VALUE *argv, VALUE self);
|
||||
VALUE copy(VALUE mat);
|
||||
|
||||
VALUE rb_to_8u(VALUE self);
|
||||
VALUE rb_to_8s(VALUE self);
|
||||
VALUE rb_to_16u(VALUE self);
|
||||
VALUE rb_to_16s(VALUE self);
|
||||
VALUE rb_to_32s(VALUE self);
|
||||
VALUE rb_to_32f(VALUE self);
|
||||
VALUE rb_to_64f(VALUE self);
|
||||
VALUE rb_vector_q(VALUE self);
|
||||
VALUE rb_square_q(VALUE self);
|
||||
// cxcore function
|
||||
VALUE rb_to_CvMat(VALUE self);
|
||||
VALUE rb_to_IplImage(VALUE self);
|
||||
VALUE rb_sub_rect(VALUE self, VALUE args);
|
||||
VALUE rb_get_rows(int argc, VALUE* argv, VALUE self);
|
||||
VALUE rb_get_cols(VALUE self, VALUE col);
|
||||
VALUE rb_each_row(VALUE self);
|
||||
VALUE rb_each_col(VALUE self);
|
||||
VALUE rb_diag(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_size(VALUE self);
|
||||
VALUE rb_dims(VALUE self);
|
||||
VALUE rb_dim_size(VALUE self, VALUE index);
|
||||
VALUE rb_aref(VALUE self, VALUE args);
|
||||
VALUE rb_aset(VALUE self, VALUE args);
|
||||
VALUE rb_set_data(VALUE self, VALUE data);
|
||||
VALUE rb_set(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_set_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_set_zero(VALUE self);
|
||||
VALUE rb_set_zero_bang(VALUE self);
|
||||
VALUE rb_set_identity(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_set_identity_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_range(VALUE self, VALUE start, VALUE end);
|
||||
VALUE rb_range_bang(VALUE self, VALUE start, VALUE end);
|
||||
/* Transforms and Permutations */
|
||||
VALUE rb_reshape(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_repeat(VALUE self, VALUE object);
|
||||
VALUE rb_flip(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_flip_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_split(VALUE self);
|
||||
VALUE rb_merge(VALUE klass, VALUE args);
|
||||
VALUE rb_rand_shuffle(int argc, VALUE *argv, VALUE klass);
|
||||
VALUE rb_rand_shuffle_bang(int argc, VALUE *argv, VALUE klass);
|
||||
|
||||
VALUE rb_lut(VALUE self, VALUE lut);
|
||||
VALUE rb_convert_scale(VALUE self, VALUE hash);
|
||||
VALUE rb_convert_scale_abs(VALUE self, VALUE hash);
|
||||
VALUE rb_add(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_sub(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_mul(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_mat_mul(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_div(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_and(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_or(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_xor(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_not(VALUE self);
|
||||
VALUE rb_not_bang(VALUE self);
|
||||
VALUE rb_cmp_internal(VALUE self, VALUE val, int operand);
|
||||
VALUE rb_eq(VALUE self, VALUE val);
|
||||
VALUE rb_gt(VALUE self, VALUE val);
|
||||
VALUE rb_ge(VALUE self, VALUE val);
|
||||
VALUE rb_lt(VALUE self, VALUE val);
|
||||
VALUE rb_le(VALUE self, VALUE val);
|
||||
VALUE rb_ne(VALUE self, VALUE val);
|
||||
VALUE rb_in_range(VALUE self, VALUE min, VALUE max);
|
||||
VALUE rb_abs_diff(VALUE self, VALUE val);
|
||||
VALUE rb_normalize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_add_weighted(VALUE klass, VALUE src1, VALUE alpha, VALUE src2, VALUE beta, VALUE gamma);
|
||||
/* Statistics */
|
||||
VALUE rb_count_non_zero(VALUE self);
|
||||
VALUE rb_sum(VALUE self);
|
||||
VALUE rb_avg(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_avg_sdv(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_sdv(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_min_max_loc(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_norm(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_dot_product(VALUE self, VALUE mat);
|
||||
VALUE rb_cross_product(VALUE self, VALUE mat);
|
||||
// VALUE rb_gemm();
|
||||
VALUE rb_transform(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_perspective_transform(VALUE self, VALUE mat);
|
||||
VALUE rb_mul_transposed(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_trace(VALUE self);
|
||||
VALUE rb_transpose(VALUE self);
|
||||
VALUE rb_det(VALUE self);
|
||||
VALUE rb_invert(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_solve(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_svd(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_eigenvv(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_eigenvv_bang(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_dft(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_dct(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
/* drawing function*/
|
||||
VALUE rb_line(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_line_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rectangle(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rectangle_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_circle(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_circle_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_ellipse(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_ellipse_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_ellipse_box(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_ellipse_box_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_fill_poly(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_fill_poly_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_fill_convex_poly(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_fill_convex_poly_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_poly_line(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_poly_line_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_put_text(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_put_text_bang(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
/* cv function */
|
||||
VALUE rb_sobel(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_laplace(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_canny(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_pre_corner_detect(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_corner_eigenvv(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_corner_min_eigen_val(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_corner_harris(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_chessboard_corners(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_corner_sub_pix(VALUE self, VALUE corners, VALUE win_size, VALUE zero_zone, VALUE criteria);
|
||||
VALUE rb_good_features_to_track(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_rect_sub_pix(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_warp_affine(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale);
|
||||
VALUE rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest);
|
||||
VALUE rb_warp_perspective(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_homography(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_remap(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_log_polar(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_erode(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_erode_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_dilate(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_dilate_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_morphology(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_smooth(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_copy_make_border(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_filter2d(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_integral(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_threshold(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_adaptive_threshold(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_pyr_down(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_pyr_up(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_flood_fill(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_flood_fill_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_contours(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_contours_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_draw_contours(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_draw_contours_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_draw_chessboard_corners(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
|
||||
VALUE rb_draw_chessboard_corners_bang(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
|
||||
VALUE rb_pyr_mean_shift_filtering(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_watershed(VALUE self, VALUE markers);
|
||||
VALUE rb_moments(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_hough_lines(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_hough_circles(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_dist_transform(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_inpaint(VALUE self, VALUE inpaint_method, VALUE mask, VALUE radius);
|
||||
|
||||
VALUE rb_equalize_hist(VALUE self);
|
||||
|
||||
VALUE rb_apply_color_map(VALUE self, VALUE colormap);
|
||||
|
||||
/* Matching*/
|
||||
VALUE rb_match_template(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_match_shapes(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
/* Object Tracking */
|
||||
VALUE rb_mean_shift(VALUE self, VALUE window, VALUE criteria);
|
||||
VALUE rb_cam_shift(VALUE self, VALUE window, VALUE criteria);
|
||||
VALUE rb_snake_image(int argc, VALUE *argv, VALUE self);
|
||||
/* Optical Flow */
|
||||
VALUE rb_optical_flow_hs(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_optical_flow_lk(VALUE self, VALUE prev, VALUE win_size);
|
||||
VALUE rb_optical_flow_bm(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_optical_flow_pyr_lk(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
/* Epipolar Geometory */
|
||||
VALUE rb_find_fundamental_mat(int argc, VALUE *argv, VALUE klass);
|
||||
VALUE rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_image, VALUE fundamental_matrix);
|
||||
|
||||
/* Feature detection and description */
|
||||
VALUE rb_extract_surf(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_subspace_project(VALUE self, VALUE w, VALUE mean);
|
||||
VALUE rb_subspace_reconstruct(VALUE self, VALUE w, VALUE mean);
|
||||
|
||||
// HighGUI function
|
||||
VALUE rb_save_image(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE new_object(int rows, int cols, int type);
|
||||
VALUE new_object(CvSize size, int type);
|
||||
VALUE new_mat_kind_object(CvSize size, VALUE ref_obj);
|
||||
VALUE new_mat_kind_object(CvSize size, VALUE ref_obj, int cvmat_depth, int channel);
|
||||
|
||||
CvMat* prepare_decoding(int argc, VALUE *argv, int* iscolor, int* need_release);
|
||||
|
||||
__NAMESPACE_END_CVMAT
|
||||
|
||||
inline CvMat*
|
||||
CVMAT(VALUE object)
|
||||
{
|
||||
CvMat *ptr, stub;
|
||||
Data_Get_Struct(object, CvMat, ptr);
|
||||
return cvGetMat(ptr, &stub);
|
||||
}
|
||||
|
||||
inline CvMat*
|
||||
CVMAT_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvMat::rb_class()))
|
||||
raise_typeerror(object, cCvMat::rb_class());
|
||||
return CVMAT(object);
|
||||
}
|
||||
|
||||
inline CvMat*
|
||||
MASK(VALUE object)
|
||||
{
|
||||
if (NIL_P(object))
|
||||
return NULL;
|
||||
else {
|
||||
CvMat* obj_ptr = CVMAT_WITH_CHECK(object);
|
||||
if (CV_MAT_DEPTH(obj_ptr->type) == CV_8UC1 &&
|
||||
CV_MAT_CN(obj_ptr->type) == 1)
|
||||
return obj_ptr;
|
||||
else
|
||||
rb_raise(rb_eTypeError, "Mask should be 8bit 1-channel matrix.");
|
||||
}
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVMAT_H
|
|
@ -1,73 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvmemstorage.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvmemstorage.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvMemStorage
|
||||
*
|
||||
* Internal memory management class used by CvSeq.
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVMEMSTORAGE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvMemStorage *storage = rb_cvCreateMemStorage(0);
|
||||
return Data_Wrap_Struct(klass, 0, cvmemstorage_free, storage);
|
||||
}
|
||||
|
||||
void
|
||||
cvmemstorage_free(void *ptr)
|
||||
{
|
||||
try {
|
||||
cvReleaseMemStorage((CvMemStorage**)&ptr);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(int blocksize)
|
||||
{
|
||||
CvMemStorage *storage = rb_cvCreateMemStorage(blocksize);
|
||||
return Data_Wrap_Struct(rb_klass, 0, cvmemstorage_free, storage);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvMemStorage", rb_cObject);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVMEMSTORAGE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvmemstorage.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVMEMSTORAGE_H
|
||||
#define RUBY_OPENCV_CVMEMSTORAGE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVMEMSTORAGE namespace cCvMemStorage {
|
||||
#define __NAMESPACE_END_CVMEMSTORAGE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVMEMSTORAGE
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_class();
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
void cvmemstorage_free(void *ptr);
|
||||
|
||||
VALUE new_object(int blocksize = 0);
|
||||
|
||||
__NAMESPACE_END_CVMEMSTORAGE
|
||||
|
||||
inline CvMemStorage*
|
||||
CVMEMSTORAGE(VALUE object)
|
||||
{
|
||||
CvMemStorage *ptr;
|
||||
Data_Get_Struct(object, CvMemStorage, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline VALUE
|
||||
CHECK_CVMEMSTORAGE(VALUE object)
|
||||
{
|
||||
if (rb_obj_is_kind_of(object, cCvMemStorage::rb_class())) {
|
||||
return object;
|
||||
}
|
||||
return cCvMemStorage::new_object();
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVMEMSTORAGE_H
|
|
@ -1,293 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvmoments.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvmoments.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvMoments
|
||||
*
|
||||
* moments
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVMOMENTS
|
||||
|
||||
#define DEFINE_CVMOMENTS_ACCESSOR(elem) \
|
||||
rb_define_method(rb_klass, #elem, RUBY_METHOD_FUNC(rb_##elem), 0)
|
||||
|
||||
#define CVMOMENTS_ACCESSOR(elem) \
|
||||
VALUE rb_##elem(VALUE self) { return DBL2NUM(CVMOMENTS(self)->elem); }
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvMoments *ptr;
|
||||
return Data_Make_Struct(klass, CvMoments, 0, -1, ptr);
|
||||
}
|
||||
/*
|
||||
* call-seq:
|
||||
* CvMoments.new(src[,is_binary = nil])
|
||||
*
|
||||
* Calculates all moments up to third order of a polygon or rasterized shape.
|
||||
* <i>src</i> should be CvMat or CvPolygon.
|
||||
*
|
||||
* If is_binary = true, all the zero pixel values are treated as zeroes, all the others are treated as 1's.
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE src, is_binary;
|
||||
rb_scan_args(argc, argv, "02", &src, &is_binary);
|
||||
if (!NIL_P(src)) {
|
||||
if (rb_obj_is_kind_of(src, cCvMat::rb_class()) || rb_obj_is_kind_of(src, cCvSeq::rb_class())) {
|
||||
try {
|
||||
cvMoments(CVARR(src), CVMOMENTS(self), TRUE_OR_FALSE(is_binary, 0));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
rb_raise(rb_eTypeError, "argument 1 (src) should be %s or %s.",
|
||||
rb_class2name(cCvMat::rb_class()), rb_class2name(cCvSeq::rb_class()));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
CVMOMENTS_ACCESSOR(m00);
|
||||
CVMOMENTS_ACCESSOR(m10);
|
||||
CVMOMENTS_ACCESSOR(m01);
|
||||
CVMOMENTS_ACCESSOR(m20);
|
||||
CVMOMENTS_ACCESSOR(m11);
|
||||
CVMOMENTS_ACCESSOR(m02);
|
||||
CVMOMENTS_ACCESSOR(m30);
|
||||
CVMOMENTS_ACCESSOR(m21);
|
||||
CVMOMENTS_ACCESSOR(m12);
|
||||
CVMOMENTS_ACCESSOR(m03);
|
||||
|
||||
CVMOMENTS_ACCESSOR(mu20);
|
||||
CVMOMENTS_ACCESSOR(mu11);
|
||||
CVMOMENTS_ACCESSOR(mu02);
|
||||
CVMOMENTS_ACCESSOR(mu30);
|
||||
CVMOMENTS_ACCESSOR(mu21);
|
||||
CVMOMENTS_ACCESSOR(mu12);
|
||||
CVMOMENTS_ACCESSOR(mu03);
|
||||
|
||||
CVMOMENTS_ACCESSOR(inv_sqrt_m00);
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* spatial -> float
|
||||
*
|
||||
* Retrieves spatial moment.
|
||||
*
|
||||
* which in case of image moments is defined as:
|
||||
* Mx_order,y_order=sumx,y(I(x,y)*xx_order*yy_order)
|
||||
* where I(x,y) is the intensity of the pixel (x, y).
|
||||
*/
|
||||
VALUE
|
||||
rb_spatial(VALUE self, VALUE x_order, VALUE y_order)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvGetSpatialMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* central -> float
|
||||
*
|
||||
* Retrieves central moment.
|
||||
*
|
||||
* which in case of image moments is defined as:
|
||||
* μx_order,y_order=sumx,y(I(x,y)*(x-xc)x_order*(y-yc)y_order),
|
||||
* where xc=M10/M00, yc=M01/M00 - coordinates of the gravity center
|
||||
*/
|
||||
VALUE
|
||||
rb_central(VALUE self, VALUE x_order, VALUE y_order)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvGetCentralMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* normalized_central -> float
|
||||
*
|
||||
* Retrieves normalized central moment.
|
||||
*
|
||||
* ηx_order,y_order= μx_order,y_order/M00((y_order+x_order)/2+1)
|
||||
*/
|
||||
VALUE
|
||||
rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order)
|
||||
{
|
||||
double result = 0;
|
||||
try {
|
||||
result = cvGetNormalizedCentralMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return rb_float_new(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hu -> cvhumoments
|
||||
*
|
||||
* Calculates seven Hu invariants.
|
||||
*
|
||||
* seven Hu invariants that are defined as:
|
||||
* h1=η20+η02
|
||||
* h2=(η20-η02)²+4η11²
|
||||
* h3=(η30-3η12)²+ (3η21-η03)²
|
||||
* h4=(η30+η12)²+ (η21+η03)²
|
||||
* h5=(η30-3η12)(η30+η12)[(η30+η12)²-3(η21+η03)²]+(3η21-η03)(η21+η03)[3(η30+η12)²-(η21+η03)²]
|
||||
* h6=(η20-η02)[(η30+η12)²- (η21+η03)²]+4η11(η30+η12)(η21+η03)
|
||||
* h7=(3η21-η03)(η21+η03)[3(η30+η12)²-(η21+η03)²]-(η30-3η12)(η21+η03)[3(η30+η12)²-(η21+η03)²]
|
||||
* where ηi,j are normalized central moments of 2-nd and 3-rd orders. The computed values are proved to be invariant to the image scaling, rotation, and reflection except the seventh one, whose sign is changed by reflection.
|
||||
*/
|
||||
VALUE
|
||||
rb_hu(VALUE self)
|
||||
{
|
||||
return cCvHuMoments::new_object(CVMOMENTS(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* gravity_center -> cvpoint2d32f
|
||||
*
|
||||
* Return gravity center.
|
||||
*/
|
||||
VALUE
|
||||
rb_gravity_center(VALUE self)
|
||||
{
|
||||
CvMoments *moments = CVMOMENTS(self);
|
||||
CvPoint2D32f point;
|
||||
double m00 = 0, m01 = 0, m10 = 0;
|
||||
try {
|
||||
m00 = cvGetSpatialMoment(moments, 0, 0);
|
||||
m10 = cvGetSpatialMoment(moments, 1, 0);
|
||||
m01 = cvGetSpatialMoment(moments, 0, 1);
|
||||
point = cvPoint2D32f(m10 / m00, m01 / m00);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return cCvPoint2D32f::new_object(point);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* angle -> float
|
||||
*
|
||||
* Return angle.
|
||||
*/
|
||||
VALUE
|
||||
rb_angle(VALUE self)
|
||||
{
|
||||
CvMoments *moments = CVMOMENTS(self);
|
||||
double m11 = 0, m20 = 0, m02 = 0;
|
||||
try {
|
||||
m11 = cvGetCentralMoment(moments, 1, 1);
|
||||
m20 = cvGetCentralMoment(moments, 2, 0);
|
||||
m02 = cvGetCentralMoment(moments, 0, 2);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
double mangle = 0.5 * atan(2 * m11 / (m20 - m02));
|
||||
if (cvIsNaN(mangle) || cvIsInf(mangle))
|
||||
return Qnil;
|
||||
else
|
||||
return rb_float_new(mangle);
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvArr *arr, int is_binary = 0)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
try {
|
||||
cvMoments(arr, CVMOMENTS(object), is_binary);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvMoments", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "spatial", RUBY_METHOD_FUNC(rb_spatial), 2);
|
||||
rb_define_method(rb_klass, "central", RUBY_METHOD_FUNC(rb_central), 2);
|
||||
rb_define_method(rb_klass, "normalized_central", RUBY_METHOD_FUNC(rb_normalized_central), 2);
|
||||
rb_define_method(rb_klass, "hu", RUBY_METHOD_FUNC(rb_hu), 0);
|
||||
rb_define_method(rb_klass, "gravity_center", RUBY_METHOD_FUNC(rb_gravity_center), 0);
|
||||
rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
|
||||
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m00);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m10);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m01);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m20);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m11);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m02);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m30);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m21);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m12);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(m03);
|
||||
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu20);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu11);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu02);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu30);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu21);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu12);
|
||||
DEFINE_CVMOMENTS_ACCESSOR(mu03);
|
||||
|
||||
DEFINE_CVMOMENTS_ACCESSOR(inv_sqrt_m00);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVMOMENTS
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvmoments.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2007 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVMOMENTS_H
|
||||
#define RUBY_OPENCV_CVMOMENTS_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVMOMENTS namespace cCvMoments {
|
||||
#define __NAMESPACE_END_CVMOMENTS }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVMOMENTS
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_spatial(VALUE self, VALUE x_order, VALUE y_order);
|
||||
VALUE rb_central(VALUE self, VALUE x_order, VALUE y_order);
|
||||
VALUE rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order);
|
||||
VALUE rb_hu(VALUE self);
|
||||
VALUE rb_gravity_center(VALUE self);
|
||||
VALUE rb_angle(VALUE self);
|
||||
|
||||
VALUE rb_m00(VALUE self);
|
||||
VALUE rb_m10(VALUE self);
|
||||
VALUE rb_m01(VALUE self);
|
||||
VALUE rb_m20(VALUE self);
|
||||
VALUE rb_m11(VALUE self);
|
||||
VALUE rb_m02(VALUE self);
|
||||
VALUE rb_m30(VALUE self);
|
||||
VALUE rb_m21(VALUE self);
|
||||
VALUE rb_m12(VALUE self);
|
||||
VALUE rb_m03(VALUE self);
|
||||
VALUE rb_mu20(VALUE self);
|
||||
VALUE rb_mu11(VALUE self);
|
||||
VALUE rb_mu02(VALUE self);
|
||||
VALUE rb_mu30(VALUE self);
|
||||
VALUE rb_mu21(VALUE self);
|
||||
VALUE rb_mu12(VALUE self);
|
||||
VALUE rb_mu03(VALUE self);
|
||||
VALUE rb_inv_sqrt_m00(VALUE self);
|
||||
|
||||
VALUE new_object(CvArr *arr, int is_binary);
|
||||
|
||||
__NAMESPACE_END_CVMOMENTS
|
||||
|
||||
inline CvMoments*
|
||||
CVMOMENTS(VALUE object)
|
||||
{
|
||||
CvMoments *ptr;
|
||||
Data_Get_Struct(object, CvMoments, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvMoments*
|
||||
CVMOMENTS_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvMoments::rb_class()))
|
||||
raise_typeerror(object, cCvMoments::rb_class());
|
||||
return CVMOMENTS(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVMOMENTS_H
|
|
@ -1,234 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvpoint.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvPoint
|
||||
*
|
||||
* This class means one point on X axis Y axis.
|
||||
* X and Y takes the value of the Fixnum. see also CvPoint2D32F
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvPoint {
|
||||
* int x;
|
||||
* int y;
|
||||
* }
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* combatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvPoint. Return true if object have method #x and #y.
|
||||
*
|
||||
* For example.
|
||||
* class MyPoint
|
||||
* def x
|
||||
* 1
|
||||
* end
|
||||
* def y
|
||||
* 2
|
||||
* end
|
||||
* end
|
||||
* mp = MyPoint.new
|
||||
* CvPoint.compatible?(mp) #=> true
|
||||
* CvPoint.new(mp) #=> same as CvPoint(1, 2)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvPoint *ptr;
|
||||
return Data_Make_Struct(klass, CvPoint, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new -> CvPoint.new(0, 0)
|
||||
* new(obj) -> CvPoint.new(obj.x.to_i, obj.y.to_i)
|
||||
* new(x, y)
|
||||
*
|
||||
* Create new 2D-coordinate, (x, y). It is dropped below the decimal point.
|
||||
*
|
||||
* new() is same as new(0, 0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_i, obj.y.to_i)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvPoint* self_ptr = CVPOINT(self);
|
||||
switch (argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvPoint point = VALUE_TO_CVPOINT(argv[0]);
|
||||
self_ptr->x = point.x;
|
||||
self_ptr->y = point.y;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
self_ptr->x = NUM2INT(argv[0]);
|
||||
self_ptr->y = NUM2INT(argv[1]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_x(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVPOINT(self)->x);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* x = val
|
||||
*
|
||||
* Set x-axis parameter, return self.
|
||||
* It is dropped below the decimal point.
|
||||
* pt = CvPoint.new
|
||||
* pt.x = 1.1
|
||||
* pt.x #=> 1
|
||||
* pt.x = 100.9
|
||||
* pt.x #=> 100
|
||||
*/
|
||||
VALUE
|
||||
rb_set_x(VALUE self, VALUE x)
|
||||
{
|
||||
CVPOINT(self)->x = NUM2INT(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on y-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_y(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVPOINT(self)->y);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* y = val
|
||||
*
|
||||
* Set y-axis parameter, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_y(VALUE self, VALUE y)
|
||||
{
|
||||
CVPOINT(self)->y = NUM2INT(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpenCV::CvPoint:(self.x,self.y)>"
|
||||
*
|
||||
* Return x and y by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 4;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:(%d,%d)>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_x(self);
|
||||
str[3] = rb_y(self);
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [x, y]
|
||||
*
|
||||
* Return x and y by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
CvPoint* self_ptr = CVPOINT(self);
|
||||
return rb_ary_new3(2, INT2NUM(self_ptr->x), INT2NUM(self_ptr->y));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVPOINT(object) = cvPoint(0, 0);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
VALUE
|
||||
new_object(CvPoint point)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVPOINT(object) = point;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvPoint", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
||||
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
||||
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
||||
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
||||
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVPOINT
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVPOINT_H
|
||||
#define RUBY_OPENCV_CVPOINT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVPOINT namespace cCvPoint {
|
||||
#define __NAMESPACE_END_CVPOINT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_x(VALUE self);
|
||||
VALUE rb_set_x(VALUE self, VALUE x);
|
||||
VALUE rb_y(VALUE self);
|
||||
VALUE rb_set_y(VALUE self, VALUE y);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
VALUE new_object(CvPoint point);
|
||||
|
||||
__NAMESPACE_END_CVPOINT
|
||||
|
||||
inline CvPoint*
|
||||
CVPOINT(VALUE object){
|
||||
CvPoint *ptr;
|
||||
Data_Get_Struct(object, CvPoint, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvPoint
|
||||
VALUE_TO_CVPOINT(VALUE object)
|
||||
{
|
||||
if (cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)) {
|
||||
return cvPoint(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVPOINT_H
|
|
@ -1,216 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint2d32f.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvpoint2d32f.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvPoint2D32f
|
||||
*
|
||||
* This class means one point on X axis Y axis.
|
||||
* X and Y takes the value of the Float. see also CvPoint
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvPoint2D32f {
|
||||
* float x;
|
||||
* float y;
|
||||
* }
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT2D32F
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* combatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvPoint2D32f. Return true if object have method #x and #y.
|
||||
*
|
||||
* For example.
|
||||
* class MyPoint2D32f
|
||||
* def x
|
||||
* 95.7
|
||||
* end
|
||||
* def y
|
||||
* 70.2
|
||||
* end
|
||||
* end
|
||||
* mp = MyPoint2D32f.new
|
||||
* CvPoint2D32f.compatible?(mp) #=> true
|
||||
* CvPoint2D32f.new(mp) #=> same as CvPoint2D32f(95.7, 70.2)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvPoint2D32f *ptr;
|
||||
return Data_Make_Struct(klass, CvPoint2D32f, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new
|
||||
* new(obj)
|
||||
* new(x, y)
|
||||
*
|
||||
* Create new 2D-coordinate, (x, y).
|
||||
*
|
||||
* new() is same as new(0.0, 0.0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_f, obj.y.to_f)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvPoint2D32f *self_ptr = CVPOINT2D32F(self);
|
||||
switch (argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvPoint2D32f point = VALUE_TO_CVPOINT2D32F(argv[0]);
|
||||
self_ptr->x = point.x;
|
||||
self_ptr->y = point.y;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
self_ptr->x = NUM2DBL(argv[0]);
|
||||
self_ptr->y = NUM2DBL(argv[1]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_x(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVPOINT2D32F(self)->x);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* x = val
|
||||
*
|
||||
* Set x-axis parameter, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_x(VALUE self, VALUE x)
|
||||
{
|
||||
CVPOINT2D32F(self)->x = NUM2DBL(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on y-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_y(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVPOINT2D32F(self)->y);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* y = val
|
||||
*
|
||||
* Set y-axis parameter, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_y(VALUE self, VALUE y)
|
||||
{
|
||||
CVPOINT2D32F(self)->y = NUM2DBL(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpenCV::CvSize2D32f:(self.x,self.y)>"
|
||||
*
|
||||
* Return x and y by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 4;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:(%g,%g)>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_x(self);
|
||||
str[3] = rb_y(self);
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [x, y]
|
||||
*
|
||||
* Return x and y by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(2, rb_x(self), rb_y(self));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvPoint2D32f point)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVPOINT2D32F(object) = point;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
||||
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
||||
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
||||
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
||||
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVPOINT2D32F
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,63 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint2d32f.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVPOINT2D32F_H
|
||||
#define RUBY_OPENCV_CVPOINT2D32F_H
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVPOINT2D32F namespace cCvPoint2D32f {
|
||||
#define __NAMESPACE_END_CVPOINT2D32F }
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT2D32F
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_x(VALUE self);
|
||||
VALUE rb_set_x(VALUE self, VALUE x);
|
||||
VALUE rb_y(VALUE self);
|
||||
VALUE rb_set_y(VALUE self, VALUE y);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object(CvPoint2D32f point);
|
||||
|
||||
__NAMESPACE_END_CVPOINT2D32F
|
||||
|
||||
inline CvPoint2D32f*
|
||||
CVPOINT2D32F(VALUE object)
|
||||
{
|
||||
CvPoint2D32f *ptr;
|
||||
Data_Get_Struct(object, CvPoint2D32f, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvPoint2D32f
|
||||
VALUE_TO_CVPOINT2D32F(VALUE object)
|
||||
{
|
||||
if (cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)) {
|
||||
return cvPoint2D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint2D32f::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
#endif // RUBY_OPENCV_CVPOINT2D32F_H
|
|
@ -1,252 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint3d32f.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2008 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvpoint3d32f.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvPoint3D32f
|
||||
*
|
||||
* This class means one point on X axis Y axis.
|
||||
* X and Y takes the value of the Float. see also CvPoint
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvPoint3D32f {
|
||||
* float x;
|
||||
* float y;
|
||||
* float z;
|
||||
* }
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT3D32F
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* combatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvPoint3D32f. Return true if object have method #x and #y and #z.
|
||||
*
|
||||
* For example.
|
||||
* class MyPoint3D32f
|
||||
* def x
|
||||
* 95.7
|
||||
* end
|
||||
* def y
|
||||
* 70.2
|
||||
* end
|
||||
* def z
|
||||
* 10.0
|
||||
* end
|
||||
* end
|
||||
* mp = MyPoint3D32f.new
|
||||
* CvPoint3D32f.compatible?(mp) #=> true
|
||||
* CvPoint3D32f.new(mp) #=> same as CvPoint3D32f(95.7, 70.2)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) &&
|
||||
rb_respond_to(object, rb_intern("y")) &&
|
||||
rb_respond_to(object, rb_intern("z"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvPoint3D32f *ptr;
|
||||
return Data_Make_Struct(klass, CvPoint3D32f, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new
|
||||
* new(obj)
|
||||
* new(x, y, z)
|
||||
*
|
||||
* Create new 3D-coordinate, (x, y, z).
|
||||
*
|
||||
* new() is same as new(0.0, 0.0, 0.0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_f, obj.y.to_f, obj.z.to_f)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvPoint3D32f *self_ptr = CVPOINT3D32F(self);
|
||||
switch (argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvPoint3D32f point = VALUE_TO_CVPOINT3D32F(argv[0]);
|
||||
self_ptr->x = point.x;
|
||||
self_ptr->y = point.y;
|
||||
self_ptr->z = point.z;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
self_ptr->x = NUM2DBL(argv[0]);
|
||||
self_ptr->y = NUM2DBL(argv[1]);
|
||||
self_ptr->z = NUM2DBL(argv[2]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_x(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVPOINT2D32F(self)->x);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* x = val
|
||||
*
|
||||
* Set x-axis parameter, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_x(VALUE self, VALUE x)
|
||||
{
|
||||
CVPOINT2D32F(self)->x = NUM2DBL(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on y-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_y(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVPOINT2D32F(self)->y);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* y = val
|
||||
*
|
||||
* Set y-axis parameter, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_y(VALUE self, VALUE y)
|
||||
{
|
||||
CVPOINT2D32F(self)->y = NUM2DBL(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on z-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_z(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVPOINT3D32F(self)->z);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* z = val
|
||||
*
|
||||
* Set z-axis parameter, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_z(VALUE self, VALUE z)
|
||||
{
|
||||
CVPOINT3D32F(self)->z = NUM2DBL(z);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpenCV::CvSize3D32f:(self.x,self.y,self.z)>"
|
||||
*
|
||||
* Return x and y by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 5;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:(%g,%g,%g)>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_x(self);
|
||||
str[3] = rb_y(self);
|
||||
str[4] = rb_z(self);
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [x, y, z]
|
||||
*
|
||||
* Return x and y by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(3, rb_x(self), rb_y(self), rb_z(self));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvPoint3D32f point)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVPOINT3D32F(object) = point;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
VALUE cvpoint2d32f = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
* cvpoint2d32f = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
VALUE cvpoint2d32f = cCvPoint2D32f::rb_class();
|
||||
rb_klass = rb_define_class_under(opencv, "CvPoint3D32f", cvpoint2d32f);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
||||
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
||||
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
||||
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
||||
rb_define_method(rb_klass, "z", RUBY_METHOD_FUNC(rb_z), 0);
|
||||
rb_define_method(rb_klass, "z=", RUBY_METHOD_FUNC(rb_set_z), 1);
|
||||
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVPOINT3D32F
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvpoint3d32f.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2008 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVPOINT3D32F_H
|
||||
#define RUBY_OPENCV_CVPOINT3D32F_H
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVPOINT3D32F namespace cCvPoint3D32f {
|
||||
#define __NAMESPACE_END_CVPOINT3D32F }
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVPOINT3D32F
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_x(VALUE self);
|
||||
VALUE rb_set_x(VALUE self, VALUE x);
|
||||
VALUE rb_y(VALUE self);
|
||||
VALUE rb_set_y(VALUE self, VALUE y);
|
||||
VALUE rb_z(VALUE self);
|
||||
VALUE rb_set_z(VALUE self, VALUE z);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object(CvPoint3D32f point);
|
||||
|
||||
__NAMESPACE_END_CVPOINT3D32F
|
||||
|
||||
inline CvPoint3D32f*
|
||||
CVPOINT3D32F(VALUE object)
|
||||
{
|
||||
CvPoint3D32f *ptr;
|
||||
Data_Get_Struct(object, CvPoint3D32f, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvPoint3D32f
|
||||
VALUE_TO_CVPOINT3D32F(VALUE object)
|
||||
{
|
||||
if (cCvPoint3D32f::rb_compatible_q(cCvPoint3D32f::rb_class(), object)) {
|
||||
return cvPoint3D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("z"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint3D32f::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
#endif // RUBY_OPENCV_CVPOINT3D32F_H
|
|
@ -1,338 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvrect.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvrect.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvRect
|
||||
*
|
||||
* This class have coordinate of top-left point(x, y) and size, width and height.
|
||||
*
|
||||
*
|
||||
* C stracture is here, very simple.
|
||||
* typdef struct CvRect {
|
||||
* int x;
|
||||
* int y;
|
||||
* int width;
|
||||
* int height;
|
||||
* }
|
||||
*
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVRECT
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* combatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvRect. Return true if object have method #x and #y and #width and #height.
|
||||
*
|
||||
* For example.
|
||||
* class MyRect
|
||||
* def x
|
||||
* 1
|
||||
* end
|
||||
* def y
|
||||
* 2
|
||||
* end
|
||||
* def width
|
||||
* 10
|
||||
* end
|
||||
* def height
|
||||
* 20
|
||||
* end
|
||||
* end
|
||||
* mr = MyRect.new
|
||||
* CvRect.compatible?(mp) #=> true
|
||||
* CvRect.new(mp) #=> same as CvRect(1, 2, 10, 20)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) &&
|
||||
rb_respond_to(object, rb_intern("y")) &&
|
||||
rb_respond_to(object, rb_intern("width")) &&
|
||||
rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* max_rect(rect1, rect2) -> cvrect
|
||||
*
|
||||
* Finds bounding rectangle for given rectangles.
|
||||
*/
|
||||
VALUE
|
||||
rb_max_rect(VALUE klass, VALUE rect1, VALUE rect2)
|
||||
{
|
||||
return cCvRect::new_object(cvMaxRect(CVRECT(rect1), CVRECT(rect2)));
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvRect *ptr;
|
||||
return Data_Make_Struct(klass, CvRect, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new -> CvRect.new(0, 0, 0, 0)
|
||||
* new(obj) -> CvRect.new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
|
||||
* new(x, y, width, height)
|
||||
*
|
||||
* Create new rectangle area. (x, y) is top-left point, and width, height is size of area.
|
||||
* It is dropped below the decimal point.
|
||||
*
|
||||
* new() is same as new(0, 0, 0, 0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvRect *self_ptr = CVRECT(self);
|
||||
switch (argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvRect rect = VALUE_TO_CVRECT(argv[0]);
|
||||
self_ptr->x = rect.x;
|
||||
self_ptr->y = rect.y;
|
||||
self_ptr->width = rect.width;
|
||||
self_ptr->height = rect.height;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
self_ptr->x = NUM2INT(argv[0]);
|
||||
self_ptr->y = NUM2INT(argv[1]);
|
||||
self_ptr->width = NUM2INT(argv[2]);
|
||||
self_ptr->height = NUM2INT(argv[3]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on x-axis of top-left point.
|
||||
*/
|
||||
VALUE
|
||||
rb_x(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVRECT(self)->x);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* x = val
|
||||
*
|
||||
* Set x-axis parameter of top-left point, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_x(VALUE self, VALUE x)
|
||||
{
|
||||
CVRECT(self)->x = NUM2INT(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return parameter on y-axis of top-left point.
|
||||
*/
|
||||
VALUE
|
||||
rb_y(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVRECT(self)->y);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* y = val
|
||||
*
|
||||
* Set y-axis parameter of top-left point, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_y(VALUE self, VALUE y)
|
||||
{
|
||||
CVRECT(self)->y = NUM2INT(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_width(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVRECT(self)->width);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* width = val
|
||||
*
|
||||
* Set x-axis size, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_width(VALUE self, VALUE x)
|
||||
{
|
||||
CVRECT(self)->width = NUM2INT(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of y-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_height(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVRECT(self)->height);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* height = val
|
||||
*
|
||||
* Set y-axis size, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_height(VALUE self, VALUE y)
|
||||
{
|
||||
CVRECT(self)->height = NUM2INT(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return center point of rectangle.
|
||||
*/
|
||||
VALUE
|
||||
rb_center(VALUE self)
|
||||
{
|
||||
CvRect *rect = CVRECT(self);
|
||||
return cCvPoint2D32f::new_object(cvPoint2D32f((float)rect->x + (float)rect->width / 2.0,
|
||||
(float)rect->y + (float)rect->height / 2.0));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 4 points (top-left, bottom-left, bottom-right, top-right)
|
||||
*/
|
||||
VALUE
|
||||
rb_points(VALUE self)
|
||||
{
|
||||
CvRect *rect = CVRECT(self);
|
||||
return rb_ary_new3(4,
|
||||
cCvPoint::new_object(cvPoint(rect->x, rect->y)),
|
||||
cCvPoint::new_object(cvPoint(rect->x, rect->y + rect->height)),
|
||||
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y + rect->height)),
|
||||
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y))
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return top-left point of rectangle.
|
||||
*/
|
||||
VALUE
|
||||
rb_top_left(VALUE self)
|
||||
{
|
||||
CvRect* rect = CVRECT(self);
|
||||
return cCvPoint::new_object(cvPoint(rect->x, rect->y));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return top-right point of rectangle.
|
||||
*/
|
||||
VALUE
|
||||
rb_top_right(VALUE self)
|
||||
{
|
||||
CvRect* rect = CVRECT(self);
|
||||
return cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return bottom-left point of rectangle.
|
||||
*/
|
||||
VALUE
|
||||
rb_bottom_left(VALUE self)
|
||||
{
|
||||
CvRect* rect = CVRECT(self);
|
||||
return cCvPoint::new_object(cvPoint(rect->x,
|
||||
rect->y + rect->height));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return bottom-right point of rectangle.
|
||||
*/
|
||||
VALUE
|
||||
rb_bottom_right(VALUE self)
|
||||
{
|
||||
CvRect* rect = CVRECT(self);
|
||||
return cCvPoint::new_object(cvPoint(rect->x + rect->width,
|
||||
rect->y + rect->height));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvRect rect)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVRECT(object) = rect;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvRect", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_singleton_method(rb_klass, "max_rect", RUBY_METHOD_FUNC(rb_max_rect), 2);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
|
||||
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
||||
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
||||
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
||||
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
||||
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
||||
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
||||
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
||||
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
||||
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
||||
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
||||
rb_define_method(rb_klass, "top_left", RUBY_METHOD_FUNC(rb_top_left), 0);
|
||||
rb_define_method(rb_klass, "top_right", RUBY_METHOD_FUNC(rb_top_right), 0);
|
||||
rb_define_method(rb_klass, "bottom_left", RUBY_METHOD_FUNC(rb_bottom_left), 0);
|
||||
rb_define_method(rb_klass, "bottom_right", RUBY_METHOD_FUNC(rb_bottom_right), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVRECT
|
||||
__NAMESPACE_END_OPENCV
|
|
@ -1,79 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvrect.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVRECT_H
|
||||
#define RUBY_OPENCV_CVRECT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVRECT namespace cCvRect {
|
||||
#define __NAMESPACE_END_CVRECT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVRECT
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
VALUE rb_max_rect(VALUE klass, VALUE rect1, VALUE rect2);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_x(VALUE self);
|
||||
VALUE rb_set_x(VALUE self, VALUE x);
|
||||
VALUE rb_y(VALUE self);
|
||||
VALUE rb_set_y(VALUE self, VALUE y);
|
||||
VALUE rb_width(VALUE self);
|
||||
VALUE rb_set_width(VALUE self, VALUE width);
|
||||
VALUE rb_height(VALUE self);
|
||||
VALUE rb_set_height(VALUE self, VALUE height);
|
||||
|
||||
VALUE rb_center(VALUE self);
|
||||
VALUE rb_points(VALUE self);
|
||||
VALUE rb_top_left(VALUE self);
|
||||
VALUE rb_set_top_left(VALUE self, VALUE point);
|
||||
VALUE rb_top_right(VALUE self);
|
||||
VALUE rb_set_top_right(VALUE self, VALUE point);
|
||||
VALUE rb_bottom_left(VALUE self);
|
||||
VALUE rb_set_bottom_left(VALUE self, VALUE point);
|
||||
VALUE rb_bottom_right(VALUE self);
|
||||
VALUE rb_set_bottom_right(VALUE self, VALUE point);
|
||||
|
||||
VALUE new_object(CvRect rect);
|
||||
|
||||
__NAMESPACE_END_CVRECT
|
||||
|
||||
inline CvRect*
|
||||
CVRECT(VALUE object)
|
||||
{
|
||||
CvRect *ptr;
|
||||
Data_Get_Struct(object, CvRect, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvRect
|
||||
VALUE_TO_CVRECT(VALUE object)
|
||||
{
|
||||
if (cCvRect::rb_compatible_q(cCvRect::rb_class(), object)) {
|
||||
return cvRect(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvRect::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVRECT_H
|
|
@ -1,241 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvscalar.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvscalar.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvScalar
|
||||
*
|
||||
* Element-value of one pixel.
|
||||
* OpenCV supports the image of 4-channels in the maximum.
|
||||
* Therefore, CvScalar has 4-values.
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvScalar {
|
||||
* double val[4];
|
||||
* } CvScalar;
|
||||
*
|
||||
* If obtain CvScalar-object from the method of CvMat(or IplImage),
|
||||
* the channel outside the range is obtained as all 0.
|
||||
*
|
||||
* image = IplImage::load("opencv.jpg") #=> 3-channel 8bit-depth BGR image
|
||||
* pixel = image[10, 20] #=> Get pixel value of (10, 20) of image. pixel is CvScalar-object.
|
||||
* blue, green, red = pixel[0], pixel[1], pixel[2]
|
||||
* # pixel[3] always 0.
|
||||
*
|
||||
* CvColor is alias of CvScalar.
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSCALAR
|
||||
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvScalar *ptr;
|
||||
return Data_Make_Struct(klass, CvScalar, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new([d1][,d2][,d3][,d4])
|
||||
*
|
||||
* Create new Scalar. Argument should be Fixnum (or nil as 0).
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE val[4];
|
||||
rb_scan_args(argc, argv, "04", &val[0], &val[1], &val[2], &val[3]);
|
||||
CvScalar* self_ptr = CVSCALAR(self);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
self_ptr->val[i] = NIL_P(val[i]) ? 0 : NUM2DBL(val[i]);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* [<i>index</i>]
|
||||
*
|
||||
* Return value of <i>index</i> dimension.
|
||||
*/
|
||||
VALUE
|
||||
rb_aref(VALUE self, VALUE index)
|
||||
{
|
||||
int idx = NUM2INT(index);
|
||||
if (idx < 0 || idx >= 4) {
|
||||
rb_raise(rb_eIndexError, "scalar index should be 0...4");
|
||||
}
|
||||
return rb_float_new(CVSCALAR(self)->val[idx]);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* [<i>index</i>] = <i>value</i>
|
||||
*
|
||||
* Set value of <i>index</i> dimension to <i>value</i>
|
||||
*/
|
||||
VALUE
|
||||
rb_aset(VALUE self, VALUE index, VALUE value)
|
||||
{
|
||||
int idx = NUM2INT(index);
|
||||
if (idx < 0 || idx >= 4) {
|
||||
rb_raise(rb_eIndexError, "scalar index should be 0...4");
|
||||
}
|
||||
CVSCALAR(self)->val[idx] = NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* sub(val[,mask])
|
||||
*
|
||||
* Return new CvScalar if <i>val</i> is CvScalar or compatible object.
|
||||
* self[I] - val[I]
|
||||
* Or return new CvMat if <i>val</i> is CvMat or subclass.
|
||||
*/
|
||||
VALUE
|
||||
rb_sub(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE val, mask;
|
||||
rb_scan_args(argc, argv, "11", &val, &mask);
|
||||
if (rb_obj_is_kind_of(val, cCvMat::rb_class())) {
|
||||
CvArr *val_ptr = CVARR(val);
|
||||
VALUE dest = Qnil;
|
||||
try {
|
||||
dest = cCvMat::new_object(cvGetSize(val_ptr), cvGetElemType(val_ptr));
|
||||
cvSubRS(val_ptr, *CVSCALAR(self), CVARR(dest), MASK(mask));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
else {
|
||||
CvScalar *src = CVSCALAR(self);
|
||||
CvScalar scl = VALUE_TO_CVSCALAR(val);
|
||||
return new_object(cvScalar(src->val[0] - scl.val[0],
|
||||
src->val[1] - scl.val[1],
|
||||
src->val[2] - scl.val[2],
|
||||
src->val[3] - scl.val[3]));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpeCV::CvScalar:#{self[0]},#{self[1]},#{self[2]},#{self[3]}>"
|
||||
*
|
||||
* Return values by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 6;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:%g,%g,%g,%g>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_aref(self, INT2FIX(0));
|
||||
str[3] = rb_aref(self, INT2FIX(1));
|
||||
str[4] = rb_aref(self, INT2FIX(2));
|
||||
str[5] = rb_aref(self, INT2FIX(3));
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [self[0],self[1],self[2],self[3]]
|
||||
*
|
||||
* Return values by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(4,
|
||||
rb_aref(self, INT2FIX(0)),
|
||||
rb_aref(self, INT2FIX(1)),
|
||||
rb_aref(self, INT2FIX(2)),
|
||||
rb_aref(self, INT2FIX(3)));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVSCALAR(object) = cvScalar(0);
|
||||
return object;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvScalar scalar)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVSCALAR(object) = scalar;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvScalar", rb_cObject);
|
||||
/* CvScalar: class */
|
||||
rb_define_const(opencv, "CvColor", rb_klass);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
||||
rb_define_method(rb_klass, "[]=", RUBY_METHOD_FUNC(rb_aset), 2);
|
||||
rb_define_method(rb_klass, "sub", RUBY_METHOD_FUNC(rb_sub), -1);
|
||||
rb_define_alias(rb_klass, "-", "sub");
|
||||
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
|
||||
rb_define_const(rb_klass, "Black", cCvScalar::new_object(cvScalar(0x0,0x0,0x0)));
|
||||
rb_define_const(rb_klass, "Silver", cCvScalar::new_object(cvScalar(0x0c,0x0c,0x0c)));
|
||||
rb_define_const(rb_klass, "Gray", cCvScalar::new_object(cvScalar(0x80,0x80,0x80)));
|
||||
rb_define_const(rb_klass, "White", cCvScalar::new_object(cvScalar(0xff,0xff,0xff)));
|
||||
rb_define_const(rb_klass, "Maroon", cCvScalar::new_object(cvScalar(0x0,0x0,0x80)));
|
||||
rb_define_const(rb_klass, "Red", cCvScalar::new_object(cvScalar(0x0,0x0,0xff)));
|
||||
rb_define_const(rb_klass, "Purple", cCvScalar::new_object(cvScalar(0x80,0x0,0x80)));
|
||||
rb_define_const(rb_klass, "Fuchsia", cCvScalar::new_object(cvScalar(0xff,0x0,0xff)));
|
||||
rb_define_const(rb_klass, "Green", cCvScalar::new_object(cvScalar(0x0,0x80,0x0)));
|
||||
rb_define_const(rb_klass, "Lime", cCvScalar::new_object(cvScalar(0x0,0xff,0x0)));
|
||||
rb_define_const(rb_klass, "Olive", cCvScalar::new_object(cvScalar(0x0,0x80,0x80)));
|
||||
rb_define_const(rb_klass, "Yellow", cCvScalar::new_object(cvScalar(0x0,0xff,0xff)));
|
||||
rb_define_const(rb_klass, "Navy", cCvScalar::new_object(cvScalar(0x80,0x0,0x0)));
|
||||
rb_define_const(rb_klass, "Blue", cCvScalar::new_object(cvScalar(0xff,0x0,0x0)));
|
||||
rb_define_const(rb_klass, "Teal", cCvScalar::new_object(cvScalar(0x80,0x80,0x0)));
|
||||
rb_define_const(rb_klass, "Aqua", cCvScalar::new_object(cvScalar(0xff,0xff,0x0)));
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSCALAR
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvscalar.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSCALAR_H
|
||||
#define RUBY_OPENCV_CVSCALAR_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSCALAR namespace cCvScalar {
|
||||
#define __NAMESPACE_END_CVSCALAR }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSCALAR
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_aref(VALUE self, VALUE index);
|
||||
VALUE rb_aset(VALUE self, VALUE index, VALUE value);
|
||||
VALUE rb_sub(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
VALUE new_object(CvScalar scalar);
|
||||
|
||||
__NAMESPACE_END_CVSCALAR
|
||||
|
||||
inline CvScalar*
|
||||
CVSCALAR(VALUE object)
|
||||
{
|
||||
CvScalar *ptr;
|
||||
Data_Get_Struct(object, CvScalar, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvScalar
|
||||
VALUE_TO_CVSCALAR(VALUE object)
|
||||
{
|
||||
ID aref_id;
|
||||
if (FIXNUM_P(object)) {
|
||||
return cvScalarAll(FIX2INT(object));
|
||||
}
|
||||
else if (rb_respond_to(object, (aref_id = rb_intern("[]")))) {
|
||||
return cvScalar(NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(0))),
|
||||
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(1))),
|
||||
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(2))),
|
||||
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(3))));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvScalar::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSCALAR_H
|
|
@ -1,648 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvseq.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvseq.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSeq
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSEQ
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
void cvseq_free(void *ptr);
|
||||
|
||||
VALUE rb_klass;
|
||||
// contain sequence-block class
|
||||
st_table *seqblock_klass_table = st_init_numtable();
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
seqblock_class(void *ptr)
|
||||
{
|
||||
VALUE klass;
|
||||
if (!st_lookup(seqblock_klass_table, (st_data_t)ptr, (st_data_t*)&klass)) {
|
||||
rb_raise(rb_eTypeError, "Invalid sequence error.");
|
||||
}
|
||||
return klass;
|
||||
}
|
||||
|
||||
void
|
||||
register_elem_class(CvSeq *seq, VALUE klass)
|
||||
{
|
||||
st_insert(seqblock_klass_table, (st_data_t)seq, (st_data_t)klass);
|
||||
}
|
||||
|
||||
void
|
||||
unregister_elem_class(void *ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
st_delete(seqblock_klass_table, (st_data_t*)&ptr, NULL);
|
||||
unregister_object(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSeq *ptr = ALLOC(CvSeq);
|
||||
return Data_Wrap_Struct(klass, mark_root_object, unregister_elem_class, ptr);
|
||||
}
|
||||
|
||||
CvSeq*
|
||||
create_seq(int seq_flags, size_t header_size, VALUE storage_value)
|
||||
{
|
||||
VALUE klass = Qnil;
|
||||
int eltype = seq_flags & CV_SEQ_ELTYPE_MASK;
|
||||
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
||||
|
||||
switch (eltype) {
|
||||
case CV_SEQ_ELTYPE_POINT:
|
||||
klass = cCvPoint::rb_class();
|
||||
break;
|
||||
case CV_32FC2:
|
||||
klass = cCvPoint2D32f::rb_class();
|
||||
break;
|
||||
case CV_SEQ_ELTYPE_POINT3D:
|
||||
klass = cCvPoint3D32f::rb_class();
|
||||
break;
|
||||
case CV_SEQ_ELTYPE_CODE:
|
||||
case CV_SEQ_ELTYPE_INDEX:
|
||||
klass = rb_cFixnum;
|
||||
break;
|
||||
case CV_SEQ_ELTYPE_PPOINT: // or CV_SEQ_ELTYPE_PTR:
|
||||
// Not supported
|
||||
rb_raise(rb_eArgError, "seq_flags %d is not supported.", eltype);
|
||||
break;
|
||||
default:
|
||||
seq_flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_GENERIC;
|
||||
klass = cCvPoint::rb_class();
|
||||
break;
|
||||
}
|
||||
|
||||
int mat_type = CV_MAT_TYPE(seq_flags);
|
||||
size_t elem_size = (size_t)(CV_ELEM_SIZE(mat_type));
|
||||
CvSeq* seq = NULL;
|
||||
try {
|
||||
seq = cvCreateSeq(seq_flags, header_size, elem_size, CVMEMSTORAGE(storage_value));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
register_elem_class(seq, klass);
|
||||
register_root_object(seq, storage_value);
|
||||
|
||||
return seq;
|
||||
}
|
||||
|
||||
VALUE
|
||||
class2seq_flags_value(VALUE klass) {
|
||||
int seq_flags;
|
||||
if (klass == cCvPoint::rb_class()) {
|
||||
seq_flags = CV_SEQ_ELTYPE_POINT;
|
||||
}
|
||||
else if (klass == cCvPoint2D32f::rb_class()) {
|
||||
seq_flags = CV_32FC2;
|
||||
}
|
||||
else if (klass == cCvPoint3D32f::rb_class()) {
|
||||
seq_flags = CV_SEQ_ELTYPE_POINT3D;
|
||||
}
|
||||
else if (klass == rb_cFixnum) {
|
||||
seq_flags = CV_SEQ_ELTYPE_INDEX;
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eTypeError, "unexpected type: %s", rb_class2name(klass));
|
||||
}
|
||||
|
||||
return INT2NUM(seq_flags | CV_SEQ_KIND_GENERIC);
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*
|
||||
* @overload new(seq_flags, storage = nil)
|
||||
* @param [Fixnum] seq_flags Flags of the created sequence, which are combinations of
|
||||
* the element types and sequence types.
|
||||
* - Element type:
|
||||
* - <tt>CV_SEQ_ELTYPE_POINT</tt>: {CvPoint}
|
||||
* - <tt>CV_32FC2</tt>: {CvPoint2D32f}
|
||||
* - <tt>CV_SEQ_ELTYPE_POINT3D</tt>: {CvPoint3D32f}
|
||||
* - <tt>CV_SEQ_ELTYPE_INDEX</tt>: Fixnum
|
||||
* - <tt>CV_SEQ_ELTYPE_CODE</tt>: Fixnum (Freeman code)
|
||||
* - Sequence type:
|
||||
* - <tt>CV_SEQ_KIND_GENERIC</tt>: Generic sequence
|
||||
* - <tt>CV_SEQ_KIND_CURVE</tt>: Curve
|
||||
* @param [CvMemStorage] storage Sequence location
|
||||
* @return [CvSeq] self
|
||||
* @opencv_func cvCreateSeq
|
||||
* @example
|
||||
* seq1 = CvSeq.new(CV_SEQ_ELTYPE_INDEX)
|
||||
* seq1 << 1
|
||||
* seq1 << CvPoint.new(1, 2) #=> TypeError
|
||||
*
|
||||
* seq2 = CvSeq.new(CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_CURVE)
|
||||
* seq2 << CvPoint.new(1, 2)
|
||||
* seq2 << 3 #=> TypeError
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE seq_flags_value, storage_value;
|
||||
rb_scan_args(argc, argv, "11", &seq_flags_value, &storage_value);
|
||||
int seq_flags = 0;
|
||||
|
||||
if (TYPE(seq_flags_value) == T_CLASS) { // To maintain backward compatibility
|
||||
seq_flags_value = class2seq_flags_value(seq_flags_value);
|
||||
}
|
||||
Check_Type(seq_flags_value, T_FIXNUM);
|
||||
seq_flags = FIX2INT(seq_flags_value);
|
||||
|
||||
DATA_PTR(self) = create_seq(seq_flags, sizeof(CvSeq), storage_value);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* total -> int
|
||||
*
|
||||
* Return total number of sequence-block.
|
||||
*/
|
||||
VALUE
|
||||
rb_total(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSEQ(self)->total);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* empty? -> true or false.
|
||||
*
|
||||
* Return <tt>true</tt> if contain no object, otherwize return <tt>false</tt>.
|
||||
*/
|
||||
VALUE
|
||||
rb_empty_q(VALUE self)
|
||||
{
|
||||
return CVSEQ(self)->total == 0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* [<i>index</i>] -> obj or nil
|
||||
*
|
||||
* Return sequence-block at <i>index</i>.
|
||||
*/
|
||||
VALUE
|
||||
rb_aref(VALUE self, VALUE index)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
int idx = NUM2INT(index);
|
||||
if (seq->total == 0) {
|
||||
return Qnil;
|
||||
}
|
||||
if (idx >= seq->total) {
|
||||
rb_raise(rb_eIndexError, "index %d out of sequence", idx);
|
||||
}
|
||||
|
||||
VALUE result = Qnil;
|
||||
try {
|
||||
VALUE klass = seqblock_class(seq);
|
||||
if (RTEST(rb_class_inherited_p(klass, rb_cInteger))) {
|
||||
result = INT2NUM(*CV_GET_SEQ_ELEM(int, seq, idx));
|
||||
}
|
||||
else {
|
||||
result = REFER_OBJECT(klass, cvGetSeqElem(seq, idx), self);
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* first -> obj or nil
|
||||
*
|
||||
* Return first sequence-block.
|
||||
*/
|
||||
VALUE
|
||||
rb_first(VALUE self)
|
||||
{
|
||||
return rb_aref(self, INT2FIX(0));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* last -> obj or nil
|
||||
*
|
||||
* Return last sequence-block.
|
||||
*/
|
||||
VALUE
|
||||
rb_last(VALUE self)
|
||||
{
|
||||
return rb_aref(self, INT2FIX(-1));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* h_prev -> seq or nil
|
||||
*
|
||||
* Return the sequence horizontally located in previous.
|
||||
* Return <tt>nil</tt> if not existing.
|
||||
*/
|
||||
VALUE
|
||||
rb_h_prev(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->h_prev)
|
||||
return new_sequence(CLASS_OF(self), seq->h_prev, seqblock_class(seq), lookup_root_object(seq));
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* h_next -> seq or nil
|
||||
*
|
||||
* Return the sequence horizontally located in next.
|
||||
* Return <tt>nil</tt> if not existing.
|
||||
*/
|
||||
VALUE
|
||||
rb_h_next(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->h_next)
|
||||
return new_sequence(CLASS_OF(self), seq->h_next, seqblock_class(seq), lookup_root_object(seq));
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* v_prev -> seq or nil
|
||||
*
|
||||
* Return the sequence vertically located in previous.
|
||||
* Return <tt>nil</tt> if not existing.
|
||||
*/
|
||||
VALUE
|
||||
rb_v_prev(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->v_prev)
|
||||
return new_sequence(CLASS_OF(self), seq->v_prev, seqblock_class(seq), lookup_root_object(seq));
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* v_next -> seq or nil
|
||||
*
|
||||
* Return the sequence vertically located in next.
|
||||
* Return <tt>nil</tt> if not existing.
|
||||
*/
|
||||
VALUE
|
||||
rb_v_next(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->v_next)
|
||||
return new_sequence(CLASS_OF(self), seq->v_next, seqblock_class(seq), lookup_root_object(seq));
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_seq_push(VALUE self, VALUE args, int flag)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
VALUE klass = seqblock_class(seq);
|
||||
volatile void *elem = NULL;
|
||||
int len = RARRAY_LEN(args);
|
||||
for (int i = 0; i < len; i++) {
|
||||
VALUE object = RARRAY_PTR(args)[i];
|
||||
if (rb_obj_is_kind_of(object, klass)) {
|
||||
if (rb_obj_is_kind_of(object, rb_cInteger)) {
|
||||
volatile int int_elem = NUM2INT(object);
|
||||
elem = &int_elem;
|
||||
}
|
||||
else if (rb_obj_is_kind_of(object, rb_cNumeric)) {
|
||||
volatile double double_elem = NUM2DBL(object);
|
||||
elem = &double_elem;
|
||||
}
|
||||
else {
|
||||
elem = (void*)DATA_PTR(object);
|
||||
}
|
||||
try {
|
||||
if (flag == CV_FRONT)
|
||||
cvSeqPushFront(seq, (const void*)elem);
|
||||
else
|
||||
cvSeqPush(seq, (const void*)elem);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
else if ((rb_obj_is_kind_of(object, rb_klass) == Qtrue) &&
|
||||
RTEST(rb_class_inherited_p(seqblock_class(CVSEQ(object)), klass))) { // object is CvSeq
|
||||
void *buffer = NULL;
|
||||
try {
|
||||
buffer = cvCvtSeqToArray(CVSEQ(object), rb_cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
|
||||
cvSeqPushMulti(seq, buffer, CVSEQ(object)->total, flag);
|
||||
cvFree(&buffer);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
if (buffer != NULL)
|
||||
cvFree(&buffer);
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eTypeError, "arguments should be %s or %s which includes %s.",
|
||||
rb_class2name(klass), rb_class2name(rb_klass), rb_class2name(klass));
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* push(obj, ...) -> self
|
||||
*
|
||||
* Append - Pushes the given object(s) on the end of this sequence. This expression return the sequence itself,
|
||||
* so several append may be chained together.
|
||||
*/
|
||||
VALUE
|
||||
rb_push(VALUE self, VALUE args)
|
||||
{
|
||||
return rb_seq_push(self, args, CV_BACK);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* pop -> obj or nil
|
||||
*
|
||||
* Remove the last sequence-block from <i>self</i> and return it,
|
||||
* or <tt>nil</tt> if the sequence is empty.
|
||||
*/
|
||||
VALUE
|
||||
rb_pop(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->total == 0)
|
||||
return Qnil;
|
||||
|
||||
VALUE object = Qnil;
|
||||
VALUE klass = seqblock_class(seq);
|
||||
try {
|
||||
if (klass == rb_cFixnum) {
|
||||
int n = 0;
|
||||
cvSeqPop(seq, &n);
|
||||
object = INT2FIX(n);
|
||||
}
|
||||
else {
|
||||
object = GENERIC_OBJECT(klass, malloc(seq->elem_size));
|
||||
cvSeqPop(seq, DATA_PTR(object));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* clear -> self
|
||||
*
|
||||
* Clears sequence. Removes all elements from the sequence.
|
||||
*/
|
||||
VALUE
|
||||
rb_clear(VALUE self)
|
||||
{
|
||||
try {
|
||||
cvClearSeq(CVSEQ(self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* unshift -> self
|
||||
*
|
||||
* Prepends objects to the front of sequence. other elements up one.
|
||||
*/
|
||||
VALUE
|
||||
rb_unshift(VALUE self, VALUE args)
|
||||
{
|
||||
VALUE result = Qnil;
|
||||
try {
|
||||
result = rb_seq_push(self, args, CV_FRONT);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* shift -> obj or nil
|
||||
*
|
||||
* Returns the first element of <i>self</i> and removes it (shifting all other elements down by one). Returns <tt>nil</tt> if the array is empty.
|
||||
*/
|
||||
VALUE
|
||||
rb_shift(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->total == 0)
|
||||
return Qnil;
|
||||
|
||||
VALUE object = Qnil;
|
||||
try {
|
||||
if (seqblock_class(seq) == rb_cFixnum) {
|
||||
int n = 0;
|
||||
cvSeqPopFront(seq, &n);
|
||||
object = INT2NUM(n);
|
||||
}
|
||||
else {
|
||||
object = GENERIC_OBJECT(seqblock_class(seq), malloc(seq->elem_size));
|
||||
cvSeqPopFront(seq, DATA_PTR(object));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* each {|obj| ... } -> self
|
||||
*
|
||||
* Calls block once for each sequence-block in <i>self</i>,
|
||||
* passing that sequence-block as a parameter.
|
||||
* seq = CvSeq.new(CvIndex)
|
||||
* seq.push(5, 6, 7)
|
||||
* seq.each {|x| print x, " -- " }
|
||||
* produces:
|
||||
* 5 -- 6 -- 7 --
|
||||
*/
|
||||
VALUE
|
||||
rb_each(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
if (seq->total > 0) {
|
||||
VALUE klass = seqblock_class(seq);
|
||||
try {
|
||||
if (klass == rb_cFixnum)
|
||||
for (int i = 0; i < seq->total; ++i)
|
||||
rb_yield(INT2NUM(*CV_GET_SEQ_ELEM(int, seq, i)));
|
||||
else
|
||||
for (int i = 0; i < seq->total; ++i)
|
||||
rb_yield(REFER_OBJECT(klass, cvGetSeqElem(seq, i), self));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* each_index {|index| ... } -> self
|
||||
*
|
||||
* Same as CvSeq#each, but passes the index of the element instead of the element itself.
|
||||
*/
|
||||
VALUE
|
||||
rb_each_index(VALUE self)
|
||||
{
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
for(int i = 0; i < seq->total; ++i)
|
||||
rb_yield(INT2NUM(i));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* insert(index,obj) -> self
|
||||
*
|
||||
* Inserts the given values before element with the given index (which may be negative).
|
||||
*/
|
||||
VALUE
|
||||
rb_insert(VALUE self, VALUE index, VALUE object)
|
||||
{
|
||||
Check_Type(index, T_FIXNUM);
|
||||
CvSeq *seq = CVSEQ(self);
|
||||
VALUE klass = seqblock_class(seq);
|
||||
if (CLASS_OF(object) != klass)
|
||||
rb_raise(rb_eTypeError, "arguments should be %s.", rb_class2name(klass));
|
||||
try {
|
||||
if (klass == rb_cFixnum) {
|
||||
int n = NUM2INT(object);
|
||||
cvSeqInsert(seq, NUM2INT(index), &n);
|
||||
}
|
||||
else
|
||||
cvSeqInsert(seq, NUM2INT(index), DATA_PTR(object));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* remove(index) -> obj or nil
|
||||
*
|
||||
* Deletes the elements at the specified index.
|
||||
*/
|
||||
VALUE
|
||||
rb_remove(VALUE self, VALUE index)
|
||||
{
|
||||
try {
|
||||
cvSeqRemove(CVSEQ(self), NUM2INT(index));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_sequence(VALUE klass, CvSeq *seq, VALUE element_klass, VALUE storage)
|
||||
{
|
||||
register_root_object(seq, storage);
|
||||
if (!NIL_P(element_klass))
|
||||
register_elem_class(seq, element_klass);
|
||||
return Data_Wrap_Struct(klass, mark_root_object, unregister_elem_class, seq);
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvSeq", rb_cObject);
|
||||
rb_include_module(rb_klass, rb_mEnumerable);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "total", RUBY_METHOD_FUNC(rb_total), 0);
|
||||
rb_define_alias(rb_klass, "length", "total");
|
||||
rb_define_alias(rb_klass, "size", "total");
|
||||
rb_define_method(rb_klass, "empty?", RUBY_METHOD_FUNC(rb_empty_q), 0);
|
||||
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
||||
rb_define_method(rb_klass, "first", RUBY_METHOD_FUNC(rb_first), 0);
|
||||
rb_define_method(rb_klass, "last", RUBY_METHOD_FUNC(rb_last), 0);
|
||||
|
||||
rb_define_method(rb_klass, "h_prev", RUBY_METHOD_FUNC(rb_h_prev), 0);
|
||||
rb_define_method(rb_klass, "h_next", RUBY_METHOD_FUNC(rb_h_next), 0);
|
||||
rb_define_method(rb_klass, "v_prev", RUBY_METHOD_FUNC(rb_v_prev), 0);
|
||||
rb_define_method(rb_klass, "v_next", RUBY_METHOD_FUNC(rb_v_next), 0);
|
||||
|
||||
rb_define_method(rb_klass, "push", RUBY_METHOD_FUNC(rb_push), -2);
|
||||
rb_define_alias(rb_klass, "<<", "push");
|
||||
rb_define_method(rb_klass, "pop", RUBY_METHOD_FUNC(rb_pop), 0);
|
||||
rb_define_method(rb_klass, "unshift", RUBY_METHOD_FUNC(rb_unshift), -2);
|
||||
rb_define_alias(rb_klass, "push_front", "unshift");
|
||||
rb_define_method(rb_klass, "shift", RUBY_METHOD_FUNC(rb_shift), 0);
|
||||
rb_define_alias(rb_klass, "pop_front", "shift");
|
||||
rb_define_method(rb_klass, "each", RUBY_METHOD_FUNC(rb_each), 0);
|
||||
rb_define_method(rb_klass, "each_index", RUBY_METHOD_FUNC(rb_each_index), 0);
|
||||
rb_define_method(rb_klass, "insert", RUBY_METHOD_FUNC(rb_insert), 2);
|
||||
rb_define_method(rb_klass, "remove", RUBY_METHOD_FUNC(rb_remove), 1);
|
||||
rb_define_alias(rb_klass, "delete_at", "remove");
|
||||
rb_define_method(rb_klass, "clear", RUBY_METHOD_FUNC(rb_clear), 0);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSEQ
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvseq.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSEQ_H
|
||||
#define RUBY_OPENCV_CVSEQ_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSEQ namespace cCvSeq {
|
||||
#define __NAMESPACE_END_CVSEQ }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSEQ
|
||||
|
||||
VALUE rb_class();
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE seqblock_class(void *ptr);
|
||||
void register_elem_class(CvSeq *seq, VALUE klass);
|
||||
void unregister_elem_class(void *ptr);
|
||||
CvSeq* create_seq(int seq_flags, size_t header_size, VALUE storage_value);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_total(VALUE self);
|
||||
VALUE rb_empty_q(VALUE self);
|
||||
VALUE rb_aref(VALUE self, VALUE index);
|
||||
VALUE rb_first(VALUE self);
|
||||
VALUE rb_last(VALUE self);
|
||||
VALUE rb_h_prev(VALUE self);
|
||||
VALUE rb_h_next(VALUE self);
|
||||
VALUE rb_v_prev(VALUE self);
|
||||
VALUE rb_v_next(VALUE self);
|
||||
VALUE rb_push(VALUE self, VALUE args);
|
||||
VALUE rb_pop(VALUE self);
|
||||
VALUE rb_unshift(VALUE self, VALUE args);
|
||||
VALUE rb_shift(VALUE self);
|
||||
VALUE rb_each(VALUE self);
|
||||
VALUE rb_each_index(VALUE self);
|
||||
VALUE rb_insert(VALUE self, VALUE index, VALUE object);
|
||||
VALUE rb_remove(VALUE self, VALUE index);
|
||||
VALUE rb_clear(VALUE self);
|
||||
|
||||
VALUE new_object(CvSeq *seq, VALUE klass);
|
||||
VALUE new_object(CvSeq *seq, VALUE klass, VALUE storage);
|
||||
VALUE new_sequence(VALUE klass, CvSeq *seq, VALUE element_klass, VALUE storage);
|
||||
|
||||
__NAMESPACE_END_CVSEQ
|
||||
|
||||
inline CvSeq*
|
||||
CVSEQ(VALUE object)
|
||||
{
|
||||
CvSeq *ptr;
|
||||
Data_Get_Struct(object, CvSeq, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvSeq*
|
||||
CVSEQ_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvSeq::rb_class()))
|
||||
raise_typeerror(object, cCvSeq::rb_class());
|
||||
return CVSEQ(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSEQ_H
|
|
@ -1,227 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsize.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvsize.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSize
|
||||
*
|
||||
* This class means one size on X axis Y axis.
|
||||
* X and Y takes the value of the Fixnum.
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvSize {
|
||||
* int width;
|
||||
* int height;
|
||||
* }
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSIZE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* compatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvSize. Return true if object have method #width and #height.
|
||||
*
|
||||
* For example.
|
||||
* class MySize
|
||||
* def width
|
||||
* 10
|
||||
* end
|
||||
* def height
|
||||
* 20
|
||||
* end
|
||||
* end
|
||||
* mp = MySize.new
|
||||
* CvSize.compatible?(mp) #=> true
|
||||
* CvSize.new(mp) #=> same as CvSize(10, 20)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSize *ptr;
|
||||
return Data_Make_Struct(klass, CvSize, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new
|
||||
* new(obj)
|
||||
* new(width, height)
|
||||
*
|
||||
* Create new size of 2D, (width, height). It is dropped below the decimal point.
|
||||
*
|
||||
* new() is same as new(0, 0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_i, obj.y.to_i)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvSize *self_ptr = CVSIZE(self);
|
||||
switch (argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvSize size = VALUE_TO_CVSIZE(argv[0]);
|
||||
self_ptr->width = size.width;
|
||||
self_ptr->height = size.height;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
self_ptr->width = NUM2INT(argv[0]);
|
||||
self_ptr->height = NUM2INT(argv[1]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_width(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSIZE(self)->width);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* width = val
|
||||
*
|
||||
* Set x-axis size, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_width(VALUE self, VALUE x)
|
||||
{
|
||||
CVSIZE(self)->width = NUM2INT(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of yaxis.
|
||||
*/
|
||||
VALUE
|
||||
rb_height(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSIZE(self)->height);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* height = val
|
||||
*
|
||||
* Set y-axis size, return self.
|
||||
* It is dropped below the decimal point.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_height(VALUE self, VALUE y)
|
||||
{
|
||||
CVSIZE(self)->height = NUM2INT(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpenCV::CvSize:widthxheight>"
|
||||
*
|
||||
* Return width and height by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 4;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:%dx%d>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_width(self);
|
||||
str[3] = rb_height(self);
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [width, height]
|
||||
*
|
||||
* Return width and height by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(2, rb_width(self), rb_height(self));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVSIZE(object) = cvSize(0, 0);
|
||||
return object;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvSize size)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVSIZE(object) = size;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvSize", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
||||
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
||||
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
||||
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
||||
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSIZE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsize.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSIZE_H
|
||||
#define RUBY_OPENCV_CVSIZE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSIZE namespace cCvSize {
|
||||
#define __NAMESPACE_END_CVSIZE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSIZE
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_width(VALUE self);
|
||||
VALUE rb_set_width(VALUE self, VALUE width);
|
||||
VALUE rb_height(VALUE self);
|
||||
VALUE rb_set_height(VALUE self, VALUE height);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object();
|
||||
VALUE new_object(CvSize size);
|
||||
|
||||
__NAMESPACE_END_CVSIZE
|
||||
|
||||
inline CvSize*
|
||||
CVSIZE(VALUE object)
|
||||
{
|
||||
CvSize *ptr;
|
||||
Data_Get_Struct(object, CvSize, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvSize
|
||||
VALUE_TO_CVSIZE(VALUE object)
|
||||
{
|
||||
if (cCvSize::rb_compatible_q(cCvSize::rb_class(), object)) {
|
||||
return cvSize(NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSIZE_H
|
|
@ -1,215 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsize2d32f.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvsize2d32f.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSize2D32f
|
||||
*
|
||||
* This class means one size on X axis Y axis.
|
||||
* X and Y takes the value of the Float.
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvSize2D32f {
|
||||
* float width;
|
||||
* float height;
|
||||
* } CvSize2D32f;
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSIZE2D32F
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* compatible?(obj)
|
||||
*
|
||||
* Return compatibility to CvSize2D32f. Return true if object have method #width and #height.
|
||||
*
|
||||
* For example.
|
||||
* class MySize
|
||||
* def width
|
||||
* 10.1
|
||||
* end
|
||||
* def height
|
||||
* 20.2
|
||||
* end
|
||||
* end
|
||||
* mp = MySize.new
|
||||
* CvSize2D32f.compatible?(mp) #=> true
|
||||
* CvSize2D32f.new(mp) #=> same as CvSize2D32f.new(10.1, 20.2)
|
||||
*/
|
||||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSize2D32f *ptr;
|
||||
return Data_Make_Struct(klass, CvSize2D32f, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new
|
||||
* new(obj)
|
||||
* new(width, height)
|
||||
*
|
||||
* Create new size of 2D, (width, height).
|
||||
*
|
||||
* new() is same as new(0.0, 0.0)
|
||||
*
|
||||
* new(obj) is same as new(obj.x.to_f, obj.y.to_f)
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvSize2D32f *self_ptr = CVSIZE2D32F(self);
|
||||
switch(argc){
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
CvSize2D32f size = VALUE_TO_CVSIZE2D32F(argv[0]);
|
||||
self_ptr->width = size.width;
|
||||
self_ptr->height = size.height;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
self_ptr->width = NUM2DBL(argv[0]);
|
||||
self_ptr->height = NUM2DBL(argv[1]);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of x-axis.
|
||||
*/
|
||||
VALUE
|
||||
rb_width(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVSIZE2D32F(self)->width);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* width = val
|
||||
*
|
||||
* Set x-axis size, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_width(VALUE self, VALUE x)
|
||||
{
|
||||
CVSIZE2D32F(self)->width = NUM2DBL(x);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of yaxis.
|
||||
*/
|
||||
VALUE
|
||||
rb_height(VALUE self)
|
||||
{
|
||||
return rb_float_new(CVSIZE2D32F(self)->height);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* height = val
|
||||
*
|
||||
* Set y-axis size, return self.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_height(VALUE self, VALUE y)
|
||||
{
|
||||
CVSIZE2D32F(self)->height = NUM2DBL(y);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_s -> "<OpenCV::CvSize2D32f:widthxheight>"
|
||||
*
|
||||
* Return width and height by String.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_s(VALUE self)
|
||||
{
|
||||
const int i = 4;
|
||||
VALUE str[i];
|
||||
str[0] = rb_str_new2("<%s:%gx%g>");
|
||||
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
||||
str[2] = rb_width(self);
|
||||
str[3] = rb_height(self);
|
||||
return rb_f_sprintf(i, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_ary -> [width, height]
|
||||
*
|
||||
* Return width and height by Array.
|
||||
*/
|
||||
VALUE
|
||||
rb_to_ary(VALUE self)
|
||||
{
|
||||
return rb_ary_new3(2, rb_width(self), rb_height(self));
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvSize2D32f size)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVSIZE2D32F(object) = size;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvSize2D32f", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
||||
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
||||
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
||||
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
||||
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSIZE2D32F
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsize2d32f.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSIZE2D32F_H
|
||||
#define RUBY_OPENCV_CVSIZE2D32F_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSIZE2D32F namespace cCvSize2D32f {
|
||||
#define __NAMESPACE_END_CVSIZE2D32F }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSIZE2D32F
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_width(VALUE self);
|
||||
VALUE rb_set_width(VALUE self, VALUE width);
|
||||
VALUE rb_height(VALUE self);
|
||||
VALUE rb_set_height(VALUE self, VALUE height);
|
||||
|
||||
VALUE rb_to_s(VALUE self);
|
||||
VALUE rb_to_ary(VALUE self);
|
||||
|
||||
VALUE new_object(CvSize2D32f size);
|
||||
|
||||
__NAMESPACE_END_CVSIZE2D32F
|
||||
|
||||
inline CvSize2D32f*
|
||||
CVSIZE2D32F(VALUE object)
|
||||
{
|
||||
CvSize2D32f *ptr;
|
||||
Data_Get_Struct(object, CvSize2D32f, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvSize2D32f
|
||||
VALUE_TO_CVSIZE2D32F(VALUE object)
|
||||
{
|
||||
if (cCvSize2D32f::rb_compatible_q(cCvSize2D32f::rb_class(), object)) {
|
||||
return cvSize2D32f(NUM2DBL(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize2D32f::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSIZE2D32F_H
|
|
@ -1,126 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvslice.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvslice.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSlice
|
||||
*
|
||||
* C structure is here, very simple.
|
||||
* typdef struct CvSlice {
|
||||
* int start_index;
|
||||
* int end_index;
|
||||
* } CvSlice;
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSLICE
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSlice *ptr;
|
||||
return Data_Make_Struct(klass, CvSlice, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* new(start, end)
|
||||
*
|
||||
* Create new slice object.
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(VALUE self, VALUE start, VALUE end)
|
||||
{
|
||||
CvSlice *self_ptr = CVSLICE(self);
|
||||
self_ptr->start_index = NUM2INT(start);
|
||||
self_ptr->end_index = NUM2INT(end);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* start_index
|
||||
*
|
||||
*/
|
||||
VALUE
|
||||
rb_start_index_aref(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSLICE(self)->start_index);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* end_index
|
||||
*
|
||||
*/
|
||||
VALUE
|
||||
rb_end_index_aref(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSLICE(self)->end_index);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* start_index = index
|
||||
*
|
||||
*/
|
||||
VALUE
|
||||
rb_start_index_aset(VALUE self, VALUE index)
|
||||
{
|
||||
CVSLICE(self)->start_index = NUM2INT(index);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* end_index = index
|
||||
*
|
||||
*/
|
||||
VALUE
|
||||
rb_end_index_aset(VALUE self, VALUE index)
|
||||
{
|
||||
CVSLICE(self)->end_index = NUM2INT(index);
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvSlice", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), 2);
|
||||
rb_define_method(rb_klass, "start_index", RUBY_METHOD_FUNC(rb_start_index_aref), 0);
|
||||
rb_define_method(rb_klass, "end_index", RUBY_METHOD_FUNC(rb_end_index_aref), 0);
|
||||
rb_define_method(rb_klass, "start_index=", RUBY_METHOD_FUNC(rb_start_index_aset), 1);
|
||||
rb_define_method(rb_klass, "end_index=", RUBY_METHOD_FUNC(rb_end_index_aset), 1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSLICE
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvslice.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSLICE_H
|
||||
#define RUBY_OPENCV_CVSLICE_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSLICE namespace cCvSlice {
|
||||
#define __NAMESPACE_END_CVSLICE }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSLICE
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(VALUE self, VALUE start, VALUE end);
|
||||
VALUE rb_start_index_aref(VALUE self);
|
||||
VALUE rb_end_index_aref(VALUE self);
|
||||
VALUE rb_start_index_aset(VALUE self, VALUE index);
|
||||
VALUE rb_end_index_aset(VALUE self, VALUE index);
|
||||
|
||||
__NAMESPACE_END_CVSLICE
|
||||
|
||||
inline CvSlice*
|
||||
CVSLICE(VALUE object)
|
||||
{
|
||||
CvSlice *ptr;
|
||||
Data_Get_Struct(object, CvSlice, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvSlice
|
||||
VALUE_TO_CVSLICE(VALUE object)
|
||||
{
|
||||
if (rb_obj_is_kind_of(object, cCvSlice::rb_class())) {
|
||||
CvSlice* ptr = CVSLICE(object);
|
||||
return *ptr;
|
||||
}
|
||||
else if (rb_obj_is_kind_of(object, rb_cRange)) {
|
||||
return cvSlice(NUM2INT(rb_funcall(object, rb_intern("begin"), 0)),
|
||||
rb_funcall(object, rb_intern("exclude_end?"), 0) ? NUM2INT(rb_funcall(object, rb_intern("end"), 0)) : NUM2INT(rb_funcall(object, rb_intern("end"), 0)) - 1);
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSlice::rb_class());
|
||||
}
|
||||
throw "Should never reach here";
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSLICE_H
|
|
@ -1,208 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsurfparams.cpp -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#include "cvsurfparams.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSURFParams
|
||||
*
|
||||
* C structure is here.
|
||||
* typedef struct CvSURFParams {
|
||||
* int extended;
|
||||
* double hessianThreshold;
|
||||
* int nOctaves;
|
||||
* int nOctaveLayers;
|
||||
* } CvSURFParams;
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSURFPARAMS
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSURFParams *ptr;
|
||||
return Data_Make_Struct(klass, CvSURFParams, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a CvSURFParams
|
||||
*
|
||||
* @overload CvSURFParams.new(hessian_threshold, extended = false, n_octaves = 3, n_octave_layers = 4)
|
||||
* @param hessian_threshold [Number]
|
||||
* @param extended [Boolean] If <tt>true</tt>, exteneded descriptors (128 elements each),
|
||||
* otherwise basic descriptors (64 elements each)
|
||||
* @param n_octaves [Integer] Number of octaves to be used for extraction
|
||||
* @param n_octave_layers [Integer] Number of layers within each octave
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
CvSURFParams *self_ptr = CVSURFPARAMS(self);
|
||||
VALUE h_thresh, ext, noct, noctl;
|
||||
rb_scan_args(argc, argv, "13", &h_thresh, &ext, &noct, &noctl);
|
||||
|
||||
self_ptr->hessianThreshold = NUM2DBL(h_thresh);
|
||||
self_ptr->extended = NIL_P(ext) ? 0 : BOOL2INT(ext);
|
||||
self_ptr->nOctaves = NIL_P(noct) ? 3 : NUM2INT(noct);
|
||||
self_ptr->nOctaveLayers = NIL_P(noctl) ? 4 : NUM2INT(noctl);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hessian_threshold -> number
|
||||
* Return threshold of hessian
|
||||
*/
|
||||
VALUE
|
||||
rb_get_hessian_threshold(VALUE self)
|
||||
{
|
||||
return DBL2NUM(CVSURFPARAMS(self)->hessianThreshold);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hessian_threshold = <i>value</i>
|
||||
*
|
||||
* Set threshold of hessian to <i>value</i>
|
||||
*/
|
||||
VALUE
|
||||
rb_set_hessian_threshold(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPARAMS(self)->hessianThreshold = NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* extended -> bool
|
||||
* Return the type of descripters
|
||||
* false: basic descriptors (64 elements each)
|
||||
* true : exteneded descriptors (128 elements each)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_extended(VALUE self)
|
||||
{
|
||||
return INT2BOOL(CVSURFPARAMS(self)->extended);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* extended = <i>value</i>
|
||||
* Set the type of descripters
|
||||
* false: basic descriptors (64 elements each)
|
||||
* true : exteneded descriptors (128 elements each)
|
||||
*/
|
||||
VALUE
|
||||
rb_set_extended(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPARAMS(self)->extended = BOOL2INT(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* n_octaves -> fixnum
|
||||
* Return the number of octaves to be used for extraction
|
||||
*/
|
||||
VALUE
|
||||
rb_get_n_octaves(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSURFPARAMS(self)->nOctaves);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* n_octaves = <i>value</i>
|
||||
* Set the number of octaves to be used for extraction
|
||||
*/
|
||||
VALUE
|
||||
rb_set_n_octaves(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPARAMS(self)->nOctaves = NUM2INT(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* n_octave_layers -> fixnum
|
||||
* Return the number of layers within each octave
|
||||
*/
|
||||
VALUE
|
||||
rb_get_n_octave_layers(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSURFPARAMS(self)->nOctaveLayers);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* n_octave_layers = <i>value</i>
|
||||
* Set the number of layers within each octave
|
||||
*/
|
||||
VALUE
|
||||
rb_set_n_octave_layers(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPARAMS(self)->nOctaveLayers = NUM2INT(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
return rb_allocate(rb_klass);
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvSURFParams* cvsurfparams)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
CvSURFParams *ptr = CVSURFPARAMS(object);
|
||||
ptr = cvsurfparams;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvSURFParams", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "hessian_threshold", RUBY_METHOD_FUNC(rb_get_hessian_threshold), 0);
|
||||
rb_define_method(rb_klass, "hessian_threshold=", RUBY_METHOD_FUNC(rb_set_hessian_threshold), 1);
|
||||
rb_define_method(rb_klass, "extended", RUBY_METHOD_FUNC(rb_get_extended), 0);
|
||||
rb_define_method(rb_klass, "extended=", RUBY_METHOD_FUNC(rb_set_extended), 1);
|
||||
rb_define_method(rb_klass, "n_octaves", RUBY_METHOD_FUNC(rb_get_n_octaves), 0);
|
||||
rb_define_method(rb_klass, "n_octaves=", RUBY_METHOD_FUNC(rb_set_n_octaves), 1);
|
||||
rb_define_method(rb_klass, "n_octave_layers", RUBY_METHOD_FUNC(rb_get_n_octave_layers), 0);
|
||||
rb_define_method(rb_klass, "n_octave_layers=", RUBY_METHOD_FUNC(rb_set_n_octave_layers), 1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSURFPARAMS
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsurfparams.h -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSURFPARAMS_H
|
||||
#define RUBY_OPENCV_CVSURFPARAMS_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSURFPARAMS namespace cCvSURFParams {
|
||||
#define __NAMESPACE_END_CVSURFPARAMS }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSURFPARAMS
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_get_hessian_threshold(VALUE self);
|
||||
VALUE rb_set_hessian_threshold(VALUE self, VALUE value);
|
||||
VALUE rb_get_extended(VALUE self);
|
||||
VALUE rb_set_extended(VALUE self, VALUE value);
|
||||
VALUE rb_get_n_octaves(VALUE self);
|
||||
VALUE rb_set_n_octaves(VALUE self, VALUE value);
|
||||
VALUE rb_get_n_octave_layers(VALUE self);
|
||||
VALUE rb_set_n_octave_layers(VALUE self, VALUE value);
|
||||
|
||||
VALUE new_object(CvSURFPoint *cvsurfparams);
|
||||
|
||||
__NAMESPACE_END_CVSURFPARAMS
|
||||
|
||||
inline CvSURFParams*
|
||||
CVSURFPARAMS(VALUE object)
|
||||
{
|
||||
CvSURFParams* ptr;
|
||||
Data_Get_Struct(object, CvSURFParams, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvSURFParams*
|
||||
CVSURFPARAMS_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvSURFParams::rb_class()))
|
||||
raise_typeerror(object, cCvSURFParams::rb_class());
|
||||
return CVSURFPARAMS(object);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSURFPARAMS_H
|
|
@ -1,246 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsurfpoint.cpp -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#include "cvsurfpoint.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvSURFPoint
|
||||
*
|
||||
* C structure is here.
|
||||
* typedef struct CvSURFPoint {
|
||||
* CvPoint2D32f pt; // position of the feature within the image
|
||||
* int laplacian; // -1, 0 or +1. sign of the laplacian at the point.
|
||||
* // can be used to speedup feature comparison
|
||||
* // (normally features with laplacians of different
|
||||
* // signs can not match)
|
||||
* int size; // size of the feature
|
||||
* float dir; // orientation of the feature: 0..360 degrees
|
||||
* float hessian; // value of the hessian (can be used to
|
||||
* // approximately estimate the feature strengths)
|
||||
* } CvSURFPoint;
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSURFPOINT
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSURFPoint *ptr;
|
||||
return Data_Make_Struct(klass, CvSURFPoint, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a CvSURFPoint
|
||||
*
|
||||
* @overload new(pt, laplacian, size, dir, hessian)
|
||||
* @param pt [CvPoint2D32f] Position of the feature within the image
|
||||
* @param laplacian [Integer] -1, 0 or +1. sign of the laplacian at the point.
|
||||
* Can be used to speedup feature comparison
|
||||
* (normally features with laplacians of different signs can not match)
|
||||
* @param size [Integer] Size of the feature
|
||||
* @param dir [Number] Orientation of the feature: 0..360 degrees
|
||||
* @param hessian [Number] Value of the hessian (can be used to
|
||||
* approximately estimate the feature strengths)
|
||||
* @return [CvSURFPoint] self
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(VALUE self, VALUE pt, VALUE laplacian, VALUE size, VALUE dir, VALUE hessian)
|
||||
{
|
||||
CvSURFPoint *self_ptr = CVSURFPOINT(self);
|
||||
self_ptr->pt = VALUE_TO_CVPOINT2D32F(pt);
|
||||
self_ptr->laplacian = NUM2INT(laplacian);
|
||||
self_ptr->size = NUM2INT(size);
|
||||
self_ptr->dir = (float)NUM2DBL(dir);
|
||||
self_ptr->hessian = (float)NUM2DBL(hessian);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return position of the feature as CvPoint2D32f.
|
||||
*
|
||||
* @overload pt
|
||||
* @return [CvPoint2D32f] Position of the feature.
|
||||
*/
|
||||
VALUE
|
||||
rb_get_pt(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVSURFPOINT(self)->pt, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set position of the feature.
|
||||
*
|
||||
* @overload pt=(value)
|
||||
* @param value [CvPoint2D32f] Valuet to set.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_pt(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->pt = VALUE_TO_CVPOINT2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return sign of the laplacian at the point (-1, 0 or +1)
|
||||
*
|
||||
* @overload laplacian
|
||||
* @return [Integer] Sign of the laplacian at the point.
|
||||
*/
|
||||
VALUE
|
||||
rb_get_laplacian(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSURFPOINT(self)->laplacian);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set sign of the laplacian at the point
|
||||
*
|
||||
* @overload laplacian=(value)
|
||||
* @param value [Integer] Value to set.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_laplacian(VALUE self, VALUE value)
|
||||
{
|
||||
int val = NUM2INT(value);
|
||||
CVSURFPOINT(self)->laplacian = (val > 0) ? 1 : (val < 0) ? -1 : 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns size of feature.
|
||||
*
|
||||
* @overload size
|
||||
* @return [Integer] Size of feature.
|
||||
*/
|
||||
VALUE
|
||||
rb_get_size(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVSURFPOINT(self)->size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of feature
|
||||
*
|
||||
* @overload size=(value)
|
||||
* @param [Integer] Value to set.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_size(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->size = NUM2INT(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return orientation of the feature: 0..360 degrees
|
||||
*
|
||||
* @overload dir
|
||||
* @return [Number] Orientation of the feature.
|
||||
*/
|
||||
VALUE
|
||||
rb_get_dir(VALUE self)
|
||||
{
|
||||
return DBL2NUM((double)(CVSURFPOINT(self)->dir));
|
||||
}
|
||||
|
||||
/*
|
||||
* Set orientation of the feature: 0..360 degrees.
|
||||
*
|
||||
* @overload dir=(value)
|
||||
* @param [Number] Value to set.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_dir(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->dir = (float)NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return value of the hessian
|
||||
*
|
||||
* @overload hessian
|
||||
* @return [Number] Hessian
|
||||
*/
|
||||
VALUE
|
||||
rb_get_hessian(VALUE self)
|
||||
{
|
||||
return DBL2NUM((double)(CVSURFPOINT(self)->hessian));
|
||||
}
|
||||
|
||||
/*
|
||||
* Set value of the hessian
|
||||
*
|
||||
* @overload hessian=(value)
|
||||
* @param [Number] Value to set.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_hessian(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->hessian = (float)NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object()
|
||||
{
|
||||
return rb_allocate(rb_klass);
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvSURFPoint* cvsurfpoint)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
CvSURFPoint *ptr = CVSURFPOINT(object);
|
||||
ptr = cvsurfpoint;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "CvSURFPoint", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), 5);
|
||||
rb_define_method(rb_klass, "pt", RUBY_METHOD_FUNC(rb_get_pt), 0);
|
||||
rb_define_method(rb_klass, "pt=", RUBY_METHOD_FUNC(rb_set_pt), 1);
|
||||
rb_define_method(rb_klass, "laplacian", RUBY_METHOD_FUNC(rb_get_laplacian), 0);
|
||||
rb_define_method(rb_klass, "laplacian=", RUBY_METHOD_FUNC(rb_set_laplacian), 1);
|
||||
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_get_size), 0);
|
||||
rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
|
||||
rb_define_method(rb_klass, "dir", RUBY_METHOD_FUNC(rb_get_dir), 0);
|
||||
rb_define_method(rb_klass, "dir=", RUBY_METHOD_FUNC(rb_set_dir), 1);
|
||||
rb_define_method(rb_klass, "hessian", RUBY_METHOD_FUNC(rb_get_hessian), 0);
|
||||
rb_define_method(rb_klass, "hessian=", RUBY_METHOD_FUNC(rb_set_hessian), 1);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSURFPOINT
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvsurfpoint.h -
|
||||
|
||||
$Author: ser1zw $
|
||||
|
||||
Copyright (C) 2011 ser1zw
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVSURFPOINT_H
|
||||
#define RUBY_OPENCV_CVSURFPOINT_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVSURFPOINT namespace cCvSURFPoint {
|
||||
#define __NAMESPACE_END_CVSURFPOINT }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVSURFPOINT
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(VALUE self, VALUE pt, VALUE laplacian, VALUE size, VALUE dir, VALUE hessian);
|
||||
VALUE rb_get_pt(VALUE self);
|
||||
VALUE rb_set_pt(VALUE self, VALUE value);
|
||||
VALUE rb_get_laplacian(VALUE self);
|
||||
VALUE rb_set_laplacian(VALUE self, VALUE value);
|
||||
VALUE rb_get_size(VALUE self);
|
||||
VALUE rb_set_size(VALUE self, VALUE value);
|
||||
VALUE rb_get_dir(VALUE self);
|
||||
VALUE rb_set_dir(VALUE self, VALUE value);
|
||||
VALUE rb_get_hessian(VALUE self);
|
||||
VALUE rb_set_hessian(VALUE self, VALUE value);
|
||||
|
||||
VALUE new_object(CvSURFPoint *cvsurfpoint);
|
||||
|
||||
__NAMESPACE_END_CVSURFPOINT
|
||||
|
||||
inline CvSURFPoint*
|
||||
CVSURFPOINT(VALUE object)
|
||||
{
|
||||
CvSURFPoint* ptr;
|
||||
Data_Get_Struct(object, CvSURFPoint, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVSURFPOINT_H
|
|
@ -1,198 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvtermcriteria.cpp -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#include "cvtermcriteria.h"
|
||||
/*
|
||||
* Document-class: OpenCV::CvTermCriteria
|
||||
*
|
||||
* CvTermCriteria has parameter "max" and "eps".
|
||||
* "max" is the maximum repetition frequency.
|
||||
* "eps" is a minimum difference value during current and previous state
|
||||
* (It is different to which state "eps" refer depending on the method).
|
||||
*
|
||||
* Because the name of CvTermCriteria seems to be very long, it has alias named CvTerm.
|
||||
*/
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVTERMCRITERIA
|
||||
|
||||
VALUE rb_klass;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
{
|
||||
return rb_klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvTermCriteria *ptr;
|
||||
return Data_Make_Struct(klass, CvTermCriteria, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* CvTermCriteria.new([max = 0][,eps = 0.0]) -> obj
|
||||
* CvTermCriteria.new(int) = CvTermCriteria.new(int, 0.0)
|
||||
* CvTermCriteria.new(float) = CvTermCriteria.new(0, float)
|
||||
*
|
||||
* Create new term criteria.
|
||||
*/
|
||||
VALUE
|
||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE max, eps;
|
||||
rb_scan_args(argc, argv, "02", &max, &eps);
|
||||
int type = 0;
|
||||
if (!NIL_P(max))
|
||||
type |= CV_TERMCRIT_ITER;
|
||||
if (!NIL_P(eps))
|
||||
type |= CV_TERMCRIT_EPS;
|
||||
try {
|
||||
*CVTERMCRITERIA(self) = cvTermCriteria(type, IF_INT(max, 0), IF_DBL(eps, 0.0));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* type -> int
|
||||
*
|
||||
* Return a combination of CV_TERMCRIT_ITER and CV_TERMCRIT_EPS
|
||||
*/
|
||||
VALUE
|
||||
rb_type(VALUE self)
|
||||
{
|
||||
return INT2NUM(CVTERMCRITERIA(self)->type);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* max -> int or nil
|
||||
*
|
||||
* Return the maximum repetition frequency.
|
||||
*/
|
||||
VALUE
|
||||
rb_max(VALUE self)
|
||||
{
|
||||
CvTermCriteria *ptr = CVTERMCRITERIA(self);
|
||||
if (ptr->type & CV_TERMCRIT_ITER)
|
||||
return INT2NUM(ptr->max_iter);
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* max = <i>val</i> -> self
|
||||
*
|
||||
* Set the maximum repetition frequency.
|
||||
* If <i>val</i> is 0 (or negative value), repetition frequency is disregarded.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_max(VALUE self, VALUE max_value)
|
||||
{
|
||||
CvTermCriteria *ptr = CVTERMCRITERIA(self);
|
||||
int max = NUM2INT(max_value);
|
||||
if (max > 0) {
|
||||
ptr->type |= CV_TERMCRIT_ITER;
|
||||
ptr->max_iter = max;
|
||||
}
|
||||
else {
|
||||
ptr->type ^= CV_TERMCRIT_ITER;
|
||||
ptr->max_iter = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* eps -> float or nil
|
||||
*
|
||||
* Return the minimum difference value during current and previous state.
|
||||
*/
|
||||
VALUE
|
||||
rb_eps(VALUE self)
|
||||
{
|
||||
CvTermCriteria *ptr = CVTERMCRITERIA(self);
|
||||
if (ptr->type & CV_TERMCRIT_EPS)
|
||||
return rb_float_new(ptr->epsilon);
|
||||
else
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* eps = <i>val</i> -> self
|
||||
*
|
||||
* Set the minimum difference value during current and previous state.
|
||||
* If <i>val</i> is 0.0 (or negative value), the minimum difference value
|
||||
* during current and previous state is disregarded.
|
||||
*/
|
||||
VALUE
|
||||
rb_set_eps(VALUE self, VALUE eps_value)
|
||||
{
|
||||
CvTermCriteria *ptr = CVTERMCRITERIA(self);
|
||||
double eps = NUM2DBL(eps_value);
|
||||
if (eps > 0) {
|
||||
ptr->type = ptr->type | CV_TERMCRIT_EPS;
|
||||
ptr->epsilon = eps;
|
||||
}
|
||||
else {
|
||||
ptr->type = ptr->type ^ CV_TERMCRIT_EPS;
|
||||
ptr->epsilon = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
VALUE
|
||||
new_object(CvTermCriteria criteria)
|
||||
{
|
||||
VALUE object = rb_allocate(rb_klass);
|
||||
*CVTERMCRITERIA(object) = criteria;
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
init_ruby_class()
|
||||
{
|
||||
#if 0
|
||||
// For documentation using YARD
|
||||
VALUE opencv = rb_define_module("OpenCV");
|
||||
#endif
|
||||
|
||||
if (rb_klass)
|
||||
return;
|
||||
/*
|
||||
* opencv = rb_define_module("OpenCV");
|
||||
*
|
||||
* note: this comment is used by rdoc.
|
||||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
|
||||
rb_klass = rb_define_class_under(opencv, "CvTermCriteria", rb_cObject);
|
||||
/* CvTermCriteria: class */
|
||||
rb_define_const(opencv, "CvTerm", rb_klass);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
rb_define_method(rb_klass, "type", RUBY_METHOD_FUNC(rb_type), 0);
|
||||
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
|
||||
rb_define_method(rb_klass, "max=", RUBY_METHOD_FUNC(rb_set_max), 1);
|
||||
rb_define_method(rb_klass, "eps", RUBY_METHOD_FUNC(rb_eps), 0);
|
||||
rb_define_method(rb_klass, "eps=", RUBY_METHOD_FUNC(rb_set_eps), 1);
|
||||
rb_define_alias(rb_klass, "epsilon", "eps");
|
||||
rb_define_alias(rb_klass, "epsilon=", "eps=");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVTERMCRITERIA
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/************************************************************
|
||||
|
||||
cvtermcriteria.h -
|
||||
|
||||
$Author: lsxi $
|
||||
|
||||
Copyright (C) 2005-2006 Masakazu Yonekura
|
||||
|
||||
************************************************************/
|
||||
#ifndef RUBY_OPENCV_CVTERMCRITERIA_H
|
||||
#define RUBY_OPENCV_CVTERMCRITERIA_H
|
||||
|
||||
#include "opencv.h"
|
||||
|
||||
#define __NAMESPACE_BEGIN_CVTERMCRITERIA namespace cCvTermCriteria {
|
||||
#define __NAMESPACE_END_CVTERMCRITERIA }
|
||||
|
||||
__NAMESPACE_BEGIN_OPENCV
|
||||
__NAMESPACE_BEGIN_CVTERMCRITERIA
|
||||
|
||||
VALUE rb_class();
|
||||
|
||||
void init_ruby_class();
|
||||
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_type(VALUE self);
|
||||
VALUE rb_max(VALUE self);
|
||||
VALUE rb_set_max(VALUE self, VALUE max_value);
|
||||
VALUE rb_eps(VALUE self);
|
||||
VALUE rb_set_eps(VALUE self, VALUE eps_value);
|
||||
|
||||
VALUE new_object(CvTermCriteria criteria);
|
||||
|
||||
__NAMESPACE_END_CVTERMCRITERIA
|
||||
|
||||
inline CvTermCriteria*
|
||||
CVTERMCRITERIA(VALUE object)
|
||||
{
|
||||
CvTermCriteria *ptr;
|
||||
Data_Get_Struct(object, CvTermCriteria, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvTermCriteria
|
||||
VALUE_TO_CVTERMCRITERIA(VALUE object)
|
||||
{
|
||||
if (rb_obj_is_kind_of(object, cCvTermCriteria::rb_class())) {
|
||||
return *CVTERMCRITERIA(object);
|
||||
}
|
||||
switch (TYPE(object)) {
|
||||
case T_NIL:
|
||||
return cvTermCriteria(CV_TERMCRIT_ITER, 0, 0);
|
||||
case T_FIXNUM:
|
||||
return cvTermCriteria(CV_TERMCRIT_ITER, NUM2INT(object), 0);
|
||||
case T_FLOAT:
|
||||
return cvTermCriteria(CV_TERMCRIT_EPS, 0, NUM2DBL(object));
|
||||
case T_ARRAY:
|
||||
if (RARRAY_LEN(object) == 2) {
|
||||
return cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS,
|
||||
NUM2INT(rb_ary_entry(object, 0)),
|
||||
NUM2DBL(rb_ary_entry(object, 1)));
|
||||
}
|
||||
}
|
||||
rb_raise(rb_eTypeError, "Invalid type");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
#endif // RUBY_OPENCV_CVTERMCRITERIA_H
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue