Class: OpenCV::CvSVM

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter
Defined in:
lib/ruby/ropencv/ropencv_types.rb

Constants collapse

C_SVC =
100
NU_SVC =
101
ONE_CLASS =
102
EPS_SVR =
103
NU_SVR =
104
LINEAR =
0
POLY =
1
RBF =
2
SIGMOID =
3
C =
0
GAMMA =
1
P =
2
NU =
3
COEF =
4
DEGREE =
5

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ CvSVM

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CvSVM.



20247
20248
20249
20250
20251
20252
20253
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20247

def initialize(ptr)
    @__obj_ptr__ = if ptr.is_a? CvSVMStruct
                       ptr
                   else
                       CvSVMStruct.new(FFI::AutoPointer.new(ptr,CvSVMStruct.method(:release)))
                   end
end

Instance Attribute Details

#__obj_ptr__Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20244
20245
20246
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20244

def __obj_ptr__
  @__obj_ptr__
end

Class Method Details

.from_native(ptr, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

can be overwritten by the user



20239
20240
20241
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20239

def self.from_native(ptr,context)
    rbind_from_native(ptr,context)
end

.new(*args) ⇒ Object

Raises:

  • (ArgumentError)


20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20183

def self.new(*args)
    if args.first.is_a?(FFI::Pointer) || args.first.is_a?(CvSVMStruct)
        raise ArgumentError, "too many arguments for creating #{self.name} from Pointer" unless args.size == 1
        return super(args.first)
    end
    # wrapper for CvSVM::CvSVM()
    @@cvsvm_cvsvm_defaults0 ||= []
    if(args.size >= 0 && args.size <= 0)
        args.size.upto(-1) do |i|
            args[i] = @@cvsvm_cvsvm_defaults0[i]
        end
        begin
            return Rbind::cvsvm_cvsvm(*args)
        rescue TypeError => e
            @error = e
        end
    end

    # wrapper for CvSVM::CvSVM(const cv::Mat trainData, const cv::Mat responses, const cv::Mat varIdx=cv::Mat(), const cv::Mat sampleIdx=cv::Mat(), const CvSVMParams params=CvSVMParams())
    @@cvsvm_cvsvm2_defaults1 ||= [nil, nil, Cv::Mat.new(), Cv::Mat.new(), CvSVMParams.new()]
    if(args.size >= 2 && args.size <= 5)
        args.size.upto(4) do |i|
            args[i] = @@cvsvm_cvsvm2_defaults1[i]
        end
        begin
            return Rbind::cvsvm_cvsvm2(*args)
        rescue TypeError => e
            @error = e
        end
    end

    raise ArgumentError, "no constructor for #{self}(#{args.inspect})"
end

.rbind_from_native(ptr, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20227
20228
20229
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20227

def self.rbind_from_native(ptr,context)
    CvSVM.new(ptr)
end

.rbind_to_native(obj, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20218
20219
20220
20221
20222
20223
20224
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20218

def self.rbind_to_native(obj,context)
    if obj.is_a? CvSVM
        obj.__obj_ptr__
    else
        raise TypeError, "expected kind of #{name}, was #{obj.class}"
    end
end

.to_native(obj, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

can be overwritten by the user



20233
20234
20235
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20233

def self.to_native(obj,context)
    rbind_to_native(obj,context)
end

Instance Method Details

#__owner__?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

returns true if the underlying pointer is owner of the real object

Returns:

  • (Boolean)


20258
20259
20260
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20258

def __owner__?
    @__obj_ptr__[:bowner]
end

#clearObject

wrapper for void CvSVM::clear()



20312
20313
20314
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20312

def clear()
    Rbind::cvsvm_clear( self)
end

#get_support_vector_countObject

wrapper for int CvSVM::get_support_vector_count()



20307
20308
20309
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20307

def get_support_vector_count()
    Rbind::cvsvm_get_support_vector_count( self)
end

#get_var_countObject

wrapper for int CvSVM::get_var_count()



20317
20318
20319
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20317

def get_var_count()
    Rbind::cvsvm_get_var_count( self)
end

#load(filename, name = 0) ⇒ Object

wrapper for void CvSVM::load(c_string filename, c_string name=0)



20327
20328
20329
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20327

def load(filename, name = 0)
    Rbind::cvsvm_load( self, filename, name)
end

#predict(sample, return_d_f_val = false) ⇒ Object

wrapper for float CvSVM::predict(const cv::Mat sample, bool returnDFVal=false)



20297
20298
20299
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20297

def predict(sample, return_d_f_val = false)
    Rbind::cvsvm_predict( self, sample, return_d_f_val)
end

#predict_all(samples, results) ⇒ Object

wrapper for void CvSVM::predict(const cv::Mat samples, cv::Mat results)



20302
20303
20304
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20302

def predict_all(samples, results)
    Rbind::cvsvm_predict_all( self, samples, results)
end

#save(filename, name = 0) ⇒ Object

wrapper for void CvSVM::save(c_string filename, c_string name=0)



20322
20323
20324
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20322

def save(filename, name = 0)
    Rbind::cvsvm_save( self, filename, name)
end

#train(train_data, responses, var_idx = Cv::Mat.new(), sample_idx = Cv::Mat.new(), params = CvSVMParams.new()) ⇒ Object

methods wrapper for bool CvSVM::train(const cv::Mat trainData, const cv::Mat responses, const cv::Mat varIdx=cv::Mat(), const cv::Mat sampleIdx=cv::Mat(), const CvSVMParams params=CvSVMParams())



20287
20288
20289
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20287

def train(train_data, responses, var_idx = Cv::Mat.new(), sample_idx = Cv::Mat.new(), params = CvSVMParams.new())
    Rbind::cvsvm_train( self, train_data, responses, var_idx, sample_idx, params)
end

#train_auto(train_data, responses, var_idx, sample_idx, params, k_fold = 10, cgrid = CvSVM.new(CvSVM::C), gamma_grid = CvSVM.new(CvSVM::GAMMA), p_grid = CvSVM.new(CvSVM::P), nu_grid = CvSVM.new(CvSVM::NU), coeff_grid = CvSVM.new(CvSVM::COEF), degree_grid = CvSVM.new(CvSVM::DEGREE), balanced = false) ⇒ Object

wrapper for bool CvSVM::train_auto(const cv::Mat trainData, const cv::Mat responses, const cv::Mat varIdx, const cv::Mat sampleIdx, const CvSVMParams params, int k_fold=10, const CvParamGrid Cgrid=CvSVM::get_default_grid(CvSVM::C), const CvParamGrid gammaGrid=CvSVM::get_default_grid(CvSVM::GAMMA), const CvParamGrid pGrid=CvSVM::get_default_grid(CvSVM::P), const CvParamGrid nuGrid=CvSVM::get_default_grid(CvSVM::NU), const CvParamGrid coeffGrid=CvSVM::get_default_grid(CvSVM::COEF), const CvParamGrid degreeGrid=CvSVM::get_default_grid(CvSVM::DEGREE), bool balanced=false)



20292
20293
20294
# File 'lib/ruby/ropencv/ropencv_types.rb', line 20292

def train_auto(train_data, responses, var_idx, sample_idx, params, k_fold = 10, cgrid = CvSVM.new(CvSVM::C), gamma_grid = CvSVM.new(CvSVM::GAMMA), p_grid = CvSVM.new(CvSVM::P), nu_grid = CvSVM.new(CvSVM::NU), coeff_grid = CvSVM.new(CvSVM::COEF), degree_grid = CvSVM.new(CvSVM::DEGREE), balanced = false)
    Rbind::cvsvm_train_auto( self, train_data, responses, var_idx, sample_idx, params, k_fold, cgrid, gamma_grid, p_grid, nu_grid, coeff_grid, degree_grid, balanced)
end