mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added type check to some CvMat methods (3)
This commit is contained in:
parent
d3ecd00428
commit
76289fa9ea
3 changed files with 247 additions and 62 deletions
|
@ -1815,9 +1815,9 @@ rb_mat_mul(int argc, VALUE *argv, VALUE self)
|
|||
rb_scan_args(argc, argv, "11", &val, &shiftvec);
|
||||
dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
if (NIL_P(shiftvec))
|
||||
cvMatMul(CVARR(self), CVARR(val), CVARR(dest));
|
||||
cvMatMul(CVARR(self), CVMAT_WITH_CHECK(val), CVARR(dest));
|
||||
else
|
||||
cvMatMulAdd(CVARR(self), CVARR(val), CVARR(shiftvec), CVARR(dest));
|
||||
cvMatMulAdd(CVARR(self), CVMAT_WITH_CHECK(val), CVMAT_WITH_CHECK(shiftvec), CVARR(dest));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -1840,7 +1840,8 @@ rb_div(int argc, VALUE *argv, VALUE self)
|
|||
dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
if (rb_obj_is_kind_of(val, rb_klass)) {
|
||||
cvDiv(CVARR(self), CVARR(val), CVARR(dest), NUM2DBL(scale));
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
CvScalar scl = VALUE_TO_CVSCALAR(val);
|
||||
VALUE mat = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvSet(CVARR(mat), scl);
|
||||
|
@ -2057,15 +2058,18 @@ rb_in_range(VALUE self, VALUE min, VALUE max)
|
|||
VALUE dest = new_object(cvGetSize(CVARR(self)), CV_8UC1), tmp;
|
||||
if (rb_obj_is_kind_of(min, rb_klass) && rb_obj_is_kind_of(max, rb_klass)) {
|
||||
cvInRange(CVARR(self), CVARR(min), CVARR(max), CVARR(dest));
|
||||
}else if (rb_obj_is_kind_of(min, rb_klass)) {
|
||||
}
|
||||
else if (rb_obj_is_kind_of(min, rb_klass)) {
|
||||
tmp = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
|
||||
cvSet(CVARR(tmp), VALUE_TO_CVSCALAR(max));
|
||||
cvInRange(CVARR(self), CVARR(min), CVARR(tmp), CVARR(dest));
|
||||
}else if (rb_obj_is_kind_of(max, rb_klass)) {
|
||||
}
|
||||
else if (rb_obj_is_kind_of(max, rb_klass)) {
|
||||
tmp = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
|
||||
cvSet(CVARR(tmp), VALUE_TO_CVSCALAR(min));
|
||||
cvInRange(CVARR(self), CVARR(tmp), CVARR(max), CVARR(dest));
|
||||
}else
|
||||
}
|
||||
else
|
||||
cvInRangeS(CVARR(self), VALUE_TO_CVSCALAR(min), VALUE_TO_CVSCALAR(max), CVARR(dest));
|
||||
return dest;
|
||||
}
|
||||
|
@ -2084,7 +2088,8 @@ rb_abs_diff(VALUE self, VALUE val)
|
|||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
if (rb_obj_is_kind_of(val, rb_klass)) {
|
||||
cvAbsDiff(CVARR(self), CVARR(val), CVARR(dest));
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
cvAbsDiffS(CVARR(self), CVARR(dest), VALUE_TO_CVSCALAR(val));
|
||||
}
|
||||
return dest;
|
||||
|
@ -2206,9 +2211,7 @@ rb_min_max_loc(int argc, VALUE *argv, VALUE self)
|
|||
VALUE
|
||||
rb_dot_product(VALUE self, VALUE mat)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(mat, rb_klass))
|
||||
rb_raise(rb_eTypeError, "argument should be CvMat.");
|
||||
return rb_float_new(cvDotProduct(CVARR(self), CVARR(mat)));
|
||||
return rb_float_new(cvDotProduct(CVARR(self), CVMAT_WITH_CHECK(mat)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2221,10 +2224,8 @@ rb_dot_product(VALUE self, VALUE mat)
|
|||
VALUE
|
||||
rb_cross_product(VALUE self, VALUE mat)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(mat, rb_klass))
|
||||
rb_raise(rb_eTypeError, "argument should be CvMat.");
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvCrossProduct(CVARR(self), CVARR(mat), CVARR(dest));
|
||||
cvCrossProduct(CVARR(self), CVMAT_WITH_CHECK(mat), CVARR(dest));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -2242,9 +2243,9 @@ rb_transform(int argc, VALUE *argv, VALUE self)
|
|||
rb_scan_args(argc, argv, "11", &transmat, &shiftvec);
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
if (NIL_P(shiftvec))
|
||||
cvTransform(CVARR(self), CVARR(dest), CVMAT(transmat), NULL);
|
||||
cvTransform(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(transmat), NULL);
|
||||
else
|
||||
cvTransform(CVARR(self), CVARR(dest), CVMAT(transmat), CVMAT(shiftvec));
|
||||
cvTransform(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(transmat), CVMAT_WITH_CHECK(shiftvec));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -2267,7 +2268,7 @@ VALUE
|
|||
rb_perspective_transform(VALUE self, VALUE mat)
|
||||
{
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvPerspectiveTransform(CVARR(self), CVARR(dest), CVMAT(mat));
|
||||
cvPerspectiveTransform(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(mat));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -2408,7 +2409,8 @@ rb_solve(int argc, VALUE *argv, VALUE self)
|
|||
VALUE mat, symbol;
|
||||
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));
|
||||
rb_raise(rb_eTypeError, "argument 1 (right-hand part of the linear system) should be %s.)",
|
||||
rb_class2name(rb_klass));
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(mat)), self);
|
||||
cvSolve(CVARR(self), CVARR(mat), CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
|
||||
return dest;
|
||||
|
@ -3453,10 +3455,10 @@ rb_find_homograpy(int argc, VALUE *argv, VALUE self)
|
|||
double _ransac_reproj_threshold = NIL_P(ransac_reproj_threshold) ? 0.0 : NUM2DBL(ransac_reproj_threshold);
|
||||
|
||||
if ((_method != 0) && (!NIL_P(get_status)) && IF_BOOL(get_status, 1, 0, 0)) {
|
||||
CvMat *src = CVMAT(src_points);
|
||||
CvMat *src = CVMAT_WITH_CHECK(src_points);
|
||||
int num_points = MAX(src->rows, src->cols);
|
||||
VALUE status = new_object(cvSize(num_points, 1), CV_8UC1);
|
||||
cvFindHomography(src, CVMAT(dst_points), CVMAT(homography),
|
||||
cvFindHomography(src, CVMAT_WITH_CHECK(dst_points), CVMAT(homography),
|
||||
_method, _ransac_reproj_threshold, CVMAT(status));
|
||||
return rb_assoc_new(homography, status);
|
||||
}
|
||||
|
@ -5079,8 +5081,9 @@ rb_optical_flow_bm(int argc, VALUE *argv, VALUE self)
|
|||
VALUE
|
||||
rb_find_fundamental_mat_7point(VALUE klass, VALUE points1, VALUE points2)
|
||||
{
|
||||
VALUE fundamental_matrix = cCvMat::new_object(9, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
int num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix),
|
||||
CvMat* points1_ptr = CVMAT_WITH_CHECK(points1);
|
||||
VALUE fundamental_matrix = cCvMat::new_object(9, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
int num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix),
|
||||
CV_FM_7POINT, 0, 0, NULL);
|
||||
return (num == 0) ? Qnil : fundamental_matrix;
|
||||
}
|
||||
|
@ -5097,8 +5100,9 @@ rb_find_fundamental_mat_7point(VALUE klass, VALUE points1, VALUE points2)
|
|||
VALUE
|
||||
rb_find_fundamental_mat_8point(VALUE klass, VALUE points1, VALUE points2)
|
||||
{
|
||||
VALUE fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
int num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix),
|
||||
CvMat* points1_ptr = CVMAT_WITH_CHECK(points1);
|
||||
VALUE fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
int num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix),
|
||||
CV_FM_8POINT, 0, 0, NULL);
|
||||
return (num == 0) ? Qnil : fundamental_matrix;
|
||||
}
|
||||
|
@ -5128,16 +5132,17 @@ rb_find_fundamental_mat_ransac(int argc, VALUE *argv, VALUE klass)
|
|||
int num = 0;
|
||||
rb_scan_args(argc, argv, "21", &points1, &points2, &option);
|
||||
option = FIND_FUNDAMENTAL_MAT_OPTION(option);
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
if(FFM_WITH_STATUS(option)){
|
||||
CvMat *points1_ptr = CVMAT(points1);
|
||||
CvMat *points1_ptr = CVMAT_WITH_CHECK(points1);
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
if (FFM_WITH_STATUS(option)) {
|
||||
int status_len = (points1_ptr->rows > points1_ptr->cols) ? points1_ptr->rows : points1_ptr->cols;
|
||||
status = cCvMat::new_object(1, status_len, CV_8UC1);
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), CVMAT(status));
|
||||
return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status);
|
||||
}else{
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||
}
|
||||
else {
|
||||
num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), NULL);
|
||||
return num == 0 ? Qnil : fundamental_matrix;
|
||||
}
|
||||
|
@ -5165,16 +5170,17 @@ rb_find_fundamental_mat_lmeds(int argc, VALUE *argv, VALUE klass)
|
|||
int num = 0;
|
||||
rb_scan_args(argc, argv, "21", &points1, &points2, &option);
|
||||
option = FIND_FUNDAMENTAL_MAT_OPTION(option);
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
CvMat *points1_ptr = CVMAT_WITH_CHECK(points1);
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
if(FFM_WITH_STATUS(option)){
|
||||
CvMat *points1_ptr = CVMAT(points1);
|
||||
int status_len = (points1_ptr->rows > points1_ptr->cols) ? points1_ptr->rows : points1_ptr->cols;
|
||||
status = cCvMat::new_object(1, status_len, CV_8UC1);
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_LMEDS,
|
||||
num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), CV_FM_LMEDS,
|
||||
0, FFM_DESIRABLE_LEVEL(option), CVMAT(status));
|
||||
return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status);
|
||||
}else{
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_LMEDS,
|
||||
}
|
||||
else{
|
||||
num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), CV_FM_LMEDS,
|
||||
0, FFM_DESIRABLE_LEVEL(option), NULL);
|
||||
return num == 0 ? Qnil : fundamental_matrix;
|
||||
}
|
||||
|
@ -5212,20 +5218,20 @@ rb_find_fundamental_mat(int argc, VALUE *argv, VALUE klass)
|
|||
rb_scan_args(argc, argv, "31", &points1, &points2, &method, &option);
|
||||
option = FIND_FUNDAMENTAL_MAT_OPTION(option);
|
||||
int fm_method = FIX2INT(method);
|
||||
CvMat *points1_ptr = CVMAT_WITH_CHECK(points1);
|
||||
if (fm_method == CV_FM_7POINT)
|
||||
fundamental_matrix = cCvMat::new_object(9, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
fundamental_matrix = cCvMat::new_object(9, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
else
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(CVMAT(points1)->type));
|
||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(points1_ptr->type));
|
||||
if (FFM_WITH_STATUS(option)) {
|
||||
CvMat *points1_ptr = CVMAT(points1);
|
||||
int status_len = (points1_ptr->rows > points1_ptr->cols) ? points1_ptr->rows : points1_ptr->cols;
|
||||
status = cCvMat::new_object(1, status_len, CV_8UC1);
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), fm_method,
|
||||
num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), fm_method,
|
||||
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), CVMAT(status));
|
||||
return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status);
|
||||
}
|
||||
else {
|
||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), fm_method,
|
||||
num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), fm_method,
|
||||
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), NULL);
|
||||
return num == 0 ? Qnil : fundamental_matrix;
|
||||
}
|
||||
|
@ -5252,17 +5258,17 @@ VALUE
|
|||
rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_image, VALUE fundamental_matrix)
|
||||
{
|
||||
VALUE correspondent_lines;
|
||||
CvMat* points_ptr = CVMAT(points);
|
||||
CvMat* points_ptr = CVMAT_WITH_CHECK(points);
|
||||
int n;
|
||||
if(points_ptr->cols <= 3 && points_ptr->rows >= 7)
|
||||
if (points_ptr->cols <= 3 && points_ptr->rows >= 7)
|
||||
n = points_ptr->rows;
|
||||
else if(points_ptr->rows <= 3 && points_ptr->cols >= 7)
|
||||
else if (points_ptr->rows <= 3 && points_ptr->cols >= 7)
|
||||
n = points_ptr->cols;
|
||||
else
|
||||
rb_raise(rb_eArgError, "input points should 2xN, Nx2 or 3xN, Nx3 matrix(N >= 7).");
|
||||
|
||||
correspondent_lines = cCvMat::new_object(n, 3, CV_MAT_DEPTH(points_ptr->type));
|
||||
cvComputeCorrespondEpilines(points_ptr, FIX2INT(which_image), CVMAT(fundamental_matrix),
|
||||
cvComputeCorrespondEpilines(points_ptr, FIX2INT(which_image), CVMAT_WITH_CHECK(fundamental_matrix),
|
||||
CVMAT(correspondent_lines));
|
||||
return correspondent_lines;
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ inline int
|
|||
CVMETHOD(const char *name, VALUE method, int ifnone = 0)
|
||||
{
|
||||
VALUE value;
|
||||
switch(TYPE(method)){
|
||||
switch (TYPE(method)) {
|
||||
case T_NIL:
|
||||
return ifnone;
|
||||
case T_FIXNUM:
|
||||
|
@ -267,14 +267,16 @@ CVMETHOD(const char *name, VALUE method, int ifnone = 0)
|
|||
method = rb_str_intern(method);
|
||||
case T_SYMBOL:
|
||||
value = rb_hash_aref(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
|
||||
if(NIL_P(value)){
|
||||
if (NIL_P(value)) {
|
||||
rb_warn("invalid opencv method type (see OpenCV::%s)", name);
|
||||
return ifnone;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
return FIX2INT(value);
|
||||
}
|
||||
default:
|
||||
rb_raise(rb_eTypeError, "");
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
||||
rb_class2name(CLASS_OF(method)), rb_class2name(rb_cSymbol));
|
||||
}
|
||||
return ifnone;
|
||||
}
|
||||
|
|
|
@ -1369,6 +1369,13 @@ class TestCvMat < OpenCVTestCase
|
|||
n = c + 1
|
||||
CvScalar.new(n / 0.1, n / 0.2, n / 0.3, n / 0.4)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.div(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m1.div(m2, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_and
|
||||
|
@ -1440,6 +1447,13 @@ class TestCvMat < OpenCVTestCase
|
|||
n = c + 1
|
||||
CvScalar.new(n & 1, n & 2, n & 3, n & 4)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.and(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m1.and(m2, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_or
|
||||
|
@ -1511,8 +1525,14 @@ class TestCvMat < OpenCVTestCase
|
|||
n = c + 1
|
||||
CvScalar.new(n | 1, n | 2, n | 3, n | 4)
|
||||
}
|
||||
end
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.or(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m1.or(m2, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_xor
|
||||
m1 = create_cvmat(6, 4)
|
||||
|
@ -1583,6 +1603,13 @@ class TestCvMat < OpenCVTestCase
|
|||
n = c + 1
|
||||
CvScalar.new(n ^ 1, n ^ 2, n ^ 3, n ^ 4)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.xor(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m1.xor(m2, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_not
|
||||
|
@ -1621,6 +1648,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.eq(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_gt
|
||||
|
@ -1643,6 +1674,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.gt(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_ge
|
||||
|
@ -1665,6 +1700,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.ge(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_lt
|
||||
|
@ -1687,6 +1726,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.lt(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_le
|
||||
|
@ -1709,6 +1752,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.le(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_in_range
|
||||
|
@ -1737,6 +1784,13 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(n, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.in_range(DUMMY_OBJ, m2)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.in_range(m1, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_abs_diff
|
||||
|
@ -1761,6 +1815,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(10.5, 10.5, 10.5, 10.5)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.abs_diff(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_count_non_zero
|
||||
|
@ -1809,6 +1867,16 @@ class TestCvMat < OpenCVTestCase
|
|||
avg, sdv = m0.avg_sdv(mask)
|
||||
assert_in_delta(CvScalar.new(0.75, -0.75, 7.5, -7.5), avg, 0.001)
|
||||
assert_in_delta(CvScalar.new(0.55901, 0.55901, 5.5901, 5.5901), sdv, 0.001)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.avg(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.sdv(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.avg_sdv(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_min_max_loc
|
||||
|
@ -1825,6 +1893,10 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_equal(100.5, max_val)
|
||||
assert_equal(2, max_loc.y)
|
||||
assert_equal(3, max_loc.x)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.min_max_loc(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_dot_product
|
||||
|
@ -1843,6 +1915,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(c * 1.5, c * 2.0, c * 2.5, c * 3.0)
|
||||
}
|
||||
assert_in_delta(85.39999, m1.dot_product(m2), 0.001)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.dot_product(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_cross_product
|
||||
|
@ -1857,6 +1933,10 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_in_delta(CvScalar.new(-0.5), m3[0, 0], 0.001)
|
||||
assert_in_delta(CvScalar.new(1), m3[0, 1], 0.001)
|
||||
assert_in_delta(CvScalar.new(-0.5), m3[0, 2], 0.001)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m1.cross_product(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_transform
|
||||
|
@ -1890,6 +1970,13 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_each_cvscalar(m1, 0.01) { |j, i, c|
|
||||
CvScalar.new(c * 1.5 - 10, 0, c + 5, 0)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.transform(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.transform(transmat, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_perspective_transform
|
||||
|
@ -1922,6 +2009,10 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_equal(:cv32f, m.depth)
|
||||
assert_equal(3, m.channel)
|
||||
assert_in_delta(CvScalar.new(4, 6, 8), m[0], 0.001);
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat.perspective_transform(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_mul_transposed
|
||||
|
@ -1986,6 +2077,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(expected[c])
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.invert(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_solve
|
||||
|
@ -2015,6 +2110,10 @@ class TestCvMat < OpenCVTestCase
|
|||
CvScalar.new(expected[c])
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.solve(b, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_svd
|
||||
|
@ -2048,6 +2147,16 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_in_delta(-0.615, vec3[0, 0][0], 0.01)
|
||||
assert_in_delta(0.788, vec3[0, 1][0], 0.01)
|
||||
assert_in_delta(8.562, val3[0][0], 0.01)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.eigenvv(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.eigenvv(nil, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.eigenvv(nil, nil, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_calc_covar_matrix
|
||||
|
@ -2122,6 +2231,20 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_in_delta(1.0, status[i][0], 0.0001)
|
||||
}
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_homography(DUMMY_OBJ, dst, :ransac, 5, true)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_homography(src, DUMMY_OBJ, :ransac, 5, true)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_homography(src, dst, DUMMY_OBJ, 5, true)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_homography(src, dst, :ransac, DUMMY_OBJ, true)
|
||||
}
|
||||
CvMat.find_homography(src, dst, :ransac, 5, DUMMY_OBJ)
|
||||
end
|
||||
|
||||
def test_find_fundamental_mat_7point
|
||||
|
@ -2169,6 +2292,13 @@ class TestCvMat < OpenCVTestCase
|
|||
expected.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_7point(DUMMY_OBJ, mat2)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_7point(mat1, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_fundamental_mat_8point
|
||||
|
@ -2212,6 +2342,13 @@ class TestCvMat < OpenCVTestCase
|
|||
expected.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_8point(DUMMY_OBJ, mat2)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_8point(mat1, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_fundamental_mat_ransac
|
||||
|
@ -2290,6 +2427,13 @@ class TestCvMat < OpenCVTestCase
|
|||
expected_status.each_with_index { |val, i|
|
||||
assert_in_delta(val, status[i][0], 1.0e-5)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_ransac(DUMMY_OBJ, mat2)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_ransac(mat1, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_fundamental_mat_lmeds
|
||||
|
@ -2336,9 +2480,9 @@ class TestCvMat < OpenCVTestCase
|
|||
CvMat.find_fundamental_mat_lmeds(mat1, mat2)].each { |f_mat|
|
||||
assert_equal(3, f_mat.rows)
|
||||
assert_equal(3, f_mat.cols)
|
||||
expected = [0.000009, -0.000129, -0.008502,
|
||||
0.000183, -0.000004, -0.106088,
|
||||
0.002575, 0.090291, 1.000000]
|
||||
expected = [0.000032, 0.000882, -0.012426,
|
||||
-0.000854, 0.000091, 0.210136,
|
||||
0.001034, -0.2405784, 1.000000]
|
||||
expected.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
|
@ -2352,17 +2496,24 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_equal(1, status.rows)
|
||||
assert_equal(points1.size, status.cols)
|
||||
|
||||
expected_f_mat = [0.000009, -0.000129, -0.008502,
|
||||
0.000183, -0.000004, -0.106088,
|
||||
0.002575, 0.090291, 1.000000]
|
||||
expected_f_mat = [0.000009, 0.000101, -0.009396,
|
||||
-0.000113, -0.000002, 0.049380,
|
||||
0.003335, -0.045132, 1.000000]
|
||||
expected_f_mat.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
expected_status = [0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1]
|
||||
expected_status = [1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1 ]
|
||||
|
||||
expected_status.each_with_index { |val, i|
|
||||
assert_in_delta(val, status[i][0], 1.0e-5)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_lmeds(DUMMY_OBJ, mat2)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat_lmeds(mat1, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_fundamental_mat
|
||||
|
@ -2532,9 +2683,9 @@ class TestCvMat < OpenCVTestCase
|
|||
CvMat.find_fundamental_mat(mat1, mat2, CV_FM_LMEDS)].each { |f_mat|
|
||||
assert_equal(3, f_mat.rows)
|
||||
assert_equal(3, f_mat.cols)
|
||||
expected = [0.000009, -0.000129, -0.008502,
|
||||
0.000183, -0.000004, -0.106088,
|
||||
0.002575, 0.090291, 1.000000]
|
||||
expected = [0.000032, 0.000882, -0.012426,
|
||||
-0.000854, 0.000091, 0.210136,
|
||||
0.001034, -0.2405784, 1.000000]
|
||||
expected.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
|
@ -2548,16 +2699,29 @@ class TestCvMat < OpenCVTestCase
|
|||
assert_equal(1, status.rows)
|
||||
assert_equal(num_points, status.cols)
|
||||
|
||||
expected_f_mat = [0.000009, -0.000129, -0.008502,
|
||||
0.000183, -0.000004, -0.106088,
|
||||
0.002575, 0.090291, 1.000000]
|
||||
expected_f_mat = [0.000009, 0.000101, -0.009396,
|
||||
-0.000113, -0.000002, 0.049380,
|
||||
0.003335, -0.045132, 1.000000]
|
||||
expected_f_mat.each_with_index { |val, i|
|
||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||
}
|
||||
expected_status = [0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1]
|
||||
expected_status = [1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1 ]
|
||||
expected_status.each_with_index { |val, i|
|
||||
assert_in_delta(val, status[i][0], 1.0e-5)
|
||||
}
|
||||
|
||||
[CV_FM_7POINT, CV_FM_8POINT, CV_FM_RANSAC, CV_FM_LMEDS].each { |method|
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat(DUMMY_OBJ, mat2, method, :with_status => true)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat(mat1, DUMMY_OBJ, method, :with_status => true)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.find_fundamental_mat(mat1, mat2, method, DUMMY_OBJ)
|
||||
}
|
||||
}
|
||||
CvMat.find_fundamental_mat(mat1, mat2, DUMMY_OBJ, :with_status => true)
|
||||
end
|
||||
|
||||
def test_compute_correspond_epilines
|
||||
|
@ -2650,6 +2814,19 @@ class TestCvMat < OpenCVTestCase
|
|||
mat2[i] = CvScalar.new(pt)
|
||||
}
|
||||
test_func.call(mat1, mat2, f_mat_arr, num_points)
|
||||
|
||||
|
||||
f_mat = CvMat.new(3, 3, CV_64F, 1)
|
||||
f_mat_arr.each_with_index { |a, i|
|
||||
f_mat[i] = CvScalar.new(a)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.compute_correspond_epilines(DUMMY_OBJ, 1, f_mat)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.compute_correspond_epilines(mat1, 1, DUMMY_OBJ)
|
||||
}
|
||||
CvMat.compute_correspond_epilines(mat1, DUMMY_OBJ, f_mat)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue