Module: CVFFI::SURF

Defined in:
lib/opencv-ffi-wrappers/features2d/surf.rb

Defined Under Namespace

Classes: Result, ResultsArray

Class Method Summary collapse

Class Method Details

.detect(img, params) ⇒ Object

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/opencv-ffi-wrappers/features2d/surf.rb', line 87

def self.detect( img, params )

  raise ArgumentError unless params.is_a?( CvSURFParams ) || params.is_a?( Params )

  img = CVFFI::IplImage.new img.to_IplImage

  if img.nChannels == 3
    greyImg = CVFFI::cvCreateImage( CVFFI::CvSize.new( :height => img.height,
                                                       :width => img.width ),
                                                       :IPL_DEPTH_8U, 1 )
    CVFFI::cvCvtColor( img, greyImg, :CV_RGB2GRAY )
  else
    greyImg = img
  end

  kp_ptr = FFI::MemoryPointer.new :pointer
  desc_ptr = FFI::MemoryPointer.new :pointer

  mem_storage = CVFFI::cvCreateMemStorage( 0 )

  CVFFI::cvExtractSURF( greyImg, nil, kp_ptr, desc_ptr, mem_storage, params, :false )

  keypoints = CVFFI::CvSeq.new( kp_ptr.read_pointer() )
  descriptors = CVFFI::CvSeq.new( desc_ptr.read_pointer() )

  ResultsArray.new( keypoints, descriptors, mem_storage )
end