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 (6)
This commit is contained in:
parent
1dc04e0e3d
commit
0d56ef2762
4 changed files with 287 additions and 59 deletions
|
@ -58,9 +58,9 @@ __NAMESPACE_BEGIN_CVMAT
|
|||
#define DO_IS_CLOSED(op) ({VALUE _is_closed = rb_hash_aref(op, ID2SYM(rb_intern("is_closed"))); NIL_P(_is_closed) ? 0 : _is_closed == Qfalse ? 0 : 1;})
|
||||
|
||||
#define GOOD_FEATURES_TO_TRACK_OPTION(op) NIL_P(op) ? rb_const_get(rb_class(), rb_intern("GOOD_FEATURES_TO_TRACK_OPTION")) : rb_funcall(rb_const_get(rb_class(), rb_intern("GOOD_FEATURES_TO_TRACK_OPTION")), rb_intern("merge"), 1, op)
|
||||
#define GF_MAX(op) FIX2INT(rb_hash_aref(op, ID2SYM(rb_intern("max"))))
|
||||
#define GF_MAX(op) NUM2INT(rb_hash_aref(op, ID2SYM(rb_intern("max"))))
|
||||
#define GF_MASK(op) MASK(rb_hash_aref(op, ID2SYM(rb_intern("mask"))))
|
||||
#define GF_BLOCK_SIZE(op) FIX2INT(rb_hash_aref(op, ID2SYM(rb_intern("block_size"))))
|
||||
#define GF_BLOCK_SIZE(op) NUM2INT(rb_hash_aref(op, ID2SYM(rb_intern("block_size"))))
|
||||
#define GF_USE_HARRIS(op) TRUE_OR_FALSE(rb_hash_aref(op, ID2SYM(rb_intern("use_harris"))), 0)
|
||||
#define GF_K(op) NUM2DBL(rb_hash_aref(op, ID2SYM(rb_intern("k"))))
|
||||
|
||||
|
@ -2884,6 +2884,7 @@ rb_fill_poly_bang(int argc, VALUE *argv, VALUE self)
|
|||
p = ALLOCA_N(CvPoint*, num_polygons);
|
||||
for (j = 0; j < num_polygons; ++j) {
|
||||
points = rb_ary_entry(polygons, j);
|
||||
Check_Type(points, T_ARRAY);
|
||||
num_points[j] = RARRAY_LEN(points);
|
||||
p[j] = ALLOCA_N(CvPoint, num_points[j]);
|
||||
for (i = 0; i < num_points[j]; ++i) {
|
||||
|
@ -3100,7 +3101,7 @@ rb_sobel(int argc, VALUE *argv, VALUE self)
|
|||
dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_32F, 1);
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eRuntimeError, "source depth should be CV_8U or CV_32F.");
|
||||
rb_raise(rb_eArgError, "source depth should be CV_8U or CV_32F.");
|
||||
break;
|
||||
}
|
||||
cvSobel(self_ptr, CVARR(dest), NUM2INT(xorder), NUM2INT(yorder), NUM2INT(aperture_size));
|
||||
|
@ -3185,7 +3186,6 @@ rb_corner_eigenvv(int argc, VALUE *argv, VALUE self)
|
|||
VALUE block_size, aperture_size, dest;
|
||||
if (rb_scan_args(argc, argv, "11", &block_size, &aperture_size) < 2)
|
||||
aperture_size = INT2FIX(3);
|
||||
Check_Type(block_size, T_FIXNUM);
|
||||
CvSize size = cvGetSize(CVARR(self));
|
||||
dest = new_object(cvSize(size.width * 6, size.height), CV_MAKETYPE(CV_32F, 1));
|
||||
cvCornerEigenValsAndVecs(CVARR(self), CVARR(dest), NUM2INT(block_size), NUM2INT(aperture_size));
|
||||
|
@ -3205,7 +3205,7 @@ rb_corner_min_eigen_val(int argc, VALUE *argv, VALUE self)
|
|||
if (rb_scan_args(argc, argv, "11", &block_size, &aperture_size) < 2)
|
||||
aperture_size = INT2FIX(3);
|
||||
dest = new_object(cvGetSize(CVARR(self)), CV_MAKETYPE(CV_32F, 1));
|
||||
cvCornerMinEigenVal(CVARR(self), CVARR(dest), FIX2INT(block_size), FIX2INT(aperture_size));
|
||||
cvCornerMinEigenVal(CVARR(self), CVARR(dest), NUM2INT(block_size), NUM2INT(aperture_size));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -3222,7 +3222,7 @@ rb_corner_harris(int argc, VALUE *argv, VALUE self)
|
|||
VALUE block_size, aperture_size, k, dest;
|
||||
rb_scan_args(argc, argv, "12", &block_size, &aperture_size, &k);
|
||||
dest = new_object(cvGetSize(CVARR(self)), CV_MAKETYPE(CV_32F, 1));
|
||||
cvCornerHarris(CVARR(self), CVARR(dest), FIX2INT(block_size), IF_INT(aperture_size, 3), IF_DBL(k, 0.04));
|
||||
cvCornerHarris(CVARR(self), CVARR(dest), NUM2INT(block_size), IF_INT(aperture_size, 3), IF_DBL(k, 0.04));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -3284,18 +3284,16 @@ rb_good_features_to_track(int argc, VALUE *argv, VALUE self)
|
|||
eigen = rb_cvCreateMat(size.height, size.width, CV_MAKETYPE(CV_32F, 1));
|
||||
tmp = rb_cvCreateMat(size.height, size.width, CV_MAKETYPE(CV_32F, 1));
|
||||
int np = GF_MAX(good_features_to_track_option);
|
||||
if(!(np > 0))
|
||||
if(np <= 0)
|
||||
rb_raise(rb_eArgError, "option :max should be positive value.");
|
||||
CvPoint2D32f *p32 = (CvPoint2D32f*)rb_cvAlloc(sizeof(CvPoint2D32f) * np);
|
||||
if(!p32)
|
||||
rb_raise(rb_eNoMemError, "failed to allocate memory.");
|
||||
cvGoodFeaturesToTrack(src, &eigen, &tmp, p32, &np, NUM2DBL(quality_level), NUM2DBL(min_distance),
|
||||
GF_MASK(good_features_to_track_option),
|
||||
GF_BLOCK_SIZE(good_features_to_track_option),
|
||||
GF_USE_HARRIS(good_features_to_track_option),
|
||||
GF_K(good_features_to_track_option));
|
||||
VALUE corners = rb_ary_new2(np);
|
||||
for (i = 0; i < np; i++)
|
||||
for (i = 0; i < np; ++i)
|
||||
rb_ary_store(corners, i, cCvPoint2D32f::new_object(p32[i]));
|
||||
cvFree(&p32);
|
||||
cvReleaseMat(&eigen);
|
||||
|
@ -3362,8 +3360,8 @@ rb_rect_sub_pix(int argc, VALUE *argv, VALUE self)
|
|||
_size = cvGetSize(CVARR(self));
|
||||
else
|
||||
_size = VALUE_TO_CVSIZE(size);
|
||||
|
||||
VALUE dest = new_object(_size, cvGetElemType(CVARR(self)));
|
||||
|
||||
VALUE dest = new_mat_kind_object(_size, self);
|
||||
cvGetRectSubPix(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT2D32F(center));
|
||||
return dest;
|
||||
}
|
||||
|
@ -3385,11 +3383,8 @@ rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self)
|
|||
else
|
||||
_size = VALUE_TO_CVSIZE(size);
|
||||
|
||||
if (!rb_obj_is_kind_of(map_matrix, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1 (map matrix) should be %s (2x3).", rb_class2name(cCvMat::rb_class()));
|
||||
|
||||
VALUE dest = new_object(_size, cvGetElemType(CVARR(self)));
|
||||
cvGetQuadrangleSubPix(CVARR(self), CVARR(dest), CVMAT(map_matrix));
|
||||
VALUE dest = new_mat_kind_object(_size, self);
|
||||
cvGetQuadrangleSubPix(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(map_matrix));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
@ -3432,10 +3427,8 @@ rb_warp_affine(int argc, VALUE *argv, VALUE self)
|
|||
VALUE map_matrix, interpolation, option, fill_value;
|
||||
if (rb_scan_args(argc, argv, "13", &map_matrix, &interpolation, &option, &fill_value) < 4)
|
||||
fill_value = INT2FIX(0);
|
||||
if (!rb_obj_is_kind_of(map_matrix, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1 (map matrix) should be %s (2x3).", rb_class2name(cCvMat::rb_class()));
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvWarpAffine(CVARR(self), CVARR(dest), CVMAT(map_matrix),
|
||||
cvWarpAffine(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(map_matrix),
|
||||
CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR) | CVMETHOD("WARP_FLAG", option, CV_WARP_FILL_OUTLIERS), VALUE_TO_CVSCALAR(fill_value));
|
||||
return dest;
|
||||
}
|
||||
|
@ -3515,10 +3508,8 @@ rb_warp_perspective(int argc, VALUE *argv, VALUE self)
|
|||
VALUE map_matrix, interpolation, option, fillval;
|
||||
if (rb_scan_args(argc, argv, "13", &map_matrix, &interpolation, &option, &fillval) < 4)
|
||||
fillval = INT2FIX(0);
|
||||
if (!rb_obj_is_kind_of(map_matrix, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1 (map matrix) should be %s (3x3).", rb_class2name(cCvMat::rb_class()));
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvWarpPerspective(CVARR(self), CVARR(dest), CVMAT(map_matrix),
|
||||
cvWarpPerspective(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(map_matrix),
|
||||
CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR)
|
||||
| CVMETHOD("WARP_FLAG",option, CV_WARP_FILL_OUTLIERS), VALUE_TO_CVSCALAR(fillval));
|
||||
return dest;
|
||||
|
@ -3540,12 +3531,8 @@ rb_remap(int argc, VALUE *argv, VALUE self)
|
|||
VALUE mapx, mapy, interpolation, option, fillval;
|
||||
if (rb_scan_args(argc, argv, "23", &mapx, &mapy, &interpolation, &option, &fillval) < 5)
|
||||
fillval = INT2FIX(0);
|
||||
if (!rb_obj_is_kind_of(mapx, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1 (map of x-coordinates) should be %s(CV_32F and single-channel).", rb_class2name(cCvMat::rb_class()));
|
||||
if (!rb_obj_is_kind_of(mapy, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 2 (map of y-coordinates) should be %s(CV_32F and single-channel).", rb_class2name(cCvMat::rb_class()));
|
||||
VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvRemap(CVARR(self), CVARR(dest), CVARR(mapx), CVARR(mapy),
|
||||
cvRemap(CVARR(self), CVARR(dest), CVMAT_WITH_CHECK(mapx), CVMAT_WITH_CHECK(mapy),
|
||||
CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR) | CVMETHOD("WARP_FLAG", option, CV_WARP_FILL_OUTLIERS), VALUE_TO_CVSCALAR(fillval));
|
||||
return dest;
|
||||
}
|
||||
|
@ -3598,7 +3585,8 @@ rb_erode_bang(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
VALUE element, iteration;
|
||||
rb_scan_args(argc, argv, "02", &element, &iteration);
|
||||
cvErode(CVARR(self), CVARR(self), IPLCONVKERNEL(element), IF_INT(iteration, 1));
|
||||
IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element);
|
||||
cvErode(CVARR(self), CVARR(self), kernel, IF_INT(iteration, 1));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -3629,7 +3617,8 @@ rb_dilate_bang(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
VALUE element, iteration;
|
||||
rb_scan_args(argc, argv, "02", &element, &iteration);
|
||||
cvDilate(CVARR(self), CVARR(self), IPLCONVKERNEL(element), IF_INT(iteration, 1));
|
||||
IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element);
|
||||
cvDilate(CVARR(self), CVARR(self), kernel, IF_INT(iteration, 1));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -3639,13 +3628,14 @@ rb_morphology_internal(VALUE element, VALUE iteration, int operation, VALUE self
|
|||
CvArr* self_ptr = CVARR(self);
|
||||
CvSize size = cvGetSize(self_ptr);
|
||||
VALUE dest = new_mat_kind_object(size, self);
|
||||
IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element);
|
||||
if (operation == CV_MOP_GRADIENT) {
|
||||
CvMat* temp = rb_cvCreateMat(size.height, size.width, cvGetElemType(self_ptr));
|
||||
cvMorphologyEx(self_ptr, CVARR(dest), temp, IPLCONVKERNEL(element), CV_MOP_GRADIENT, IF_INT(iteration, 1));
|
||||
cvMorphologyEx(self_ptr, CVARR(dest), temp, kernel, CV_MOP_GRADIENT, IF_INT(iteration, 1));
|
||||
cvReleaseMat(&temp);
|
||||
}
|
||||
else {
|
||||
cvMorphologyEx(self_ptr, CVARR(dest), 0, IPLCONVKERNEL(element), operation, IF_INT(iteration, 1));
|
||||
cvMorphologyEx(self_ptr, CVARR(dest), 0, kernel, operation, IF_INT(iteration, 1));
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
@ -3754,27 +3744,32 @@ rb_smooth(int argc, VALUE *argv, VALUE self)
|
|||
int _smoothtype = CVMETHOD("SMOOTHING_TYPE", smoothtype, -1);
|
||||
|
||||
VALUE (*smooth_func)(int c, VALUE* v, VALUE s);
|
||||
argc--;
|
||||
switch (_smoothtype) {
|
||||
case CV_BLUR_NO_SCALE:
|
||||
smooth_func = rb_smooth_blur_no_scale;
|
||||
argc = (argc > 2) ? 2 : argc;
|
||||
break;
|
||||
case CV_BLUR:
|
||||
smooth_func = rb_smooth_blur;
|
||||
argc = (argc > 2) ? 2 : argc;
|
||||
break;
|
||||
case CV_GAUSSIAN:
|
||||
smooth_func = rb_smooth_gaussian;
|
||||
break;
|
||||
case CV_MEDIAN:
|
||||
smooth_func = rb_smooth_median;
|
||||
argc = (argc > 1) ? 1 : argc;
|
||||
break;
|
||||
case CV_BILATERAL:
|
||||
smooth_func = rb_smooth_bilateral;
|
||||
argc = (argc > 2) ? 2 : argc;
|
||||
break;
|
||||
default:
|
||||
smooth_func = rb_smooth_gaussian;
|
||||
break;
|
||||
}
|
||||
return (*smooth_func)(argc - 1, argv + 1, self);
|
||||
return (*smooth_func)(argc, argv + 1, self);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3903,14 +3898,13 @@ rb_smooth_bilateral(int argc, VALUE *argv, VALUE self)
|
|||
VALUE
|
||||
rb_filter2d(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE kernel, anchor, dest;
|
||||
rb_scan_args(argc, argv, "11", &kernel, &anchor);
|
||||
if (!rb_obj_is_kind_of(kernel, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1 (kernel) should be %s.", rb_class2name(cCvMat::rb_class()));
|
||||
int type = cvGetElemType(CVARR(kernel));
|
||||
dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvFilter2D(CVARR(self), CVARR(dest), CVMAT(kernel), NIL_P(anchor) ? cvPoint(-1,-1) : VALUE_TO_CVPOINT(anchor));
|
||||
return dest;
|
||||
VALUE _kernel, _anchor, _dest;
|
||||
rb_scan_args(argc, argv, "11", &_kernel, &_anchor);
|
||||
CvMat* kernel = CVMAT_WITH_CHECK(_kernel);
|
||||
int type = cvGetElemType(kernel);
|
||||
_dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
|
||||
cvFilter2D(CVARR(self), CVARR(_dest), kernel, NIL_P(_anchor) ? cvPoint(-1,-1) : VALUE_TO_CVPOINT(_anchor));
|
||||
return _dest;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3926,7 +3920,8 @@ rb_copy_make_border_constant(int argc, VALUE *argv, VALUE self)
|
|||
VALUE size, offset, value, dest;
|
||||
rb_scan_args(argc, argv, "21", &size, &offset, &value);
|
||||
dest = new_mat_kind_object(VALUE_TO_CVSIZE(size), self);
|
||||
cvCopyMakeBorder(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT(offset), IPL_BORDER_CONSTANT, NIL_P(value) ? cvScalar(0) : VALUE_TO_CVSCALAR(value));
|
||||
cvCopyMakeBorder(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT(offset), IPL_BORDER_CONSTANT,
|
||||
NIL_P(value) ? cvScalar(0) : VALUE_TO_CVSCALAR(value));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,23 @@ VALUE rb_anchor_y(VALUE self);
|
|||
|
||||
__NAMESPACE_END_IPLCONVKERNEL
|
||||
|
||||
inline IplConvKernel*
|
||||
IPLCONVKERNEL(VALUE object)
|
||||
{
|
||||
IplConvKernel *ptr;
|
||||
Data_Get_Struct(object, IplConvKernel, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline IplConvKernel*
|
||||
IPLCONVKERNEL_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cIplConvKernel::rb_class()))
|
||||
raise_typeerror(object, cIplConvKernel::rb_class());
|
||||
return IPLCONVKERNEL(object);
|
||||
}
|
||||
|
||||
/*
|
||||
inline IplConvKernel*
|
||||
IPLCONVKERNEL(VALUE object)
|
||||
{
|
||||
|
@ -41,11 +58,13 @@ IPLCONVKERNEL(VALUE object)
|
|||
else if (rb_obj_is_kind_of(object, cIplConvKernel::rb_class())) {
|
||||
Data_Get_Struct(object, IplConvKernel, ptr);
|
||||
return ptr;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
rb_warn("invalid kernel. use default kernel (3x3 rectangle).");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ extern "C"{
|
|||
#define IF_STRING(str) NIL_P(str) ? NULL : TYPE(str) == T_STRING ? rb
|
||||
#define IF_BOOL(val, t, f, ifnone) val == Qtrue ? t : val == Qfalse ? f : ifnone
|
||||
|
||||
#define IF_DEPTH(val, ifnone) NIL_P(val) ? ifnone : FIX2INT(val)
|
||||
#define IF_DEPTH(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
|
||||
|
||||
#define RESIST_CVMETHOD(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
|
||||
#define LOOKUP_CVMETHOD(hash, key_as_cstr) (rb_hash_lookup(hash, ID2SYM(rb_intern(key_as_cstr))))
|
||||
|
@ -289,7 +289,7 @@ TRUE_OR_FALSE(VALUE object, int ifnone)
|
|||
case T_NIL:
|
||||
break;
|
||||
default:
|
||||
rb_warn("argument should be true or false.");
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal(:cv32f, CvMat.new(16, 16, :cv32f, 1).sobel(1, 1).depth)
|
||||
|
||||
(DEPTH.keys - [:cv8u, :cv32f]).each { |depth|
|
||||
assert_raise(RuntimeError) {
|
||||
assert_raise(ArgumentError) {
|
||||
CvMat.new(3, 3, depth).sobel(1, 1)
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
# Uncomment the following lines to view the images
|
||||
# snap(['original', mat0], ['sobel(1,0)', mat1], ['sobel(0,1)', mat2],
|
||||
# ['sobel(1,1)', mat3], ['sobel(1,1,3)', mat4], ['sobel(1,1,5)', mat5])
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.sobel(DUMMY_OBJ, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.sobel(1, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.sobel(1, 0, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_laplace
|
||||
|
@ -70,6 +80,10 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
# Uncomment the following line to view the images
|
||||
# snap(['original', mat0], ['laplace', mat1], ['laplace(3)', mat2], ['laplace(5)', mat3])
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.laplace(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_canny
|
||||
|
@ -84,6 +98,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
# Uncomment the following line to view the images
|
||||
# snap(['canny(50,200)', mat1], ['canny(50,200,3)', mat2], ['canny(50,200,5)', mat3])
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.canny(DUMMY_OBJ, 200)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.canny(50, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.canny(50, 200, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_pre_corner_detect
|
||||
|
@ -99,6 +123,10 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
# Uncomment the following lines to show the images
|
||||
# snap(['original', mat0], ['pre_coner_detect', mat1],
|
||||
# ['pre_coner_detect(3)', mat2], ['pre_coner_detect(5)', mat3])
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.pre_corner_detect(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_corner_eigenvv
|
||||
|
@ -106,6 +134,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat1 = mat0.corner_eigenvv(3)
|
||||
mat2 = mat0.corner_eigenvv(3, 3)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_eigenvv(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_eigenvv(3, DUMMY_OBJ)
|
||||
}
|
||||
|
||||
flunk('FIXME: CvMat#corner_eigenvv is not tested yet.')
|
||||
end
|
||||
|
||||
|
@ -114,6 +149,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat1 = mat0.corner_min_eigen_val(3)
|
||||
mat2 = mat0.corner_min_eigen_val(3, 3)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_min_eigen_val(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_min_eigen_val(3, DUMMY_OBJ)
|
||||
}
|
||||
|
||||
flunk('FIXME: CvMat#corner_min_eigen_val is not tested yet.')
|
||||
end
|
||||
|
||||
|
@ -127,11 +169,22 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('6ceb54b54cc98a72de7cb75649fb0a12', hash_img(mat1))
|
||||
assert_equal('6ceb54b54cc98a72de7cb75649fb0a12', hash_img(mat2))
|
||||
assert_equal('6ceb54b54cc98a72de7cb75649fb0a12', hash_img(mat3))
|
||||
assert_equal('4e703deb9a418bbf37e3283f4a7d4d32', hash_img(mat4))
|
||||
# assert_equal('4e703deb9a418bbf37e3283f4a7d4d32', hash_img(mat4))
|
||||
assert_equal('d689b19c786c5693da7282ab9fdb7921', hash_img(mat4))
|
||||
|
||||
# Uncomment the following lines to show the images
|
||||
# snap(['original', mat0], ['corner_harris(3)', mat1], ['corner_harris(3,3)', mat2],
|
||||
# ['corner_harris(3,3,0.04)', mat3], ['corner_harris(3,7,0.01)', mat4])
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_harris(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_harris(3, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.corner_harris(3, 3, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_corner_sub_pix
|
||||
|
@ -200,6 +253,26 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_raise(ArgumentError) {
|
||||
mat0.good_features_to_track(0.2, 5, :max => 0)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(DUMMY_OBJ, 5)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(0.2, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(0.2, 5, :mask => DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(0.2, 5, :block_size => DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(0.2, 5, :k => DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.good_features_to_track(0.2, 5, :max => DUMMY_OBJ)
|
||||
}
|
||||
mat0.good_features_to_track(0.2, 5, :use_harris => DUMMY_OBJ)
|
||||
end
|
||||
|
||||
def test_sample_line
|
||||
|
@ -216,6 +289,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('b3dc0e31260dd42b5341471e23e825d3', hash_img(mat1))
|
||||
assert_equal('b3dc0e31260dd42b5341471e23e825d3', hash_img(mat2))
|
||||
assert_equal('cc27ce8f4068efedcd31c4c782c3825c', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.rect_sub_pix(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.rect_sub_pix(center, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_quadrangle_sub_pix
|
||||
|
@ -236,15 +316,27 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('f170c05fa50c3ac2a762d7b3f5c4ae2f', hash_img(mat1))
|
||||
assert_equal('f170c05fa50c3ac2a762d7b3f5c4ae2f', hash_img(mat2))
|
||||
assert_equal('4d949d5083405381ad9ea09dcd95e5a2', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.quadrangle_sub_pix(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.quadrangle_sub_pix(map_matrix, DUMMY_OBJ)
|
||||
}
|
||||
# assert_raise(CvError) {
|
||||
# mat0.quadrangle_sub_pix(CvMat.new(3, 3))
|
||||
# }
|
||||
end
|
||||
|
||||
def test_resize
|
||||
mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
mat1 = mat0.resize(CvSize.new(512, 512))
|
||||
mat2 = mat0.resize(CvSize.new(512, 512), :linear)
|
||||
mat3 = mat0.resize(CvSize.new(512, 512), :nn)
|
||||
mat4 = mat0.resize(CvSize.new(128, 128), :area)
|
||||
mat5 = mat0.resize(CvSize.new(128, 128), :cubic)
|
||||
size_512 = CvSize.new(512, 512)
|
||||
size_128 = CvSize.new(128, 128)
|
||||
mat1 = mat0.resize(size_512)
|
||||
mat2 = mat0.resize(size_512, :linear)
|
||||
mat3 = mat0.resize(size_512, :nn)
|
||||
mat4 = mat0.resize(size_128, :area)
|
||||
mat5 = mat0.resize(size_128, :cubic)
|
||||
mat6 = mat0.clone
|
||||
|
||||
assert_equal('b2203ccca2c17b042a90b79704c0f535', hash_img(mat1))
|
||||
|
@ -252,6 +344,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('ba8f2dee2329aaa6309de4770fc8fa55', hash_img(mat3))
|
||||
assert_equal('8a28a2748b0cfc87205d65c625187867', hash_img(mat4))
|
||||
assert_equal('de5c30fcd9e817aa282ab05388de995b', hash_img(mat5))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.resize(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.resize(size_128, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_warp_affine
|
||||
|
@ -276,8 +375,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('cc4eb5d8eb7cb2c0b76941bc38fb91b1', hash_img(mat4))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.warp_affine("foobar")
|
||||
mat0.warp_affine(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.warp_affine(map_matrix, DUMMY_OBJ)
|
||||
}
|
||||
# assert_raise(CvError) {
|
||||
# mat0.warp_affine(CvMat.new(3, 3))
|
||||
# }
|
||||
end
|
||||
|
||||
def test_rotation_matrix2D
|
||||
|
@ -291,6 +396,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
expected.each_with_index { |x, i|
|
||||
assert_in_delta(x, mat1[i][0], 0.001)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
CvMat.rotation_matrix2D(DUMMY_OBJ, 60, 2.0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.rotation_matrix2D(CvPoint2D32f.new(10, 20), DUMMY_OBJ, 2.0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
CvMat.rotation_matrix2D(CvPoint2D32f.new(10, 20), 60, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_warp_perspective
|
||||
|
@ -323,8 +438,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('71bd12857d2e4ac0c919652c2963b4e1', hash_img(mat4))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.warp_perspective("foobar")
|
||||
mat0.warp_perspective(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.warp_perspective(map_matrix, DUMMY_OBJ)
|
||||
}
|
||||
# assert_raise(CvError) {
|
||||
# mat0.warp_perspective(CvMat.new(2, 3))
|
||||
# }
|
||||
end
|
||||
|
||||
def test_remap
|
||||
|
@ -354,11 +475,17 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('1f6b73925056298c566e8e727627d929', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.remap('foo', maty)
|
||||
mat0.remap(DUMMY_OBJ, maty)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.remap(matx, 'bar')
|
||||
mat0.remap(matx, DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.remap(matx, maty, DUMMY_OBJ)
|
||||
}
|
||||
# assert_raise(CvError) {
|
||||
# mat0.remap(CvMat.new(3, 3, :cv8u), maty)
|
||||
# }
|
||||
end
|
||||
|
||||
def test_log_polar
|
||||
|
@ -402,6 +529,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('9f02fc4438b1d69fea75a10dfd2b66b0', hash_img(mat5))
|
||||
assert_equal('9f02fc4438b1d69fea75a10dfd2b66b0', hash_img(mat6))
|
||||
assert_equal('075eb0e281328f768eb862735d16979d', hash_img(mat7))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.erode(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.erode(nil, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_dilate
|
||||
|
@ -433,6 +567,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('ebf07f2a0edd2fd0fe26ff5921c6871b', hash_img(mat4))
|
||||
assert_equal('2841937c35c311e947bee49864b9d295', hash_img(mat5))
|
||||
assert_equal('9f02fc4438b1d69fea75a10dfd2b66b0', hash_img(mat6))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.dilate(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.dilate(nil, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_morphology
|
||||
|
@ -465,7 +606,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
# Top hat
|
||||
mat1 = mat0.morphology(CV_MOP_TOPHAT, kernel)
|
||||
mat2 = mat0.morphology(CV_MOP_TOPHAT, kernel)
|
||||
mat2 = mat0.morphology(:tophat, kernel)
|
||||
assert_equal('1760c5b63a52df37069164fe3e901aa4', hash_img(mat1))
|
||||
assert_equal('1760c5b63a52df37069164fe3e901aa4', hash_img(mat2))
|
||||
|
||||
|
@ -474,6 +615,12 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat2 = mat0.morphology(:blackhat, kernel)
|
||||
assert_equal('18b1d51637b912a38133341ee006c6ff', hash_img(mat1))
|
||||
assert_equal('18b1d51637b912a38133341ee006c6ff', hash_img(mat2))
|
||||
|
||||
[:open, :close, :gradient, :tophat, :blackhat].each { |type|
|
||||
assert_raise(TypeError) {
|
||||
mat0.morphology(type, DUMMY_OBJ)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_morphology_open
|
||||
|
@ -582,6 +729,10 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
def test_smooth
|
||||
mat0 = CvMat.load(FILENAME_LENA32x32, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(DUMMY_OBJ)
|
||||
}
|
||||
|
||||
# Blur no scale
|
||||
mat1 = mat0.smooth(CV_BLUR_NO_SCALE)
|
||||
mat2 = mat0.smooth(:blur_no_scale, 3, 3)
|
||||
|
@ -598,7 +749,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('3c9074c87b65117798f48e41a17b2f30', hash_img(mat1))
|
||||
assert_equal('3c9074c87b65117798f48e41a17b2f30', hash_img(mat2))
|
||||
assert_equal('9c549aa406a425a65b036c2f9a2689e0', hash_img(mat3))
|
||||
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BLUR_NO_SCALE, DUMMY_OBJ, 0, 0, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BLUR_NO_SCALE, 3, DUMMY_OBJ, 0, 0)
|
||||
}
|
||||
|
||||
# Blur
|
||||
mat1 = mat0.smooth(CV_BLUR)
|
||||
mat2 = mat0.smooth(:blur, 3, 3)
|
||||
|
@ -622,6 +780,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('f2473b5b964ae8950f6a7fa5cde4c67a', hash_img(mat2))
|
||||
assert_equal('d7bb344fc0f6ec0da4b9754d319e4e4a', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BLUR, DUMMY_OBJ, 0, 0, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BLUR, 3, DUMMY_OBJ, 0, 0)
|
||||
}
|
||||
|
||||
# Gaussian
|
||||
mat1 = mat0.smooth(CV_GAUSSIAN)
|
||||
mat2 = mat0.smooth(:gaussian, 3, 3)
|
||||
|
@ -650,6 +815,19 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('a1ffaa14522719e37d75eec18ff8b309', hash_img(mat4))
|
||||
assert_equal('f7f8b4eff3240ffc8f259ce975936d92', hash_img(mat5))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_GAUSSIAN, DUMMY_OBJ, 0, 0, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_GAUSSIAN, 3, DUMMY_OBJ, 0, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_GAUSSIAN, 3, 0, DUMMY_OBJ, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_GAUSSIAN, 3, 0, 0, DUMMY_OBJ)
|
||||
}
|
||||
|
||||
# Median
|
||||
mat0 = create_cvmat(64, 64, :cv8u, 1) { |j, i, c|
|
||||
if (i + j) % 15 != 0
|
||||
|
@ -663,7 +841,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat0[32 + dy, 32 + dx] = CvScalar.new(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mat1 = mat0.smooth(CV_MEDIAN)
|
||||
mat2 = mat0.smooth(:median, 3)
|
||||
mat3 = mat0.smooth(CV_MEDIAN, 7)
|
||||
|
@ -673,6 +851,10 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('7343a41c542e034db356636c06134961', hash_img(mat2))
|
||||
assert_equal('6ae59e64850377ee5470c854761551ea', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_MEDIAN, DUMMY_OBJ, 0, 0, 0)
|
||||
}
|
||||
|
||||
# Bilateral
|
||||
mat0 = create_cvmat(64, 64, :cv8u, 1) { |j, i, c|
|
||||
if i > 32
|
||||
|
@ -686,6 +868,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat2 = mat0.smooth(:bilateral, 3, 3)
|
||||
mat3 = mat0.smooth(CV_BILATERAL, 7, 7)
|
||||
mat4 = CvMat.new(64, 64, :cv8u, 3).smooth(CV_BILATERAL)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BILATERAL, DUMMY_OBJ, 0, 0, 0)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.smooth(CV_BILATERAL, 3, DUMMY_OBJ, 0, 0)
|
||||
}
|
||||
|
||||
flunk('FIXME: Cases of CvMat#smooth(CV_BILATERAL) are not tested yet.')
|
||||
end
|
||||
|
||||
|
@ -823,6 +1013,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('14a01cc47078e8f8fe4f0fd510d5521b', hash_img(mat1))
|
||||
assert_equal('14a01cc47078e8f8fe4f0fd510d5521b', hash_img(mat2))
|
||||
assert_equal('30e04de43f9240df6aadbaea6467b8fe', hash_img(mat3))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.filter2d(DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.filter2d(kernel, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_copy_make_border_constant
|
||||
|
@ -830,6 +1027,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat1 = mat0.copy_make_border_constant(CvSize.new(64, 48), CvPoint.new(16, 8), 255)
|
||||
|
||||
assert_equal('5e231f8ca051b8f93e4aaa42d193d095', hash_img(mat1))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border_constant(DUMMY_OBJ, CvPoint.new(16, 8))
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border_constant(CvSize.new(64, 48), DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border_constant(CvSize.new(64, 48), CvPoint.new(16, 8), DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_copy_make_border_replicate
|
||||
|
@ -837,6 +1044,13 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
mat1 = mat0.copy_make_border_replicate(CvSize.new(300, 300), CvPoint.new(30, 30))
|
||||
|
||||
assert_equal('ecc7e69d110f9934fa31f8ec85b30275', hash_img(mat1))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border_replicate(DUMMY_OBJ, CvPoint.new(16, 8))
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border_replicate(CvSize.new(64, 48), DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_integral
|
||||
|
|
Loading…
Add table
Reference in a new issue