Class: CVFFI::ImagePatch::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/opencv-ffi-wrappers/features2d/image_patch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(center, patch, angle = 0.0, isOriented = false) ⇒ Result

Returns a new instance of Result.



79
80
81
82
83
84
85
86
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 79

def initialize( center, patch, angle = 0.0, isOriented = false )
  @center = CVFFI::Point.new center
    @patch = CVFFI::Mat.rows( patch, :CV_8U )
  @angle = angle

  # Set this if the patch has already been rotated
  @oriented_patch = @patch if isOriented
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



77
78
79
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 77

def angle
  @angle
end

#centerObject

Returns the value of attribute center.



76
77
78
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 76

def center
  @center
end

Class Method Details

.from_a(a) ⇒ Object



123
124
125
126
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 123

def self.from_a(a)
# Serialized results are always oriented
Result.new( CVFFI::Point.new( a[0],a[1] ), a[3],a[2], true )
end

Instance Method Details

#==(b) ⇒ Object



88
89
90
91
92
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 88

def ==(b)
  @center == b.center and
  @angle == b.angle and
  @patch == b.patch
end

#distance_to(b) ⇒ Object



119
120
121
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 119

def distance_to( b )
  patch.l2distance( b.patch )
end

#orient_patchObject

TODO: Consider whether rotating just the patch is ever a good idea or if you should always get the patch by rotating the original image



96
97
98
99
100
101
102
103
104
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 96

def orient_patch
  rotmat = CVFFI::CvMat.new CVFFI::cvCreateMat( 2,3, :CV_32F )
  CVFFI::cv2DRotationMatrix( CVFFI::CvPoint2D32f.new( [ @patch.width/2.0, @patch.height/2.0 ]), -@angle*180.0/Math::PI, 1.0, rotmat )

  dstimg = @patch.twin
  CVFFI::cvWarpAffine( @patch, dstimg, rotmat )

   dstimg 
end

#oriented_patchObject



106
107
108
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 106

def oriented_patch
  @oriented_patch ||= orient_patch
end

#patch(oriented = true) ⇒ Object



110
111
112
113
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 110

def patch( oriented = true )
  return @patch if angle == 0.0 or oriented == false
  oriented_patch
end

#to_aObject



115
116
117
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 115

def to_a
  [ center.x, center.y, angle, oriented_patch.to_a ]
end