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
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'opencv-ffi-wrappers/core'
|
3
|
+
require 'opencv-ffi-wrappers/core/point'
|
4
|
+
|
5
|
+
module CVFFI
|
6
|
+
|
7
|
+
def self.draw_circle( img, point, opts={} )
|
8
|
+
color = opts[:color] || CVFFI::CvScalar.new( {:w=>255, :x=>255, :y=>255, :z=>0} )
|
9
|
+
thickness = opts[:thickness] || 5
|
10
|
+
radius = opts[:radius] || 1
|
11
|
+
|
12
|
+
CVFFI::cvCircle( img.to_IplImage, point.to_CvPoint, radius, color, thickness,8,0 )
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.draw_point( img, point, opts={} )
|
16
|
+
opts[:thickness] = -1
|
17
|
+
draw_circle( img, point, opts )
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def self.draw_line( img, aPoint, bPoint, opts )
|
22
|
+
color = opts[:color] || CVFFI::CvScalar.new( {:w=>255, :x=>255, :y=>255, :z=>0} )
|
23
|
+
thickness = opts[:thickness] || 5
|
24
|
+
|
25
|
+
CVFFI::cvLine( img.to_IplImage, aPoint.to_CvPoint, bPoint.to_CvPoint, color, thickness, 8, 0 )
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.put_text( img, text, point, opts = {} )
|
29
|
+
color = opts[:color] || CVFFI::Scalar.new( 255,255,255,0 )
|
30
|
+
thickness = opts[:thickness] || 2
|
31
|
+
face = opts[:face] || opts[:typeface] || :CV_FONT_HERSHEY_SIMPLEX
|
32
|
+
font = opts[:font] || nil
|
33
|
+
hscale = opts[:hscale] || opts[:scale] || 1.0
|
34
|
+
vscale = opts[:vscale] || opts[:scale] || hscale
|
35
|
+
shear = opts[:shear] || 0.0
|
36
|
+
|
37
|
+
unless font
|
38
|
+
font = CVFFI::CvFont.new '\0'
|
39
|
+
CVFFI::cvInitFont( font, face, hscale, vscale, shear, thickness, :CV_AA )
|
40
|
+
end
|
41
|
+
|
42
|
+
CVFFI::cvPutText( img.to_IplImage, text, point.to_CvPoint, font, color.to_CvScalar )
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
|
2
|
+
require 'opencv-ffi/core/types'
|
3
|
+
|
4
|
+
module CVFFI
|
5
|
+
|
6
|
+
module CvPointMethods
|
7
|
+
def got_what_i_need(a)
|
8
|
+
a.class.method_defined?(:x) and a.class.method_defined?(:y)
|
9
|
+
end
|
10
|
+
|
11
|
+
def /(a)
|
12
|
+
if got_what_i_need a
|
13
|
+
self.class.new( [ x.to_f/a.x.to_f, y.to_f/a.y.to_f ] )
|
14
|
+
else
|
15
|
+
self.class.new( [ x.to_f/a, y.to_f/a ] )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def *(a)
|
20
|
+
if got_what_i_need a
|
21
|
+
self.class.new( [ x*a.x, y*a.y ] )
|
22
|
+
else
|
23
|
+
self.class.new( [ x*a, y*a ] )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def -(a)
|
28
|
+
if got_what_i_need a
|
29
|
+
self.class.new( [ x.to_f-a.x, y.to_f-a.y ] )
|
30
|
+
else
|
31
|
+
self.class.new( [ x.to_f-a, y.to_f-a ] )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def +(a)
|
36
|
+
if got_what_i_need a
|
37
|
+
self.class.new( [ x+a.x, y+a.y ] )
|
38
|
+
else
|
39
|
+
self.class.new( [ x+a, y+a ] )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def rotate( rads )
|
44
|
+
sa = Math::sin rads
|
45
|
+
ca = Math::cos rads
|
46
|
+
self.class.new( x*ca - y*sa,
|
47
|
+
x*sa + y*ca )
|
48
|
+
end
|
49
|
+
|
50
|
+
def ==(b)
|
51
|
+
@x == b.x and @y == b.y
|
52
|
+
end
|
53
|
+
def ===(b)
|
54
|
+
@x === b.x and @y === b.y
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_Vector( homogeneous = true )
|
58
|
+
Vector.elements( to_a( homogeneous ) )
|
59
|
+
end
|
60
|
+
alias :to_vector :to_Vector
|
61
|
+
|
62
|
+
def to_a(homogeneous=true)
|
63
|
+
if homogeneous
|
64
|
+
[ @x/@w, @y/@w, 1.0 ]
|
65
|
+
else
|
66
|
+
[ @x, @y ]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def neighbor?( p, radius )
|
71
|
+
return false if (x-p.x).abs > radius or (y-p.y).abs > radius
|
72
|
+
return false if l2distance(p) > radius
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def neighbor_rsquared?( p, rsquared )
|
77
|
+
return false if l2_squared_distance(p) > rsquared
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
def l2distance( b )
|
82
|
+
Math::sqrt( l2_squared_distance(b) )
|
83
|
+
end
|
84
|
+
alias :distance_to :l2distance
|
85
|
+
|
86
|
+
def l2_squared_distance( b )
|
87
|
+
(x-b.x)**2 + (y-b.y)**2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
module CvPointCastMethods
|
92
|
+
def to_CvPoint2D64f
|
93
|
+
CvPoint2D64f.new( :x => x, :y => y )
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_CvPoint2D32f
|
97
|
+
CvPoint2D32f.new( :x => x, :y => y )
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_CvPoint
|
101
|
+
CvPoint.new( :x => x.to_i, :y => y.to_i )
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_Point
|
105
|
+
Point.new( x, y )
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_a(homogeneous=true)
|
109
|
+
if homogeneous
|
110
|
+
[ x, y, 1 ]
|
111
|
+
else
|
112
|
+
[x,y]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class CvPointBase
|
118
|
+
include CvPointMethods
|
119
|
+
include CvPointCastMethods
|
120
|
+
end
|
121
|
+
|
122
|
+
class CvPoint; def to_CvPoint; self; end; end
|
123
|
+
class CvPoint2D32f; def to_CvPoint2D32f; self; end; end
|
124
|
+
class CvPoint2D64f; def to_CvPoint2D64f; self; end; end
|
125
|
+
|
126
|
+
class Point
|
127
|
+
include CvPointCastMethods
|
128
|
+
include CvPointMethods
|
129
|
+
|
130
|
+
attr_accessor :w, :y, :x
|
131
|
+
|
132
|
+
def initialize( *args )
|
133
|
+
if args.length == 2 and args[1] != nil
|
134
|
+
@x = args[0]
|
135
|
+
@y = args[1]
|
136
|
+
else
|
137
|
+
args = args.shift
|
138
|
+
|
139
|
+
case args
|
140
|
+
when Hash
|
141
|
+
@y = args[:y]
|
142
|
+
@x = args[:x]
|
143
|
+
when Array
|
144
|
+
@x = args[0]
|
145
|
+
@y = args[1]
|
146
|
+
else
|
147
|
+
@x = args.x
|
148
|
+
@y = args.y
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
@x = @x.to_f
|
153
|
+
@y = @y.to_f
|
154
|
+
@w = 1
|
155
|
+
end
|
156
|
+
|
157
|
+
def area
|
158
|
+
@y*@x
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
#===========================================================
|
163
|
+
module CvPoint3DMethods
|
164
|
+
def got_what_i_need(a)
|
165
|
+
a.method_defined?(:x) and a.method_defined?(:y) and a.method_defined(:z)
|
166
|
+
end
|
167
|
+
|
168
|
+
def /(a)
|
169
|
+
if a.is_a? Point3D
|
170
|
+
self.class.new( [ x.to_f/a.x.to_f, y.to_f/a.y.to_f, z.to_f/a.z.to_f ] )
|
171
|
+
else
|
172
|
+
self.class.new( [ x.to_f/a, y.to_f/a, z.to_f/z ] )
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def *(a)
|
177
|
+
if a.is_a? Point3D
|
178
|
+
self.class.new( [ x*a.x, y*a.y, z*a.z ] )
|
179
|
+
else
|
180
|
+
self.class.new( [ x*a, y*a, z*a.z ] )
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def -(a)
|
185
|
+
if a.is_a? Point3D
|
186
|
+
self.class.new( [ x.to_f-a.x, y.to_f-a.y, z.to_f-a.z ] )
|
187
|
+
else
|
188
|
+
self.class.new( [ x.to_f-a, y.to_f-a, z.to_f-a ] )
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def +(a)
|
193
|
+
if a.is_a? Point3D
|
194
|
+
self.class.new( [ x+a.x, y+a.y, z+a.z ] )
|
195
|
+
else
|
196
|
+
self.class.new( [ x+a, y+a, z+a ] )
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def ==(b)
|
201
|
+
@x == b.x and @y == b.y and @z == b.z
|
202
|
+
end
|
203
|
+
def ===(b)
|
204
|
+
@x === b.x and @y === b.y and @z === b.z
|
205
|
+
end
|
206
|
+
|
207
|
+
def to_Vector( homogeneous = true )
|
208
|
+
Vector.elements( to_a(homogeneous) )
|
209
|
+
end
|
210
|
+
alias :to_vector :to_Vector
|
211
|
+
|
212
|
+
def to_a(homogeneous=true)
|
213
|
+
if homogeneous
|
214
|
+
[@x/@w, @y/@w, @z/@w, 1]
|
215
|
+
else
|
216
|
+
[@x, @y, @z]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
module CvPoint3DCastMethods
|
223
|
+
def to_CvPoint3D64f
|
224
|
+
CvPoint3D64f.new( :x => x, :y => y, :z => z )
|
225
|
+
end
|
226
|
+
|
227
|
+
def to_CvPoint3D32f
|
228
|
+
CvPoint3D32f.new( :x => x, :y => y, :z => z )
|
229
|
+
end
|
230
|
+
|
231
|
+
def to_a( homogeneous = true )
|
232
|
+
if homogeneous
|
233
|
+
[x,y,z,1]
|
234
|
+
else
|
235
|
+
[x,y,z]
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
class CvPoint3DBase
|
241
|
+
include CvPoint3DMethods
|
242
|
+
include CvPoint3DCastMethods
|
243
|
+
end
|
244
|
+
|
245
|
+
class CvPoint3D32f; def to_CvPoint3D32f; self; end; end
|
246
|
+
class CvPoint3D64f; def to_CvPoint3D64f; self; end; end
|
247
|
+
|
248
|
+
class Point3D
|
249
|
+
include CvPoint3DCastMethods
|
250
|
+
include CvPoint3DMethods
|
251
|
+
|
252
|
+
attr_accessor :w, :z, :y, :x
|
253
|
+
|
254
|
+
def initialize( *args )
|
255
|
+
if args.length == 3
|
256
|
+
@x = args[0]
|
257
|
+
@y = args[1]
|
258
|
+
@z = args[2]
|
259
|
+
else
|
260
|
+
args = args.shift
|
261
|
+
|
262
|
+
case args
|
263
|
+
when Hash
|
264
|
+
@z = args[:z]
|
265
|
+
@y = args[:y]
|
266
|
+
@x = args[:x]
|
267
|
+
when Array
|
268
|
+
@x = args[0]
|
269
|
+
@y = args[1]
|
270
|
+
@z = args[2]
|
271
|
+
else
|
272
|
+
@x = args.x
|
273
|
+
@y = args.y
|
274
|
+
@z = args.z
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
@w = 1
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
require 'opencv-ffi-wrappers/core'
|
3
|
+
|
4
|
+
module CVFFI
|
5
|
+
|
6
|
+
class Rect
|
7
|
+
attr_accessor :size, :origin
|
8
|
+
|
9
|
+
def initialize( args )
|
10
|
+
case args
|
11
|
+
when Array
|
12
|
+
@origin = Point.new( args[0..1] )
|
13
|
+
@size = Size.new( args[2..3] )
|
14
|
+
when Hash
|
15
|
+
if args[:size]
|
16
|
+
@size = Size.new args[:size]
|
17
|
+
else
|
18
|
+
@size = Size.new(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
if args[:origin]
|
22
|
+
@origin = Point.new( args[:origin] )
|
23
|
+
elsif args[:center]
|
24
|
+
@origin = Point.new( args[:center] - @size/2.0 )
|
25
|
+
else
|
26
|
+
@origin = Point.new(args)
|
27
|
+
end
|
28
|
+
|
29
|
+
else
|
30
|
+
@size = Size.new args.size
|
31
|
+
@origin = Point.new args.origin
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_CvRect
|
36
|
+
CvRect.new( :x => @origin.x, :y => @origin.y,
|
37
|
+
:width => @size.width, :height => @size.height )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
require 'opencv-ffi/core/types'
|
3
|
+
require 'opencv-ffi-wrappers/core'
|
4
|
+
|
5
|
+
|
6
|
+
module CVFFI
|
7
|
+
|
8
|
+
module CvScalarFunctions
|
9
|
+
def self.included(base)
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_CvScalar
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class CvMat
|
24
|
+
include CvMatFunctions
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
class Scalar
|
30
|
+
|
31
|
+
def initialize( *args )
|
32
|
+
@order = :BGR
|
33
|
+
w=x=y=z=0
|
34
|
+
|
35
|
+
if args[0].is_a?( Hash )
|
36
|
+
args = args[0]
|
37
|
+
|
38
|
+
@order = args[:channel_order] if args[:channel_order]
|
39
|
+
a,b,c,d = color_symbols
|
40
|
+
|
41
|
+
w = args[:w] || args[a] || args[a.upcase] || 0
|
42
|
+
x = args[:x] || args[b] || args[b.upcase] || 0
|
43
|
+
y = args[:y] || args[c] || args[c.upcase] || 0
|
44
|
+
z = args[:z] || args[d] || args[d.upcase] || 0
|
45
|
+
else
|
46
|
+
w,x,y,z = args
|
47
|
+
end
|
48
|
+
|
49
|
+
@s = CVFFI::CvScalar.new( :w => w, :x => x, :y => y, :z => z )
|
50
|
+
end
|
51
|
+
|
52
|
+
def color_symbols
|
53
|
+
case @order
|
54
|
+
when :BGR then
|
55
|
+
[ :b, :g, :r, :a ]
|
56
|
+
else
|
57
|
+
raise "Hm, the Scalar::order is undefined"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_CvScalar
|
62
|
+
@s
|
63
|
+
end
|
64
|
+
|
65
|
+
def []=(i,x)
|
66
|
+
a,b,c,d = color_symbols
|
67
|
+
|
68
|
+
case i.downcase
|
69
|
+
when :w,a then
|
70
|
+
@s.w = x
|
71
|
+
when :x,b then
|
72
|
+
@s.x = x
|
73
|
+
when :y,c then
|
74
|
+
@s.y = x
|
75
|
+
when :z,d then
|
76
|
+
@s.z = x
|
77
|
+
else
|
78
|
+
raise "Hm, don't understand index to CVFFI::Scalar[]="
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def [](i)
|
84
|
+
a,b,c,d = color_symbols
|
85
|
+
|
86
|
+
case i.downcase
|
87
|
+
when :w,a then
|
88
|
+
@s.w
|
89
|
+
when :x,b then
|
90
|
+
@s.x
|
91
|
+
when :y,c then
|
92
|
+
@s.y
|
93
|
+
when :z,d then
|
94
|
+
@s.z
|
95
|
+
else
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_s
|
101
|
+
"CvScalar(#{ [@s.w, @s.w, @s.y, @s.z].join(',') })"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|