Class: CVFFI::Scalar
- Inherits:
-
Object
- Object
- CVFFI::Scalar
- Defined in:
- lib/opencv-ffi-wrappers/core/scalar.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #[]=(i, x) ⇒ Object
- #color_symbols ⇒ Object
-
#initialize(*args) ⇒ Scalar
constructor
A new instance of Scalar.
- #to_CvScalar ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Scalar
Returns a new instance of Scalar.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 31 def initialize( *args ) @order = :BGR w=x=y=z=0 if args[0].is_a?( Hash ) args = args[0] @order = args[:channel_order] if args[:channel_order] a,b,c,d = color_symbols w = args[:w] || args[a] || args[a.upcase] || 0 x = args[:x] || args[b] || args[b.upcase] || 0 y = args[:y] || args[c] || args[c.upcase] || 0 z = args[:z] || args[d] || args[d.upcase] || 0 else w,x,y,z = args end @s = CVFFI::CvScalar.new( :w => w, :x => x, :y => y, :z => z ) end |
Instance Method Details
#[](i) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 83 def [](i) a,b,c,d = color_symbols case i.downcase when :w,a then @s.w when :x,b then @s.x when :y,c then @s.y when :z,d then @s.z else nil end end |
#[]=(i, x) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 65 def []=(i,x) a,b,c,d = color_symbols case i.downcase when :w,a then @s.w = x when :x,b then @s.x = x when :y,c then @s.y = x when :z,d then @s.z = x else raise "Hm, don't understand index to CVFFI::Scalar[]=" end end |
#color_symbols ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 52 def color_symbols case @order when :BGR then [ :b, :g, :r, :a ] else raise "Hm, the Scalar::order is undefined" end end |
#to_CvScalar ⇒ Object
61 62 63 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 61 def to_CvScalar @s end |
#to_s ⇒ Object
100 101 102 |
# File 'lib/opencv-ffi-wrappers/core/scalar.rb', line 100 def to_s "CvScalar(#{ [@s.w, @s.w, @s.y, @s.z].join(',') })" end |