opencv-ffi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +15 -0
- data/README.md +126 -0
- data/Rakefile +52 -0
- data/docs/DocsIndex.md +1 -0
- data/docs/examples/load_image.rb +25 -0
- data/ext/Rakefile +13 -0
- data/ext/aishack-sift/.gitignore +4 -0
- data/ext/aishack-sift/Descriptor.h +34 -0
- data/ext/aishack-sift/KeyPoint.h +38 -0
- data/ext/aishack-sift/README +20 -0
- data/ext/aishack-sift/SIFT.cpp +1036 -0
- data/ext/aishack-sift/SIFT.h +84 -0
- data/ext/aishack-sift/example/.gitignore +2 -0
- data/ext/aishack-sift/example/Makefile +24 -0
- data/ext/aishack-sift/example/MySIFT.cpp +29 -0
- data/ext/aishack-sift/mkrf_conf.rb +13 -0
- data/ext/aishack-sift/siftlib.cpp +85 -0
- data/ext/eigen/.gitignore +4 -0
- data/ext/eigen/eigen_polynomial.cpp +41 -0
- data/ext/eigen/eigen_svd.cpp +100 -0
- data/ext/eigen/mkrf_conf.rb +14 -0
- data/ext/mkrf-monkey.rb +85 -0
- data/ext/mkrf-rakehelper-monkey.rb +52 -0
- data/ext/mkrf_conf.rb +3 -0
- data/ext/opencv-ffi/.gitignore +4 -0
- data/ext/opencv-ffi/matcher_helper.cpp +56 -0
- data/ext/opencv-ffi/mkrf_conf.rb +12 -0
- data/ext/opencv-ffi/vector_math.cpp +39 -0
- data/ext/opensurf/.gitignore +4 -0
- data/ext/opensurf/README +38 -0
- data/ext/opensurf/fasthessian.cpp +376 -0
- data/ext/opensurf/fasthessian.h +108 -0
- data/ext/opensurf/integral.cpp +58 -0
- data/ext/opensurf/integral.h +55 -0
- data/ext/opensurf/ipoint.cpp +108 -0
- data/ext/opensurf/ipoint.h +76 -0
- data/ext/opensurf/kmeans.h +172 -0
- data/ext/opensurf/mkrf_conf.rb +10 -0
- data/ext/opensurf/responselayer.h +92 -0
- data/ext/opensurf/surf.cpp +317 -0
- data/ext/opensurf/surf.h +66 -0
- data/ext/opensurf/surflib.cpp +98 -0
- data/ext/opensurf/surflib.h +96 -0
- data/ext/opensurf/utils.cpp +357 -0
- data/ext/opensurf/utils.h +63 -0
- data/lib/.gitignore +1 -0
- data/lib/opencv-ffi-ext/eigen.rb +84 -0
- data/lib/opencv-ffi-ext/features2d.rb +4 -0
- data/lib/opencv-ffi-ext/matcher_helper.rb +24 -0
- data/lib/opencv-ffi-ext/opensurf.rb +217 -0
- data/lib/opencv-ffi-ext/sift.rb +118 -0
- data/lib/opencv-ffi-ext/vector_math.rb +115 -0
- data/lib/opencv-ffi-wrappers.rb +7 -0
- data/lib/opencv-ffi-wrappers/core.rb +24 -0
- data/lib/opencv-ffi-wrappers/core/iplimage.rb +50 -0
- data/lib/opencv-ffi-wrappers/core/mat.rb +268 -0
- data/lib/opencv-ffi-wrappers/core/misc_draw.rb +44 -0
- data/lib/opencv-ffi-wrappers/core/point.rb +286 -0
- data/lib/opencv-ffi-wrappers/core/rect.rb +40 -0
- data/lib/opencv-ffi-wrappers/core/scalar.rb +104 -0
- data/lib/opencv-ffi-wrappers/core/size.rb +88 -0
- data/lib/opencv-ffi-wrappers/enumerable.rb +10 -0
- data/lib/opencv-ffi-wrappers/features2d.rb +17 -0
- data/lib/opencv-ffi-wrappers/features2d/image_patch.rb +322 -0
- data/lib/opencv-ffi-wrappers/features2d/star.rb +111 -0
- data/lib/opencv-ffi-wrappers/features2d/surf.rb +115 -0
- data/lib/opencv-ffi-wrappers/highgui.rb +10 -0
- data/lib/opencv-ffi-wrappers/imgproc.rb +4 -0
- data/lib/opencv-ffi-wrappers/imgproc/features.rb +35 -0
- data/lib/opencv-ffi-wrappers/imgproc/geometric.rb +39 -0
- data/lib/opencv-ffi-wrappers/matcher.rb +297 -0
- data/lib/opencv-ffi-wrappers/matrix.rb +37 -0
- data/lib/opencv-ffi-wrappers/misc.rb +41 -0
- data/lib/opencv-ffi-wrappers/misc/params.rb +34 -0
- data/lib/opencv-ffi-wrappers/sequence.rb +37 -0
- data/lib/opencv-ffi-wrappers/vectors.rb +38 -0
- data/lib/opencv-ffi.rb +12 -0
- data/lib/opencv-ffi/calib3d.rb +26 -0
- data/lib/opencv-ffi/core.rb +15 -0
- data/lib/opencv-ffi/core/draw.rb +68 -0
- data/lib/opencv-ffi/core/dynamic.rb +13 -0
- data/lib/opencv-ffi/core/library.rb +5 -0
- data/lib/opencv-ffi/core/operations.rb +122 -0
- data/lib/opencv-ffi/core/point.rb +22 -0
- data/lib/opencv-ffi/core/types.rb +172 -0
- data/lib/opencv-ffi/cvffi.rb +8 -0
- data/lib/opencv-ffi/features2d.rb +7 -0
- data/lib/opencv-ffi/features2d/library.rb +6 -0
- data/lib/opencv-ffi/features2d/star.rb +30 -0
- data/lib/opencv-ffi/features2d/surf.rb +38 -0
- data/lib/opencv-ffi/highgui.rb +31 -0
- data/lib/opencv-ffi/imgproc.rb +9 -0
- data/lib/opencv-ffi/imgproc/features.rb +37 -0
- data/lib/opencv-ffi/imgproc/geometric.rb +42 -0
- data/lib/opencv-ffi/imgproc/library.rb +6 -0
- data/lib/opencv-ffi/imgproc/misc.rb +39 -0
- data/lib/opencv-ffi/version.rb +3 -0
- data/opencv-ffi.gemspec +26 -0
- data/test/core/test_draw.rb +46 -0
- data/test/core/test_operations.rb +135 -0
- data/test/core/test_size.rb +14 -0
- data/test/core/test_text.rb +52 -0
- data/test/ext/test_eigen.rb +105 -0
- data/test/ext/test_opensurf.rb +35 -0
- data/test/ext/test_sift.rb +26 -0
- data/test/ext/test_vector_math.rb +85 -0
- data/test/features2d/test_surf.rb +63 -0
- data/test/imgproc/test_goodfeatures.rb +18 -0
- data/test/setup.rb +65 -0
- data/test/test_calib3d.rb +38 -0
- data/test/test_core.rb +26 -0
- data/test/test_ext.rb +8 -0
- data/test/test_features2d.rb +9 -0
- data/test/test_files/images/IMG_7088.JPG +0 -0
- data/test/test_files/images/IMG_7088_small.JPG +0 -0
- data/test/test_files/images/IMG_7089.JPG +0 -0
- data/test/test_highgui.rb +26 -0
- data/test/test_imgproc.rb +35 -0
- data/test/test_wrappers.rb +8 -0
- data/test/wrappers/core/test_draw.rb +41 -0
- data/test/wrappers/core/test_mat.rb +40 -0
- data/test/wrappers/core/test_operations.rb +35 -0
- data/test/wrappers/core/test_types.rb +235 -0
- data/test/wrappers/features2d/test_image_patch.rb +108 -0
- data/test/wrappers/test_imgproc.rb +87 -0
- data/test/wrappers/test_matcher.rb +96 -0
- data/test/wrappers/test_star.rb +28 -0
- data/test/wrappers/test_surf.rb +36 -0
- metadata +234 -0
data/opencv-ffi.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "opencv-ffi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "opencv-ffi"
|
7
|
+
s.version = CVFFI::VERSION
|
8
|
+
s.authors = ["Aaron Marburg"]
|
9
|
+
s.email = ["aaron.marburg@pg.canterbury.ac.nz"]
|
10
|
+
s.homepage = "http://github.com/amarburg/opencv-ffi"
|
11
|
+
s.summary = %q{A wrapper around OpenCV's C interface using Ruby FFI. Very preliminary.}
|
12
|
+
s.description = %q{A wrapper around OpenCV's C interface using Ruby FFI.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "opencv-ffi"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.extensions = "ext/mkrf_conf.rb"
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.has_rdoc = true
|
23
|
+
|
24
|
+
s.add_dependency "nice-ffi"
|
25
|
+
s.add_dependency "mkrf"
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'test/setup'
|
4
|
+
|
5
|
+
class TestcvCircle < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@img = TestSetup::test_image
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def test_cvCircle
|
13
|
+
center = CVFFI::CvPoint.new( :x => 500, :y => 500 )
|
14
|
+
radius = 100
|
15
|
+
color = CVFFI::CvScalar.new( {:w=>255, :x=>255, :y=>255, :z=>0} )
|
16
|
+
|
17
|
+
CVFFI::cvCircle( @img, center, radius, color, -1, 8, 0 )
|
18
|
+
|
19
|
+
# Spot check a few points within the radius
|
20
|
+
pts = [ [500,500], [550,500], [450, 500] ]
|
21
|
+
pts.each { |pt|
|
22
|
+
c = CVFFI::cvGet2D( @img, pt[0],pt[1] )
|
23
|
+
|
24
|
+
assert_equal 255, c.w
|
25
|
+
assert_equal 255, c.x
|
26
|
+
assert_equal 255, c.y
|
27
|
+
assert_equal 0, c.z
|
28
|
+
}
|
29
|
+
|
30
|
+
TestSetup::save_image( "test_cvCircle", @img )
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cvLine
|
34
|
+
|
35
|
+
pointA = CVFFI::CvPoint.new( :x => 50, :y => 50 )
|
36
|
+
pointB = CVFFI::CvPoint.new( :x => @img.width-50, :y => @img.height-50 )
|
37
|
+
|
38
|
+
color = CVFFI::CvScalar.new( {:w=>255, :x=>0, :y=>255, :z=>0} )
|
39
|
+
|
40
|
+
CVFFI::cvLine( @img, pointA, pointB, color, 10, 8, 0 )
|
41
|
+
|
42
|
+
TestSetup::save_image( "text_cvLine", @img )
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
|
2
|
+
require 'test/setup'
|
3
|
+
require 'opencv-ffi/core'
|
4
|
+
require 'opencv-ffi/highgui'
|
5
|
+
|
6
|
+
|
7
|
+
class TestCoreOperations < Test::Unit::TestCase
|
8
|
+
|
9
|
+
WHITE = CVFFI::CvScalar.new( {:w=>255, :x=>255, :y=>255, :z=>0} )
|
10
|
+
BLACK = CVFFI::CvScalar.new( {:w=>0, :x=>0, :y=>0, :z=>0} )
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@center = CVFFI::CvPoint.new( :x => 50, :y => 50 )
|
14
|
+
@radius = 50
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def assert_color_at_point( img, point, color )
|
19
|
+
c = CVFFI::cvGet2D( img, point.x, point.y )
|
20
|
+
assert_equal color.w, c.w, "First channel mismatch"
|
21
|
+
assert_equal color.x, c.x, "Second channel mismatch" if img.nChannels > 1
|
22
|
+
assert_equal color.y, c.y, "Third channel mismatch" if img.nChannels > 2
|
23
|
+
assert_equal color.z, c.z, "Fourth channel mismatch" if img.nChannels > 3
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_cvReleaseImage
|
27
|
+
imgOne = CVFFI::cvCreateImage( CVFFI::CvSize.new( :width=>100, :height=>100 ), 8, 1 )
|
28
|
+
CVFFI::cvReleaseImage( imgOne )
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_imageOperations
|
33
|
+
imgOne = CVFFI::cvCreateImage( CVFFI::CvSize.new( :width=>100, :height=>100 ), 8, 1 )
|
34
|
+
CVFFI::cvSet( imgOne, BLACK, nil )
|
35
|
+
|
36
|
+
imgTwo = CVFFI::cvCloneImage( imgOne )
|
37
|
+
|
38
|
+
assert_equal imgOne.nChannels, imgTwo.nChannels
|
39
|
+
assert_equal imgOne.depth, imgTwo.depth
|
40
|
+
assert_equal imgOne.width, imgTwo.width
|
41
|
+
assert_equal imgOne.height, imgTwo.height
|
42
|
+
|
43
|
+
assert_color_at_point imgOne, @center, BLACK
|
44
|
+
assert_color_at_point imgTwo, @center, BLACK
|
45
|
+
|
46
|
+
# Draw a circle on one
|
47
|
+
CVFFI::cvCircle( imgOne, @center, @radius, WHITE, -1, 8, 0 )
|
48
|
+
|
49
|
+
assert_color_at_point imgOne, @center, WHITE
|
50
|
+
assert_color_at_point imgTwo, @center, BLACK
|
51
|
+
|
52
|
+
# Now copy
|
53
|
+
CVFFI::cvCopy( imgOne, imgTwo, nil )
|
54
|
+
|
55
|
+
assert_color_at_point imgOne, @center, WHITE
|
56
|
+
assert_color_at_point imgTwo, @center, WHITE
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_roiOperations
|
60
|
+
imgOne = CVFFI::cvCreateImage( CVFFI::CvSize.new( :width=>100, :height=>100 ), 8, 1 )
|
61
|
+
CVFFI::cvSet( imgOne, BLACK, nil )
|
62
|
+
CVFFI::cvCircle( imgOne, @center, @radius, WHITE, -1, 8, 0 )
|
63
|
+
|
64
|
+
imgTwo = CVFFI::cvCreateImage( CVFFI::CvSize.new( :width=>200, :height=>200 ), 8, 1 )
|
65
|
+
CVFFI::cvSet( imgTwo, BLACK, nil )
|
66
|
+
|
67
|
+
0.upto(100) { |i|
|
68
|
+
if i%25 == 0
|
69
|
+
|
70
|
+
roi = CVFFI::CvRect.new( :width => 100, :height => 100, :x => i, :y => i )
|
71
|
+
CVFFI::cvSetImageROI( imgTwo, roi )
|
72
|
+
|
73
|
+
r = CVFFI::CvRect.new CVFFI::cvGetImageROI( imgTwo )
|
74
|
+
|
75
|
+
assert_equal r.width, roi.width
|
76
|
+
assert_equal r.height, roi.height
|
77
|
+
assert_equal r.x, roi.x
|
78
|
+
assert_equal r.y, roi.y
|
79
|
+
|
80
|
+
CVFFI::cvCopy( imgOne, imgTwo, nil )
|
81
|
+
|
82
|
+
end
|
83
|
+
}
|
84
|
+
|
85
|
+
CVFFI::cvResetImageROI( imgTwo )
|
86
|
+
|
87
|
+
TestSetup::save_image( "test_roi", imgTwo )
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_transpose
|
92
|
+
m = CVFFI::cvCreateMat( 3,3, :CV_32F )
|
93
|
+
CVFFI::cvSetZero( m )
|
94
|
+
CVFFI::cvSetReal2D( m, 0, 2, 1.0 )
|
95
|
+
|
96
|
+
assert_equal CVFFI::cvGetReal2D( m, 0, 2 ), 1.0
|
97
|
+
assert_equal CVFFI::cvGetReal2D( m, 2, 0 ), 0.0
|
98
|
+
|
99
|
+
t = CVFFI::cvCreateMat( 3,3, :CV_32F )
|
100
|
+
CVFFI::cvTranspose( m, t )
|
101
|
+
|
102
|
+
assert_equal CVFFI::cvGetReal2D( m, 0, 2 ), 1.0
|
103
|
+
assert_equal CVFFI::cvGetReal2D( m, 2, 0 ), 0.0
|
104
|
+
|
105
|
+
assert_equal CVFFI::cvGetReal2D( t, 0, 2 ), 0.0
|
106
|
+
assert_equal CVFFI::cvGetReal2D( t, 2, 0 ), 1.0
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_solve_cubic
|
110
|
+
c = CVFFI::cvCreateMat( 1,4, :CV_32F )
|
111
|
+
r = CVFFI::cvCreateMat( 1,3, :CV_32F )
|
112
|
+
CVFFI::cvSetZero( r )
|
113
|
+
|
114
|
+
# The roots of x^3 - 6x^2 + 11x - 6
|
115
|
+
# are 1,2,3
|
116
|
+
[1,-6,11,-6].each_with_index { |x,i|
|
117
|
+
CVFFI::cvSetReal1D(c,i,x)
|
118
|
+
}
|
119
|
+
|
120
|
+
CVFFI::cvSolveCubic( c, r )
|
121
|
+
|
122
|
+
# For siplicity, dump to an array I can sort
|
123
|
+
r = Array.new(3) { |i|
|
124
|
+
CVFFI::cvGetReal1D(r,i)
|
125
|
+
}.sort
|
126
|
+
|
127
|
+
3.times { |i|
|
128
|
+
assert_in_delta i+1, r[i], 1e-06
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require 'test/setup'
|
3
|
+
require 'lib/opencv-ffi/core'
|
4
|
+
|
5
|
+
class TestCoreTextFunctions < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@img = CVFFI::cvLoadImageM( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def test_cvInitFont
|
13
|
+
font = CVFFI::CvFont.new '\0'
|
14
|
+
CVFFI::cvInitFont( font, :CV_FONT_HERSHEY_PLAIN, 2.0, 2.0, 0.0, 1, 8 )
|
15
|
+
|
16
|
+
assert_equal CVFFI::CvFontDefines[:CV_FONT_HERSHEY_PLAIN], font.font_face
|
17
|
+
assert_equal 2.0, font.hscale
|
18
|
+
assert_equal 2.0, font.vscale
|
19
|
+
assert_equal 1, font.thickness
|
20
|
+
assert_equal 0.0, font.shear
|
21
|
+
assert_equal 8, font.line_type
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_putText
|
25
|
+
font = CVFFI::CvFont.new '\0'
|
26
|
+
CVFFI::cvInitFont( font, :CV_FONT_HERSHEY_PLAIN, 2.0, 2.0, 0.0, 5, 8 )
|
27
|
+
|
28
|
+
img = CVFFI::cvCreateImage( CVFFI::CvSize.new( :height=>480, :width=>640), :IPL_DEPTH_32F, 3 )
|
29
|
+
|
30
|
+
color = CVFFI::CvScalar.new( :w => 0 , :x => 255, :y => 0, :z => 0 )
|
31
|
+
point = CVFFI::CvPoint.new( :x => 100, :y => 100 )
|
32
|
+
|
33
|
+
a = "TEST TEST!"
|
34
|
+
CVFFI::cvPutText( img, a, point, font, color )
|
35
|
+
|
36
|
+
CVFFI::cvSaveImage( TestSetup::output_filename("fontTest.tif"), img )
|
37
|
+
|
38
|
+
|
39
|
+
size = CVFFI::CvSize.new :height => 0, :width => 0
|
40
|
+
objptr = FFI::MemoryPointer.new :int
|
41
|
+
CVFFI::cvGetTextSize( a, font, size, objptr )
|
42
|
+
baseline = objptr.read_int
|
43
|
+
|
44
|
+
## These are pre-calculated values
|
45
|
+
assert_equal 12, baseline
|
46
|
+
assert_equal 191, size.width
|
47
|
+
assert_equal 21, size.height
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
|
2
|
+
require 'test/setup'
|
3
|
+
require 'opencv-ffi/core'
|
4
|
+
require 'opencv-ffi-ext/eigen'
|
5
|
+
require 'matrix'
|
6
|
+
|
7
|
+
class TestEigen < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@a = CVFFI::cvCreateMat( 3,3, :CV_32F )
|
11
|
+
3.times {|i| 3.times {|j|
|
12
|
+
@a.set_f( i,j,3*i+j+1)
|
13
|
+
}}
|
14
|
+
@epsilon = 1e-3
|
15
|
+
end
|
16
|
+
|
17
|
+
def random_matrix( x, y )
|
18
|
+
a = CVFFI::CvMat.new CVFFI::cvCreateMat( x, y, :CV_32F )
|
19
|
+
x.times { |i|
|
20
|
+
y.times { |j|
|
21
|
+
CVFFI::cvSetReal2D( a, i, j, rand )
|
22
|
+
}
|
23
|
+
}
|
24
|
+
a
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_svd
|
28
|
+
# Test matrix [ 1,2,3
|
29
|
+
# 4,5,6
|
30
|
+
# 7,8,9 ]
|
31
|
+
a = @a
|
32
|
+
u,d,v = CVFFI::Eigen::svd( a )
|
33
|
+
|
34
|
+
CVFFI::print_matrix a, {:caption => "a"}
|
35
|
+
CVFFI::print_matrix u, {:caption => "w"}
|
36
|
+
CVFFI::print_matrix d, {:caption => "u"}
|
37
|
+
CVFFI::print_matrix v, {:caption => "v"}
|
38
|
+
|
39
|
+
|
40
|
+
## Test results from alpha
|
41
|
+
uans = Matrix.rows( [ [0.214837 , 0.887231 , 0.408248 ],
|
42
|
+
[0.520587 , 0.249644 , -0.816497 ],
|
43
|
+
[0.826338 , -0.387943 , 0.408248 ] ] )
|
44
|
+
dans = [16.8481 , 1.06837 , 0.0 ]
|
45
|
+
vans = Matrix.rows( [ [0.479671 , -0.776691 , 0.408248 ],
|
46
|
+
[0.572368 , -0.0756865 , -0.816497],
|
47
|
+
[0.665064 , 0.625318 , 0.408248] ] )
|
48
|
+
|
49
|
+
# Check the SVDs
|
50
|
+
dans.each_with_index { |dans,i| assert_in_delta d.at_f(i,0), dans, @epsilon }
|
51
|
+
|
52
|
+
3.times{ |j|
|
53
|
+
# Check the original matrix
|
54
|
+
3.times { |i|
|
55
|
+
assert_equal a.at_f( i,j ), 3*i+j+1
|
56
|
+
}
|
57
|
+
2.times { |i|
|
58
|
+
# Because there's scalar ambiguity in the third column
|
59
|
+
# check ratios instead
|
60
|
+
assert_in_delta u.at_f(i,j)/u.at_f(i+1,j), uans[i,j]/uans[i+1,j], @epsilon
|
61
|
+
assert_in_delta v.at_f(i,j)/v.at_f(i+1,j), vans[i,j]/vans[i+1,j], @epsilon
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_eigen
|
67
|
+
a = @a
|
68
|
+
d,v = CVFFI::Eigen::eigen(a)
|
69
|
+
|
70
|
+
CVFFI::print_matrix d, {:caption=>"d"}
|
71
|
+
CVFFI::print_matrix v, {:caption=>"v"}
|
72
|
+
|
73
|
+
# From Wolfram alpha
|
74
|
+
dans = [ 16.1168, -1.11684, 0 ]
|
75
|
+
vans = [[0.283349, 0.641675, 1.0], [-1.28335, -0.141675, 1.0], [1.0, -2.0, 1.0 ] ]
|
76
|
+
|
77
|
+
3.times { |i|
|
78
|
+
assert_in_delta d.at_f(i,0), dans[i], @epsilon
|
79
|
+
|
80
|
+
# Ratio test on elements of eigenvectors
|
81
|
+
assert_in_delta v.at_f(0,i)/v.at_f(1,i), vans[i][0]/vans[i][1], @epsilon
|
82
|
+
assert_in_delta v.at_f(0,i)/v.at_f(2,i), vans[i][0]/vans[i][2], @epsilon
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_poly
|
90
|
+
|
91
|
+
# Should be coefficients for (t-1)(t-2)...(t-6) in ascending
|
92
|
+
# coefficient order...
|
93
|
+
coeffs = [ 720.0, -1764.0, 1624.0, -735.0, 175.0, -21.0, 1.0 ]
|
94
|
+
# Eigen expects polynomial in ascending order
|
95
|
+
roots = CVFFI::Eigen::polySolver( coeffs )
|
96
|
+
roots.sort!
|
97
|
+
|
98
|
+
|
99
|
+
6.times { |i|
|
100
|
+
assert_in_delta roots[i], (i+1).to_f, @epsilon
|
101
|
+
}
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'test/setup'
|
4
|
+
|
5
|
+
require 'opencv-ffi'
|
6
|
+
require 'opencv-ffi-ext/opensurf'
|
7
|
+
|
8
|
+
class TestOpenSURF < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_openSurfDetect
|
15
|
+
img = TestSetup::test_image
|
16
|
+
|
17
|
+
params = CVFFI::OpenSURF::Params.new
|
18
|
+
|
19
|
+
# This should test the auto=conversion to greyscale
|
20
|
+
surf = CVFFI::OpenSURF::detect( img, params )
|
21
|
+
|
22
|
+
assert_not_nil surf
|
23
|
+
|
24
|
+
surf.mark_on_image( img, {:radius=>5, :thickness=>-1} )
|
25
|
+
CVFFI::cvSaveImage( TestSetup::output_filename("openSurfPts.jpg"), img )
|
26
|
+
|
27
|
+
puts "OpenSURF detected #{surf.length} points"
|
28
|
+
|
29
|
+
|
30
|
+
descriptors = CVFFI::OpenSURF::describe( img, surf, params )
|
31
|
+
|
32
|
+
puts "After description #{descriptors.length} points"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'test/setup'
|
3
|
+
|
4
|
+
require 'opencv-ffi'
|
5
|
+
require 'opencv-ffi-ext/sift'
|
6
|
+
|
7
|
+
class TestSIFT < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def test_siftDetect
|
14
|
+
img = TestSetup::small_test_image
|
15
|
+
|
16
|
+
params = CVFFI::SIFT::Params.new( octaves: 1 )
|
17
|
+
|
18
|
+
# This should test the auto=conversion to greyscale
|
19
|
+
sift = CVFFI::SIFT::detect( img, params )
|
20
|
+
|
21
|
+
assert_not_nil sift
|
22
|
+
|
23
|
+
puts "SIFT detected #{sift.length} points."
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|