mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
modified CvMat#flip to confirm to the behavior of OpenCV's cvFlip(), and added some tests
This commit is contained in:
parent
cc1c1e23be
commit
2235b89552
2 changed files with 52 additions and 11 deletions
|
@ -1380,14 +1380,16 @@ rb_repeat(VALUE self, VALUE object)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* flip(:x) -> cvmat
|
* flip(:x) -> cvmat
|
||||||
* flip(:y) -> cvmat
|
* flip(:y) -> cvmat
|
||||||
* flip -> -> cvmat
|
* flip(:xy) -> cvmat
|
||||||
|
* flip -> cvmat
|
||||||
*
|
*
|
||||||
* Return new flipped 2D array.
|
* Return new flipped 2D array.
|
||||||
* * flip(:x) - flip around horizontal
|
* * flip(:x) - flip around horizontal
|
||||||
* * flip(:y) - flip around vertical
|
* * flip(:y) - flip around vertical
|
||||||
* * flip - flip around both axises
|
* * flip(:xy) - flip around both axises
|
||||||
|
* * flip - flip around vertical
|
||||||
*/
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_flip(int argc, VALUE *argv, VALUE self)
|
rb_flip(int argc, VALUE *argv, VALUE self)
|
||||||
|
@ -1397,9 +1399,10 @@ rb_flip(int argc, VALUE *argv, VALUE self)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* flip!(:x) -> self
|
* flip!(:x) -> self
|
||||||
* flip!(:y) -> self
|
* flip!(:y) -> self
|
||||||
* flip! -> self
|
* flip!(:xy) -> self
|
||||||
|
* flip! -> self
|
||||||
*
|
*
|
||||||
* Flip 2D array. Return self.
|
* Flip 2D array. Return self.
|
||||||
*
|
*
|
||||||
|
@ -1409,14 +1412,16 @@ VALUE
|
||||||
rb_flip_bang(int argc, VALUE *argv, VALUE self)
|
rb_flip_bang(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE format;
|
VALUE format;
|
||||||
int mode = -1;
|
int mode = 0;
|
||||||
if (rb_scan_args(argc, argv, "01", &format) > 0) {
|
if (rb_scan_args(argc, argv, "01", &format) > 0) {
|
||||||
if (rb_to_id(format) == rb_intern("x"))
|
if (rb_to_id(format) == rb_intern("x"))
|
||||||
mode = 1;
|
mode = 1;
|
||||||
else if (rb_to_id(format) == rb_intern("y"))
|
else if (rb_to_id(format) == rb_intern("y"))
|
||||||
mode = 0;
|
mode = 0;
|
||||||
|
else if (rb_to_id(format) == rb_intern("xy"))
|
||||||
|
mode = -1;
|
||||||
else
|
else
|
||||||
rb_warn("argument may be :x or :y");
|
rb_warn("argument may be :x or :y or :xy");
|
||||||
}
|
}
|
||||||
cvFlip(CVARR(self), NULL, mode);
|
cvFlip(CVARR(self), NULL, mode);
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -604,6 +604,42 @@ class TestCvMat < OpenCVTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_flip
|
||||||
|
m0 = create_cvmat(2, 3)
|
||||||
|
|
||||||
|
m1 = m0.clone
|
||||||
|
m1.flip!(:x)
|
||||||
|
m2 = m0.clone.flip(:x)
|
||||||
|
m3 = m0.clone
|
||||||
|
m3.flip!(:y)
|
||||||
|
m4 = m0.clone.flip(:y)
|
||||||
|
m5 = m0.clone
|
||||||
|
m5.flip!(:xy)
|
||||||
|
m6 = m0.clone.flip(:xy)
|
||||||
|
m7 = m0.clone
|
||||||
|
m7.flip!
|
||||||
|
m8 = m0.clone.flip
|
||||||
|
|
||||||
|
[m1, m2, m3, m4, m5, m6, m7, m8].each { |m|
|
||||||
|
assert_equal(m0.height, m.height)
|
||||||
|
assert_equal(m0.width, m.width)
|
||||||
|
}
|
||||||
|
m0.height.times { |j|
|
||||||
|
m0.width.times { |i|
|
||||||
|
ri = m0.width - i - 1
|
||||||
|
rj = m0.height - j - 1
|
||||||
|
assert_cvscalar_equal(m0[ri, j], m1[i, j])
|
||||||
|
assert_cvscalar_equal(m0[ri, j], m2[i, j])
|
||||||
|
assert_cvscalar_equal(m0[i, rj], m3[i, j])
|
||||||
|
assert_cvscalar_equal(m0[i, rj], m4[i, j])
|
||||||
|
assert_cvscalar_equal(m0[ri, rj], m5[i, j])
|
||||||
|
assert_cvscalar_equal(m0[ri, rj], m6[i, j])
|
||||||
|
assert_cvscalar_equal(m0[i, rj], m7[i, j])
|
||||||
|
assert_cvscalar_equal(m0[i, rj], m8[i, j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# def test_avg_sdv
|
# def test_avg_sdv
|
||||||
# m = CvMat.new(1, 8, CV_32F)
|
# m = CvMat.new(1, 8, CV_32F)
|
||||||
|
|
Loading…
Add table
Reference in a new issue