mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
implemented CvSURFPoint
This commit is contained in:
parent
d2ad460eb7
commit
6197c1f7fc
5 changed files with 343 additions and 1 deletions
225
ext/opencv/cvsurfpoint.cpp
Normal file
225
ext/opencv/cvsurfpoint.cpp
Normal file
|
@ -0,0 +1,225 @@
|
|||
/************************************************************
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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, "CvSURFPoint", rb_cObject);
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_private_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);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvSURFPoint *ptr;
|
||||
return Data_Make_Struct(klass, CvSURFPoint, 0, -1, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* CvSURFPoint.new(<i>pt,laplacian,size,dir,hessian</i>) -> cvsurfpoint
|
||||
*
|
||||
* Create a CvSURFPoint
|
||||
*/
|
||||
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 = FIX2INT(laplacian);
|
||||
self_ptr->size = FIX2INT(size);
|
||||
self_ptr->dir = (float)NUM2DBL(dir);
|
||||
self_ptr->hessian = (float)NUM2DBL(hessian);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* pt -> cvpoint2d32f
|
||||
* Return position of the feature as CvPoint2D32f.
|
||||
*/
|
||||
VALUE
|
||||
rb_get_pt(VALUE self)
|
||||
{
|
||||
return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVSURFPOINT(self)->pt, self);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* pt = <i>value</i>
|
||||
*
|
||||
* Set position of the feature to <i>value</i>
|
||||
*/
|
||||
VALUE
|
||||
rb_set_pt(VALUE self, VALUE value)
|
||||
{
|
||||
if (!cCvPoint2D32f::rb_compatible_q(rb_klass, value))
|
||||
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(cCvPoint2D32f::rb_class()));
|
||||
CVSURFPOINT(self)->pt = VALUE_TO_CVPOINT2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* laplacian -> fixnum
|
||||
* Return sign of the laplacian at the point (-1, 0 or +1)
|
||||
*/
|
||||
VALUE
|
||||
rb_get_laplacian(VALUE self)
|
||||
{
|
||||
return INT2FIX(CVSURFPOINT(self)->laplacian);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* laplacian = <i>value</i> (-1, 0 or +1)
|
||||
* Set sign of the laplacian at the point
|
||||
*/
|
||||
VALUE
|
||||
rb_set_laplacian(VALUE self, VALUE value)
|
||||
{
|
||||
int val = FIX2INT(value);
|
||||
CVSURFPOINT(self)->laplacian = (val > 0) ? 1 : (val < 0) ? -1 : 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* size -> fixnum
|
||||
* Return size of feature
|
||||
*/
|
||||
VALUE
|
||||
rb_get_size(VALUE self)
|
||||
{
|
||||
return INT2FIX(CVSURFPOINT(self)->size);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* size = <i>value</i>
|
||||
* Return size of feature
|
||||
*/
|
||||
VALUE
|
||||
rb_set_size(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->size = FIX2INT(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* dir -> number
|
||||
* Return orientation of the feature: 0..360 degrees
|
||||
*/
|
||||
VALUE
|
||||
rb_get_dir(VALUE self)
|
||||
{
|
||||
return DBL2NUM((double)(CVSURFPOINT(self)->dir));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* dir = <i>value</i>
|
||||
* Set orientation of the feature: 0..360 degrees
|
||||
*/
|
||||
VALUE
|
||||
rb_set_dir(VALUE self, VALUE value)
|
||||
{
|
||||
CVSURFPOINT(self)->dir = (float)NUM2DBL(value);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hessian -> number
|
||||
* Return value of the hessian
|
||||
*/
|
||||
VALUE
|
||||
rb_get_hessian(VALUE self)
|
||||
{
|
||||
return DBL2NUM((double)(CVSURFPOINT(self)->hessian));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hessian = <i>value</i>
|
||||
* Set value of the hessian
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CVSURFPOINT
|
||||
__NAMESPACE_END_OPENCV
|
52
ext/opencv/cvsurfpoint.h
Normal file
52
ext/opencv/cvsurfpoint.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/************************************************************
|
||||
|
||||
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 define_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
|
|
@ -747,7 +747,8 @@ extern "C"{
|
|||
mOpenCV::cCvMoments::define_ruby_class();
|
||||
mOpenCV::cCvHuMoments::define_ruby_class();
|
||||
mOpenCV::cCvConvexityDefect::define_ruby_class();
|
||||
|
||||
mOpenCV::cCvSURFPoint::define_ruby_class();
|
||||
|
||||
mOpenCV::cCvMemStorage::define_ruby_class();
|
||||
|
||||
mOpenCV::cCvSeq::define_ruby_class();
|
||||
|
|
|
@ -127,6 +127,8 @@ extern "C"{
|
|||
#include "cvavgcomp.h"
|
||||
#include "cvhaarclassifiercascade.h"
|
||||
|
||||
#include "cvsurfpoint.h"
|
||||
|
||||
// GUI
|
||||
#include "gui.h"
|
||||
#include "window.h"
|
||||
|
|
62
test/test_cvsurfpoint.rb
Executable file
62
test/test_cvsurfpoint.rb
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/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::CvSURFPoint
|
||||
class TestCvSURFPoint < OpenCVTestCase
|
||||
def setup
|
||||
@surf_point1 = CvSURFPoint.new(CvPoint2D32f.new(0, 0), 0, 0, 0, 0)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
sp1 = CvSURFPoint.new(CvPoint2D32f.new(1.1, 2.2), 1, 10, 12.3, 45.6)
|
||||
assert_in_delta(1.1, sp1.pt.x, 0.001)
|
||||
assert_in_delta(2.2, sp1.pt.y, 0.001)
|
||||
assert_equal(1, sp1.laplacian)
|
||||
assert_equal(10, sp1.size)
|
||||
assert_in_delta(12.3, sp1.dir, 0.001)
|
||||
assert_in_delta(45.6, sp1.hessian, 0.001)
|
||||
end
|
||||
|
||||
def test_pt
|
||||
assert_in_delta(0, @surf_point1.pt.x, 0.001)
|
||||
assert_in_delta(0, @surf_point1.pt.y, 0.001)
|
||||
|
||||
@surf_point1.pt = CvPoint2D32f.new(12.3, 45.6)
|
||||
assert_in_delta(12.3, @surf_point1.pt.x, 0.001)
|
||||
assert_in_delta(45.6, @surf_point1.pt.y, 0.001)
|
||||
end
|
||||
|
||||
def test_laplacian
|
||||
assert_equal(0, @surf_point1.laplacian)
|
||||
|
||||
@surf_point1.laplacian = -1
|
||||
assert_equal(-1, @surf_point1.laplacian)
|
||||
end
|
||||
|
||||
def test_size
|
||||
assert_equal(0, @surf_point1.size)
|
||||
|
||||
@surf_point1.size = 10
|
||||
assert_equal(10, @surf_point1.size)
|
||||
end
|
||||
|
||||
def test_dir
|
||||
assert_in_delta(0, @surf_point1.dir, 0.001)
|
||||
|
||||
@surf_point1.dir = 23.4
|
||||
assert_in_delta(23.4, @surf_point1.dir, 0.001)
|
||||
end
|
||||
|
||||
def test_hessian
|
||||
assert_in_delta(0, @surf_point1.hessian, 0.001)
|
||||
|
||||
@surf_point1.hessian = 2.1
|
||||
assert_in_delta(2.1, @surf_point1.hessian, 0.001)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in a new issue