mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
modify CvMat#normalize to take an optional operation mask.
This commit is contained in:
parent
e0b0a5ed24
commit
42cd2bd9d1
2 changed files with 22 additions and 3 deletions
|
@ -2393,8 +2393,8 @@ rb_abs_diff(VALUE self, VALUE val)
|
|||
VALUE
|
||||
rb_normalize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE alphaVal, betaVal, normTypeVal;
|
||||
rb_scan_args(argc, argv, "03", &alphaVal, &betaVal, &normTypeVal);
|
||||
VALUE alphaVal, betaVal, normTypeVal, maskVal;
|
||||
rb_scan_args(argc, argv, "04", &alphaVal, &betaVal, &normTypeVal, &maskVal);
|
||||
|
||||
const double alpha = alphaVal != Qnil ? NUM2DBL(alphaVal) : 1.0;
|
||||
const double beta = betaVal != Qnil ? NUM2DBL(betaVal) : 0.0;
|
||||
|
@ -2405,11 +2405,18 @@ rb_normalize(int argc, VALUE *argv, VALUE self)
|
|||
const cv::Mat selfMat(CVMAT(self));
|
||||
cv::Mat destMat(CVMAT(dest));
|
||||
|
||||
if (NIL_P(maskVal)) {
|
||||
cv::normalize(selfMat, destMat, alpha, beta, normType);
|
||||
}
|
||||
else {
|
||||
cv::Mat maskMat(MASK(maskVal));
|
||||
cv::normalize(selfMat, destMat, alpha, beta, normType, -1, maskMat);
|
||||
}
|
||||
|
||||
} catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
|
@ -2023,6 +2023,15 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_in_delta(x, mminmax[i][0], 0.001)
|
||||
}
|
||||
|
||||
mask = mat.to_8u.zero
|
||||
mask[0, 0] = CvScalar.new(255, 0, 0)
|
||||
mask[1, 0] = CvScalar.new(255, 0, 0)
|
||||
minf = mat.normalize(1, 0, CV_NORM_INF, mask)
|
||||
expected = [0.0, 0.0, 1.0, 0.0]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_in_delta(x, minf[i][0], 0.001)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat.normalize(DUMMY_OBJ, 0, CV_NORM_INF)
|
||||
}
|
||||
|
@ -2032,6 +2041,9 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_raise(TypeError) {
|
||||
mat.normalize(1, 0, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat.normalize(1, 0, CV_NORM_INF, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_count_non_zero
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue