1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

fixed CvMat#solve, and added some tests

This commit is contained in:
ser1zw 2011-01-09 02:09:40 +09:00
parent 832d238923
commit 87d19c362d
2 changed files with 71 additions and 1 deletions

View file

@ -2292,7 +2292,7 @@ rb_solve(int argc, VALUE *argv, VALUE self)
rb_scan_args(argc, argv, "11", &mat, &symbol);
if (!rb_obj_is_kind_of(mat, rb_klass))
rb_raise(rb_eTypeError, "argument 1 (right-hand part of the linear system) should be %s.)", rb_class2name(rb_klass));
VALUE dest = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
VALUE dest = new_object(CVMAT(self)->rows, CVMAT(mat)->cols, cvGetElemType(CVARR(self)));
cvSolve(CVARR(self), CVARR(mat), CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
return dest;
}

View file

@ -1661,6 +1661,76 @@ class TestCvMat < OpenCVTestCase
}
assert_in_delta(CvScalar.new(30, 60, 90, 120), m0.trace, 0.001)
end
def test_transpose
m0 = create_cvmat(5, 5, :cv32f, 4) { |j, i, c|
CvScalar.new(c * 0.5, c * 1.0, c * 1.5, c * 2.0)
}
m1 = m0.clone
m2 = m1.transpose
m1.transpose!
[m1, m2].each { |m|
assert_equal(m0.width, m.width)
assert_equal(m0.height, m.height)
assert_each_cvscalar(m, 0.001) { |j, i, c|
m0[i, j]
}
}
end
def test_det
elems = [2.5, 4.5, 2.0,
3.0, 2.5, -0.5,
1.0, 0.5, 1.5]
m0 = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
CvScalar.new(elems[c])
}
assert_in_delta(-14.5, m0.det, 0.001)
end
def test_invert
elems = [1, 2, 3,
2, 6, 9,
1, 4, 7]
m0 = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
CvScalar.new(elems[c])
}
m1 = m0.invert
m2 = m0.invert(:lu)
m3 = m0.invert(:svd)
m4 = m0.invert(:svd_sym)
m5 = m0.invert(:svd_symmetric)
expected = [3, -1, 0, -2.5, 2, -1.5, 1, -1, 1]
[m1, m2, m3, m4, m5].each { |m|
assert_equal(m0.width, m.width)
assert_equal(m0.height, m.height)
assert_each_cvscalar(m, 0.001) { |j, i, c|
CvScalar.new(expected[c])
}
}
end
def test_solve
elems1 = [3, 4, 5,
8, 9, 6,
3, 5, 9]
elems2 = [3,
4,
5]
m0 = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
CvScalar.new(elems1[c])
}
m1 = create_cvmat(3, 1, :cv32f, 1) { |j, i, c|
CvScalar.new(elems2[c])
}
m2 = m0.solve(m1)
expected = [2, -2, 1]
assert_each_cvscalar(m2, 0.001) { |j, i, c|
CvScalar.new(expected[c])
}
end
end