Class: OpenCV::CvKNearest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ CvKNearest

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 CvKNearest.



19931
19932
19933
19934
19935
19936
19937
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19931

def initialize(ptr)
    @__obj_ptr__ = if ptr.is_a? CvKNearestStruct
                       ptr
                   else
                       CvKNearestStruct.new(FFI::AutoPointer.new(ptr,CvKNearestStruct.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.



19928
19929
19930
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19928

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



19923
19924
19925
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19923

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

.new(*args) ⇒ Object

Raises:

  • (ArgumentError)


19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19867

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

    # wrapper for CvKNearest::CvKNearest(const cv::Mat trainData, const cv::Mat responses, const cv::Mat sampleIdx=cv::Mat(), bool isRegression=false, int max_k=32)
    @@cvk_nearest_cvk_nearest2_defaults1 ||= [nil, nil, Cv::Mat.new(), false, 32]
    if(args.size >= 2 && args.size <= 5)
        args.size.upto(4) do |i|
            args[i] = @@cvk_nearest_cvk_nearest2_defaults1[i]
        end
        begin
            return Rbind::cvk_nearest_cvk_nearest2(*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.



19911
19912
19913
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19911

def self.rbind_from_native(ptr,context)
    CvKNearest.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.



19902
19903
19904
19905
19906
19907
19908
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19902

def self.rbind_to_native(obj,context)
    if obj.is_a? CvKNearest
        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



19917
19918
19919
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19917

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)


19942
19943
19944
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19942

def __owner__?
    @__obj_ptr__[:bowner]
end

#find_nearest(samples, k, results, neighbor_responses, dists) ⇒ Object

wrapper for float CvKNearest::find_nearest(const cv::Mat samples, int k, cv::Mat results, cv::Mat neighborResponses, cv::Mat dists)



19961
19962
19963
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19961

def find_nearest(samples, k, results, neighbor_responses, dists)
    Rbind::cvk_nearest_find_nearest( self, samples, k, results, neighbor_responses, dists)
end

#load(filename, name = 0) ⇒ Object

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



19971
19972
19973
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19971

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

#save(filename, name = 0) ⇒ Object

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



19966
19967
19968
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19966

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

#train(train_data, responses, sample_idx = Cv::Mat.new(), is_regression = false, max_k = 32, update_base = false) ⇒ Object

methods wrapper for bool CvKNearest::train(const cv::Mat trainData, const cv::Mat responses, const cv::Mat sampleIdx=cv::Mat(), bool isRegression=false, int maxK=32, bool updateBase=false)



19956
19957
19958
# File 'lib/ruby/ropencv/ropencv_types.rb', line 19956

def train(train_data, responses, sample_idx = Cv::Mat.new(), is_regression = false, max_k = 32, update_base = false)
    Rbind::cvk_nearest_train( self, train_data, responses, sample_idx, is_regression, max_k, update_base)
end