mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Added CvMat#normalize from https://github.com/bonanza-market/ruby-opencv .
This commit is contained in:
parent
96c63eac86
commit
b7dff7e475
3 changed files with 37 additions and 0 deletions
|
@ -261,6 +261,7 @@ void define_ruby_class()
|
|||
rb_define_method(rb_klass, "ne", RUBY_METHOD_FUNC(rb_ne), 1);
|
||||
rb_define_method(rb_klass, "in_range", RUBY_METHOD_FUNC(rb_in_range), 2);
|
||||
rb_define_method(rb_klass, "abs_diff", RUBY_METHOD_FUNC(rb_abs_diff), 1);
|
||||
rb_define_method(rb_klass, "normalize", RUBY_METHOD_FUNC(rb_normalize), -1);
|
||||
rb_define_method(rb_klass, "count_non_zero", RUBY_METHOD_FUNC(rb_count_non_zero), 0);
|
||||
rb_define_method(rb_klass, "sum", RUBY_METHOD_FUNC(rb_sum), 0);
|
||||
rb_define_method(rb_klass, "avg", RUBY_METHOD_FUNC(rb_avg), -1);
|
||||
|
@ -2250,6 +2251,35 @@ rb_abs_diff(VALUE self, VALUE val)
|
|||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* normalize(...) -> cvmat
|
||||
*
|
||||
* Normalizes the norm or value range of an array
|
||||
*/
|
||||
VALUE
|
||||
rb_normalize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE alphaVal, betaVal, normTypeVal;
|
||||
rb_scan_args(argc, argv, "03", &alphaVal, &betaVal, &normTypeVal);
|
||||
|
||||
const double alpha = alphaVal != Qnil ? NUM2DBL(alphaVal) : 1.0;
|
||||
const double beta = betaVal != Qnil ? NUM2DBL(betaVal) : 0.0;
|
||||
const int normType = normTypeVal != Qnil ? NUM2INT(normTypeVal) : cv::NORM_L2;
|
||||
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
try {
|
||||
const cv::Mat selfMat(CVMAT(self));
|
||||
cv::Mat destMat(CVMAT(dest));
|
||||
|
||||
cv::normalize(selfMat, destMat, alpha, beta, normType);
|
||||
|
||||
} catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* count_non_zero -> int
|
||||
|
|
|
@ -107,6 +107,7 @@ VALUE rb_le(VALUE self, VALUE val);
|
|||
VALUE rb_ne(VALUE self, VALUE val);
|
||||
VALUE rb_in_range(VALUE self, VALUE min, VALUE max);
|
||||
VALUE rb_abs_diff(VALUE self, VALUE val);
|
||||
VALUE rb_normalize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_add_weighted(VALUE klass, VALUE src1, VALUE alpha, VALUE src2, VALUE beta, VALUE gamma);
|
||||
/* Statistics */
|
||||
VALUE rb_count_non_zero(VALUE self);
|
||||
|
|
|
@ -293,6 +293,12 @@ define_ruby_module()
|
|||
rb_define_const(rb_module, "CV_SVD_U_T", INT2FIX(CV_SVD_U_T));
|
||||
rb_define_const(rb_module, "CV_SVD_V_T", INT2FIX(CV_SVD_V_T));
|
||||
|
||||
/* Norm types */
|
||||
rb_define_const(rb_module, "CV_NORM_INF", INT2FIX(cv::NORM_INF));
|
||||
rb_define_const(rb_module, "CV_NORM_L1", INT2FIX(cv::NORM_L1));
|
||||
rb_define_const(rb_module, "CV_NORM_L2", INT2FIX(cv::NORM_L2));
|
||||
rb_define_const(rb_module, "CV_NORM_MINMAX", INT2FIX(cv::NORM_MINMAX));
|
||||
|
||||
/* Histogram representation format */
|
||||
rb_define_const(rb_module, "CV_HIST_ARRAY", INT2FIX(CV_HIST_ARRAY));
|
||||
rb_define_const(rb_module, "CV_HIST_SPARSE", INT2FIX(CV_HIST_SPARSE));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue