diff --git a/ext/opencv/cvmat.cpp b/ext/opencv/cvmat.cpp
index 9735b9a..b4dbd94 100644
--- a/ext/opencv/cvmat.cpp
+++ b/ext/opencv/cvmat.cpp
@@ -309,7 +309,7 @@ void define_ruby_class()
rb_define_method(rb_klass, "det", RUBY_METHOD_FUNC(rb_det), 0);
rb_define_alias(rb_klass, "determinant", "det");
rb_define_method(rb_klass, "invert", RUBY_METHOD_FUNC(rb_invert), -1);
- rb_define_method(rb_klass, "solve", RUBY_METHOD_FUNC(rb_solve), -1);
+ rb_define_singleton_method(rb_klass, "solve", RUBY_METHOD_FUNC(rb_solve), -1);
rb_define_method(rb_klass, "svd", RUBY_METHOD_FUNC(rb_svd), -1);
rb_define_method(rb_klass, "svbksb", RUBY_METHOD_FUNC(rb_svbksb), -1);
rb_define_method(rb_klass, "eigenvv", RUBY_METHOD_FUNC(rb_eigenvv), -1);
@@ -2801,7 +2801,7 @@ rb_invert(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
- * solve(mat, inversion_method=:lu)
+ * solve(src1, src2, inversion_method=:lu)
*
* Solves linear system or least-squares problem (the latter is possible with SVD method).
*
@@ -2819,13 +2819,13 @@ rb_invert(int argc, VALUE *argv, VALUE self)
VALUE
rb_solve(int argc, VALUE *argv, VALUE self)
{
- VALUE mat, symbol;
- rb_scan_args(argc, argv, "11", &mat, &symbol);
+ VALUE src1, src2, symbol;
+ rb_scan_args(argc, argv, "21", &src1, &src2, &symbol);
VALUE dest = Qnil;
- CvArr* arr_ptr = CVARR_WITH_CHECK(mat);
+ CvArr* src2_ptr = CVARR_WITH_CHECK(src2);
try {
- dest = new_mat_kind_object(cvGetSize(arr_ptr), self);
- cvSolve(CVARR(self), arr_ptr, CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
+ dest = new_mat_kind_object(cvGetSize(src2_ptr), src2);
+ cvSolve(CVARR_WITH_CHECK(src1), src2_ptr, CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
}
catch (cv::Exception& e) {
raise_cverror(e);
diff --git a/test/test_cvmat.rb b/test/test_cvmat.rb
index f6aa9d8..3b103ad 100755
--- a/test/test_cvmat.rb
+++ b/test/test_cvmat.rb
@@ -2353,29 +2353,35 @@ class TestCvMat < OpenCVTestCase
elems2 = [3,
4,
5]
- m0 = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
+ a = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
CvScalar.new(elems1[c])
}
b = create_cvmat(3, 1, :cv32f, 1) { |j, i, c|
CvScalar.new(elems2[c])
}
- m1 = m0.solve(b)
- m2 = m0.solve(b, :lu)
- m3 = m0.solve(b, :svd)
- m4 = m0.solve(b, :svd_sym)
- m5 = m0.solve(b, :svd_symmetric)
+ m1 = CvMat.solve(a, b)
+ m2 = CvMat.solve(a, b, :lu)
+ m3 = CvMat.solve(a, b, :svd)
+ m4 = CvMat.solve(a, b, :svd_sym)
+ m5 = CvMat.solve(a, b, :svd_symmetric)
expected = [2, -2, 1]
- [m1, m2, m3, m4, m5].each { |m|
+ [m1, m2, m3].each { |m|
assert_equal(b.width, m.width)
- assert_equal(m0.height, m.height)
+ assert_equal(a.height, m.height)
assert_each_cvscalar(m, 0.001) { |j, i, c|
CvScalar.new(expected[c])
}
}
assert_raise(TypeError) {
- m0.solve(b, DUMMY_OBJ)
+ CvMat.solve(DUMMY_OBJ, b)
+ }
+ assert_raise(TypeError) {
+ CvMat.solve(a, DUMMY_OBJ)
+ }
+ assert_raise(TypeError) {
+ CvMat.solve(a, b, DUMMY_OBJ)
}
end