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

use CV_WARP_* constants instead of WARP_FLAG table

This commit is contained in:
ser1zw 2013-01-18 03:37:03 +09:00
parent 6dc59df141
commit c1e67fe186
4 changed files with 49 additions and 61 deletions

View file

@ -3945,24 +3945,23 @@ rb_resize(int argc, VALUE *argv, VALUE self)
/* /*
* call-seq: * call-seq:
* warp_affine(<i>map_matrix[,interpolation = CV_INTER_LINEAR][,option = :fill_outliers][,fillval = 0]</i>) -> cvmat * warp_affine(<i>map_matrix[,flags = CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS][,fillval = 0]</i>) -> cvmat
* *
* Applies affine transformation to the image. * Applies affine transformation to the image.
*/ */
VALUE VALUE
rb_warp_affine(int argc, VALUE *argv, VALUE self) rb_warp_affine(int argc, VALUE *argv, VALUE self)
{ {
VALUE map_matrix, interpolation, option, fill_value; VALUE map_matrix, flags_val, option, fill_value;
VALUE dest = Qnil; VALUE dest = Qnil;
if (rb_scan_args(argc, argv, "13", &map_matrix, &interpolation, &option, &fill_value) < 4) if (rb_scan_args(argc, argv, "13", &map_matrix, &flags_val, &option, &fill_value) < 4)
fill_value = INT2FIX(0); fill_value = INT2FIX(0);
CvArr* self_ptr = CVARR(self); CvArr* self_ptr = CVARR(self);
int method = NIL_P(interpolation) ? CV_INTER_LINEAR : NUM2INT(interpolation); int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try { try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self); dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvWarpAffine(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix), cvWarpAffine(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix),
method | CVMETHOD("WARP_FLAG", option, CV_WARP_FILL_OUTLIERS), flags, VALUE_TO_CVSCALAR(fill_value));
VALUE_TO_CVSCALAR(fill_value));
} }
catch (cv::Exception& e) { catch (cv::Exception& e) {
raise_cverror(e); raise_cverror(e);
@ -4050,24 +4049,23 @@ rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale)
/* /*
* call-seq: * call-seq:
* warp_perspective(<i>map_matrix[,interpolation=CV_INTER_LINEAR][,option =:fill_outliers][,fillval=0])</i>) -> cvmat * warp_perspective(<i>map_matrix[,flags = CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS][,fillval=0])</i>) -> cvmat
* *
* Applies perspective transformation to the image. * Applies perspective transformation to the image.
*/ */
VALUE VALUE
rb_warp_perspective(int argc, VALUE *argv, VALUE self) rb_warp_perspective(int argc, VALUE *argv, VALUE self)
{ {
VALUE map_matrix, interpolation, option, fillval; VALUE map_matrix, flags_val, option, fillval;
if (rb_scan_args(argc, argv, "13", &map_matrix, &interpolation, &option, &fillval) < 4) if (rb_scan_args(argc, argv, "13", &map_matrix, &flags_val, &option, &fillval) < 4)
fillval = INT2FIX(0); fillval = INT2FIX(0);
CvArr* self_ptr = CVARR(self); CvArr* self_ptr = CVARR(self);
VALUE dest = Qnil; VALUE dest = Qnil;
int method = NIL_P(interpolation) ? CV_INTER_LINEAR : NUM2INT(interpolation); int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try { try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self); dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvWarpPerspective(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix), cvWarpPerspective(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix),
method | CVMETHOD("WARP_FLAG",option, CV_WARP_FILL_OUTLIERS), flags, VALUE_TO_CVSCALAR(fillval));
VALUE_TO_CVSCALAR(fillval));
} }
catch (cv::Exception& e) { catch (cv::Exception& e) {
raise_cverror(e); raise_cverror(e);
@ -4077,7 +4075,7 @@ rb_warp_perspective(int argc, VALUE *argv, VALUE self)
/* /*
* call-seq: * call-seq:
* remap(<i>mapx,mapy[,interpolation=CV_INTER_LINEAR][,option=:fill_outliers][,fillval=0]</i>) -> cvmat * remap(<i>mapx,mapy[,flags = CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS][,fillval=0]</i>) -> cvmat
* *
* Applies generic geometrical transformation to the image. * Applies generic geometrical transformation to the image.
* Transforms source image using the specified map: * Transforms source image using the specified map:
@ -4088,17 +4086,16 @@ rb_warp_perspective(int argc, VALUE *argv, VALUE self)
VALUE VALUE
rb_remap(int argc, VALUE *argv, VALUE self) rb_remap(int argc, VALUE *argv, VALUE self)
{ {
VALUE mapx, mapy, interpolation, option, fillval; VALUE mapx, mapy, flags_val, option, fillval;
if (rb_scan_args(argc, argv, "23", &mapx, &mapy, &interpolation, &option, &fillval) < 5) if (rb_scan_args(argc, argv, "23", &mapx, &mapy, &flags_val, &option, &fillval) < 5)
fillval = INT2FIX(0); fillval = INT2FIX(0);
CvArr* self_ptr = CVARR(self); CvArr* self_ptr = CVARR(self);
VALUE dest = Qnil; VALUE dest = Qnil;
int method = NIL_P(interpolation) ? CV_INTER_LINEAR : NUM2INT(interpolation); int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try { try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self); dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvRemap(self_ptr, CVARR(dest), CVARR_WITH_CHECK(mapx), CVARR_WITH_CHECK(mapy), cvRemap(self_ptr, CVARR(dest), CVARR_WITH_CHECK(mapx), CVARR_WITH_CHECK(mapy),
method | CVMETHOD("WARP_FLAG", option, CV_WARP_FILL_OUTLIERS), flags, VALUE_TO_CVSCALAR(fillval));
VALUE_TO_CVSCALAR(fillval));
} }
catch (cv::Exception& e) { catch (cv::Exception& e) {
raise_cverror(e); raise_cverror(e);

View file

@ -346,12 +346,6 @@ define_ruby_module()
REGISTER_CVMETHOD(inversion_method, "svd_sym", CV_SVD_SYM); REGISTER_CVMETHOD(inversion_method, "svd_sym", CV_SVD_SYM);
REGISTER_CVMETHOD(inversion_method, "svd_symmetric", CV_SVD_SYM); REGISTER_CVMETHOD(inversion_method, "svd_symmetric", CV_SVD_SYM);
VALUE warp_flag = rb_hash_new();
/* {:fill_outliers, :inverse_map}: Warp affine optional flags */
rb_define_const(rb_module, "WARP_FLAG", warp_flag);
REGISTER_CVMETHOD(warp_flag, "fill_outliers", CV_WARP_FILL_OUTLIERS);
REGISTER_CVMETHOD(warp_flag, "inverse_map", CV_WARP_INVERSE_MAP);
VALUE homography_calc_method = rb_hash_new(); VALUE homography_calc_method = rb_hash_new();
/* {:all, :ransac, :lmeds}: Methods used to computed homography matrix */ /* {:all, :ransac, :lmeds}: Methods used to computed homography matrix */
rb_define_const(rb_module, "HOMOGRAPHY_CALC_METHOD", homography_calc_method); rb_define_const(rb_module, "HOMOGRAPHY_CALC_METHOD", homography_calc_method);

View file

@ -424,14 +424,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
map_matrix[5] = CvScalar.new(66.08774) map_matrix[5] = CvScalar.new(66.08774)
mat1 = mat0.warp_affine(map_matrix) mat1 = mat0.warp_affine(map_matrix)
mat2 = mat0.warp_affine(map_matrix, CV_INTER_NN) mat2 = mat0.warp_affine(map_matrix, CV_INTER_NN | CV_WARP_FILL_OUTLIERS)
mat3 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR, :fill_outliers, CvColor::Yellow) mat3 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
mat4 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR, :inverse_map) mat4 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS | CV_WARP_INVERSE_MAP)
assert_equal('da3d7cdefabbaf84c4080ecd40d00897', hash_img(mat1)) [mat1, mat2, mat3, mat4].each { |m|
assert_equal('b4abcd12c4e1103c3de87bf9ad854936', hash_img(mat2)) assert_equal(mat0.cols, m.cols)
assert_equal('26f6b10e955125c91fd7e63a63cc06a3', hash_img(mat3)) assert_equal(mat0.rows, m.rows)
assert_equal('cc4eb5d8eb7cb2c0b76941bc38fb91b1', hash_img(mat4)) assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.warp_affine(DUMMY_OBJ) mat0.warp_affine(DUMMY_OBJ)
@ -439,9 +441,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.warp_affine(map_matrix, DUMMY_OBJ) mat0.warp_affine(map_matrix, DUMMY_OBJ)
} }
# assert_raise(CvError) {
# mat0.warp_affine(CvMat.new(3, 3)) # Uncomment the following lines to show the results
# } # snap mat0, mat1, mat2, mat3, mat4
end end
def test_rotation_matrix2D def test_rotation_matrix2D
@ -488,13 +490,15 @@ class TestCvMat_imageprocessing < OpenCVTestCase
mat1 = mat0.warp_perspective(map_matrix) mat1 = mat0.warp_perspective(map_matrix)
mat2 = mat0.warp_perspective(map_matrix, CV_INTER_NN) mat2 = mat0.warp_perspective(map_matrix, CV_INTER_NN)
mat3 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR, :inverse_map) mat3 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR | CV_WARP_INVERSE_MAP)
mat4 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR, :fill_outliers, CvColor::Yellow) mat4 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
assert_equal('bba3a5395f9dd9a400a0083ae74d8986', hash_img(mat1)) [mat1, mat2, mat3, mat4].each { |m|
assert_equal('a0cc4f329f459410293b75b417fc4f25', hash_img(mat2)) assert_equal(mat0.cols, m.cols)
assert_equal('3e34e6ed2404056bb72e86edf02610cb', hash_img(mat3)) assert_equal(mat0.rows, m.rows)
assert_equal('71bd12857d2e4ac0c919652c2963b4e1', hash_img(mat4)) assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.warp_perspective(DUMMY_OBJ) mat0.warp_perspective(DUMMY_OBJ)
@ -502,9 +506,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.warp_perspective(map_matrix, DUMMY_OBJ) mat0.warp_perspective(map_matrix, DUMMY_OBJ)
} }
# assert_raise(CvError) {
# mat0.warp_perspective(CvMat.new(2, 3)) # Uncomment the following line to show the results
# } # snap mat0, mat1, mat2, mat3, mat4
end end
def test_remap def test_remap
@ -527,11 +531,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
mat1 = mat0.remap(matx, maty) mat1 = mat0.remap(matx, maty)
mat2 = mat0.remap(matx, maty, CV_INTER_NN) mat2 = mat0.remap(matx, maty, CV_INTER_NN)
mat3 = mat0.remap(matx, maty, CV_INTER_LINEAR, :fill_outliers, CvColor::Yellow) mat3 = mat0.remap(matx, maty, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
assert_equal('586716c0262a3e03a54b9fc6e671e5f7', hash_img(mat1)) [mat1, mat2, mat3].each { |m|
assert_equal('5461ecdee23d5e8a9099500d631c9f0f', hash_img(mat2)) assert_equal(mat0.cols, m.cols)
assert_equal('1f6b73925056298c566e8e727627d929', hash_img(mat3)) assert_equal(mat0.rows, m.rows)
assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.remap(DUMMY_OBJ, maty) mat0.remap(DUMMY_OBJ, maty)
@ -542,9 +549,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) { assert_raise(TypeError) {
mat0.remap(matx, maty, DUMMY_OBJ) mat0.remap(matx, maty, DUMMY_OBJ)
} }
# assert_raise(CvError) {
# mat0.remap(CvMat.new(3, 3, :cv8u), maty) # Uncomment the following line to show the results
# } # snap mat0, mat1, mat2, mat3
end end
def test_log_polar def test_log_polar

View file

@ -164,16 +164,6 @@ class TestOpenCV < OpenCVTestCase
assert_equal(2, INVERSION_METHOD[:svd_sym]) assert_equal(2, INVERSION_METHOD[:svd_sym])
assert_equal(2, INVERSION_METHOD[:svd_symmetric]) assert_equal(2, INVERSION_METHOD[:svd_symmetric])
# Interpolation methods
assert_equal(0, INTERPOLATION_METHOD[:nn])
assert_equal(1, INTERPOLATION_METHOD[:linear])
assert_equal(2, INTERPOLATION_METHOD[:cubic])
assert_equal(3, INTERPOLATION_METHOD[:area])
# Warp affine optional flags
assert_equal(8, WARP_FLAG[:fill_outliers])
assert_equal(16, WARP_FLAG[:inverse_map])
# Homography calculation methods # Homography calculation methods
assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all]) assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all])
assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds]) assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds])