1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

implementated CvSURFParams

This commit is contained in:
ser1zw 2011-06-19 07:16:25 +09:00
parent dbc579c3e0
commit 3c23c44edc
5 changed files with 309 additions and 0 deletions

199
ext/opencv/cvsurfparams.cpp Normal file
View file

@ -0,0 +1,199 @@
/************************************************************
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;
}
void
define_ruby_class()
{
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_private_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);
}
VALUE
rb_allocate(VALUE klass)
{
CvSURFParams *ptr;
return Data_Make_Struct(klass, CvSURFParams, 0, -1, ptr);
}
/*
* call-seq:
* CvSURFParams.new(<i>hessian_threshold[,extended=false,n_octaves=3,n_octave_layers=4]</i>) -> cvsurfparams
*
* Create a CvSURFParams
*/
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 : FIX2INT(noct);
self_ptr->nOctaveLayers = NIL_P(noctl) ? 4 : FIX2INT(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 INT2FIX(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 = FIX2INT(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 INT2FIX(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 = FIX2INT(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;
}
__NAMESPACE_END_CVSURFPARAMS
__NAMESPACE_END_OPENCV

50
ext/opencv/cvsurfparams.h Normal file
View file

@ -0,0 +1,50 @@
/************************************************************
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 define_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;
}
__NAMESPACE_END_OPENCV
#endif // RUBY_OPENCV_CVSURFPARAMS_H

View file

@ -747,7 +747,9 @@ extern "C"{
mOpenCV::cCvMoments::define_ruby_class();
mOpenCV::cCvHuMoments::define_ruby_class();
mOpenCV::cCvConvexityDefect::define_ruby_class();
mOpenCV::cCvSURFPoint::define_ruby_class();
mOpenCV::cCvSURFParams::define_ruby_class();
mOpenCV::cCvMemStorage::define_ruby_class();

View file

@ -128,6 +128,7 @@ extern "C"{
#include "cvhaarclassifiercascade.h"
#include "cvsurfpoint.h"
#include "cvsurfparams.h"
// GUI
#include "gui.h"

57
test/test_cvsurfparams.rb Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env ruby
# -*- mode: ruby; coding: utf-8-unix -*-
require 'test/unit'
require 'opencv'
require File.expand_path(File.dirname(__FILE__)) + '/helper'
include OpenCV
# Tests for OpenCV::CvSURFParams
class TestCvSURFParams < OpenCVTestCase
def setup
@surf_param1 = CvSURFParams.new(345.6)
end
def test_initialize
sp1 = CvSURFParams.new(345.6)
assert_equal(false, sp1.extended)
assert_in_delta(345.6, sp1.hessian_threshold, 0.001)
assert_equal(3, sp1.n_octaves)
assert_equal(4, sp1.n_octave_layers)
sp2 = CvSURFParams.new(456.7, true, 4, 5)
assert_equal(true, sp2.extended)
assert_in_delta(456.7, sp2.hessian_threshold, 0.001)
assert_equal(4, sp2.n_octaves)
assert_equal(5, sp2.n_octave_layers)
end
def test_extended
assert_equal(false, @surf_param1.extended)
@surf_param1.extended = true
assert_equal(true, @surf_param1.extended)
end
def test_hessian_threshold
assert_in_delta(345.6, @surf_param1.hessian_threshold, 0.001)
@surf_param1.hessian_threshold = 456.7
assert_in_delta(456.7, @surf_param1.hessian_threshold, 0.001)
end
def test_n_octaves
assert_equal(3, @surf_param1.n_octaves)
@surf_param1.n_octaves = 4
assert_equal(4, @surf_param1.n_octaves)
end
def test_n_octave_layers
assert_equal(4, @surf_param1.n_octave_layers)
@surf_param1.n_octave_layers = 5
assert_equal(5, @surf_param1.n_octave_layers)
end
end