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

Merge branch 'master' into documentation

This commit is contained in:
ser1zw 2013-01-18 04:06:33 +09:00
commit c4c055f7a7
9 changed files with 101 additions and 121 deletions

View file

@ -89,7 +89,7 @@ VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE _dims, _sizes, _type, _ranges, _uniform;
int dims, type, uniform;
int uniform;
int* sizes;
float** ranges = NULL;

View file

@ -3711,14 +3711,14 @@ rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self)
*
* Resize image.
* <i>interpolation</i> is interpolation method:
* * :nn
* * CV_INTER_NN
* nearest-neighbor interpolation.
* * :linear
* * CV_INTER_LINEAR
* bilinear interpolation (used by default)
* * :area
* * CV_INTER_AREA
* resampling using pixel area relation. It is preferred method for image decimation that give moire-free results.
* In case of zooming it is similar to NN method.
* * :cubic
* * CV_INTER_CUBIC
* bicubic interpolation.
* Return <i>self</i> resized image that it fits exactly to <i>size</i>. If ROI is set, the method consideres the ROI as supported as usual.
*/
@ -3728,8 +3728,10 @@ rb_resize(int argc, VALUE *argv, VALUE self)
VALUE size, interpolation;
rb_scan_args(argc, argv, "11", &size, &interpolation);
VALUE dest = new_mat_kind_object(VALUE_TO_CVSIZE(size), self);
int method = NIL_P(interpolation) ? CV_INTER_LINEAR : NUM2INT(interpolation);
try {
cvResize(CVARR(self), CVARR(dest), CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR));
cvResize(CVARR(self), CVARR(dest), method);
}
catch (cv::Exception& e) {
raise_cverror(e);
@ -3739,23 +3741,23 @@ rb_resize(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
* warp_affine(<i>map_matrix[,interpolation = :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.
*/
VALUE
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;
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);
CvArr* self_ptr = CVARR(self);
int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvWarpAffine(self_ptr, 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));
flags, VALUE_TO_CVSCALAR(fill_value));
}
catch (cv::Exception& e) {
raise_cverror(e);
@ -3843,24 +3845,23 @@ rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale)
/*
* call-seq:
* warp_perspective(<i>map_matrix[,interpolation=: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.
*/
VALUE
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)
VALUE map_matrix, flags_val, option, fillval;
if (rb_scan_args(argc, argv, "13", &map_matrix, &flags_val, &option, &fillval) < 4)
fillval = INT2FIX(0);
CvArr* self_ptr = CVARR(self);
VALUE dest = Qnil;
int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvWarpPerspective(self_ptr, 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));
flags, VALUE_TO_CVSCALAR(fillval));
}
catch (cv::Exception& e) {
raise_cverror(e);
@ -3870,7 +3871,7 @@ rb_warp_perspective(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
* remap(<i>mapx,mapy[,interpolation=: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.
* Transforms source image using the specified map:
@ -3881,17 +3882,16 @@ rb_warp_perspective(int argc, VALUE *argv, VALUE self)
VALUE
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)
VALUE mapx, mapy, flags_val, option, fillval;
if (rb_scan_args(argc, argv, "23", &mapx, &mapy, &flags_val, &option, &fillval) < 5)
fillval = INT2FIX(0);
CvArr* self_ptr = CVARR(self);
VALUE dest = Qnil;
int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val);
try {
dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvRemap(self_ptr, CVARR(dest), CVARR_WITH_CHECK(mapx), CVARR_WITH_CHECK(mapy),
CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR)
| CVMETHOD("WARP_FLAG", option, CV_WARP_FILL_OUTLIERS),
VALUE_TO_CVSCALAR(fillval));
flags, VALUE_TO_CVSCALAR(fillval));
}
catch (cv::Exception& e) {
raise_cverror(e);
@ -4211,7 +4211,6 @@ rb_filter2d(int argc, VALUE *argv, VALUE self)
CvArr* self_ptr = CVARR(self);
VALUE _dest = Qnil;
try {
int type = cvGetElemType(kernel);
_dest = new_mat_kind_object(cvGetSize(self_ptr), self);
cvFilter2D(self_ptr, CVARR(_dest), kernel, NIL_P(_anchor) ? cvPoint(-1,-1) : VALUE_TO_CVPOINT(_anchor));
}

View file

@ -113,7 +113,6 @@ rb_allocate(VALUE klass)
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE obj, x, y, z;
CvPoint3D32f *self_ptr = CVPOINT3D32F(self);
switch (argc) {
case 0:

View file

@ -377,7 +377,7 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con
int low, high;
IplImage *filteredFourierImage;
int totalIntensity;
double sum, den, totalArea;
double den, totalArea;
CvScalar scalar;
if (!(pFourierImage->nChannels == 1 && pFourierImage->depth == 64) ) {

View file

@ -294,7 +294,8 @@ define_ruby_module()
rb_define_const(rb_module, "CV_INTER_LINEAR", INT2FIX(CV_INTER_LINEAR));
rb_define_const(rb_module, "CV_INTER_AREA", INT2FIX(CV_INTER_AREA));
rb_define_const(rb_module, "CV_INTER_CUBIC", INT2FIX(CV_INTER_CUBIC));
rb_define_const(rb_module, "CV_INTER_LANCZOS4", INT2FIX(CV_INTER_LANCZOS4));
/* Warp affine optional flags */
rb_define_const(rb_module, "CV_WARP_FILL_OUTLIERS", INT2FIX(CV_WARP_FILL_OUTLIERS));
rb_define_const(rb_module, "CV_WARP_INVERSE_MAP", INT2FIX(CV_WARP_INVERSE_MAP));
@ -345,20 +346,6 @@ define_ruby_module()
REGISTER_CVMETHOD(inversion_method, "svd_sym", CV_SVD_SYM);
REGISTER_CVMETHOD(inversion_method, "svd_symmetric", CV_SVD_SYM);
VALUE interpolation_method = rb_hash_new();
/* {:nn, :linear, :area, :cubic}: Interpolation method */
rb_define_const(rb_module, "INTERPOLATION_METHOD", interpolation_method);
REGISTER_CVMETHOD(interpolation_method, "nn", CV_INTER_NN);
REGISTER_CVMETHOD(interpolation_method, "linear", CV_INTER_LINEAR);
REGISTER_CVMETHOD(interpolation_method, "area", CV_INTER_AREA);
REGISTER_CVMETHOD(interpolation_method, "cubic", CV_INTER_CUBIC);
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();
/* {:all, :ransac, :lmeds}: Methods used to computed homography matrix */
rb_define_const(rb_module, "HOMOGRAPHY_CALC_METHOD", homography_calc_method);

View file

@ -202,9 +202,6 @@ __NAMESPACE_END_POINT_SET
int
CVPOINTS_FROM_POINT_SET(VALUE object, CvPoint **pointset)
{
VALUE storage;
CvSeq *seq = 0;
CvPoint2D32f p32;
if (rb_obj_is_kind_of(object, cCvSeq::rb_class())) {
if (CV_IS_SEQ_POINT_SET(CVSEQ(object))) {
*pointset = (CvPoint*)cvCvtSeqToArray(CVSEQ(object),

View file

@ -385,27 +385,31 @@ class TestCvMat_imageprocessing < OpenCVTestCase
def test_resize
mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
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
size = CvSize.new(384, 384)
mat1 = mat0.resize(size)
mat2 = mat0.resize(size, CV_INTER_LINEAR)
mat3 = mat0.resize(size, CV_INTER_NN)
mat4 = mat0.resize(size, CV_INTER_AREA)
mat5 = mat0.resize(size, CV_INTER_CUBIC)
mat6 = mat0.resize(size, CV_INTER_LANCZOS4)
assert_equal('b2203ccca2c17b042a90b79704c0f535', hash_img(mat1))
assert_equal('b2203ccca2c17b042a90b79704c0f535', hash_img(mat2))
assert_equal('ba8f2dee2329aaa6309de4770fc8fa55', hash_img(mat3))
assert_equal('10cf18adaa8548101cc230206624133a', hash_img(mat4))
assert_equal('de5c30fcd9e817aa282ab05388de995b', hash_img(mat5))
[mat1, mat2, mat3, mat4, mat5, mat6].each { |m|
assert_equal(size.width, m.cols)
assert_equal(size.height, m.rows)
assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) {
mat0.resize(DUMMY_OBJ)
}
assert_raise(TypeError) {
mat0.resize(size_128, DUMMY_OBJ)
mat0.resize(size, DUMMY_OBJ)
}
# Uncomment the following lines to show the results
# snap(['original', mat0], ['default(linear)', mat1], ['linear', mat2],
# ['nn', mat3], ['area', mat4], ['cubic', mat5] , ['lanczos4', mat6])
end
def test_warp_affine
@ -420,14 +424,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
map_matrix[5] = CvScalar.new(66.08774)
mat1 = mat0.warp_affine(map_matrix)
mat2 = mat0.warp_affine(map_matrix, :nn)
mat3 = mat0.warp_affine(map_matrix, :linear, :fill_outliers, CvColor::Yellow)
mat4 = mat0.warp_affine(map_matrix, :linear, :inverse_map)
assert_equal('da3d7cdefabbaf84c4080ecd40d00897', hash_img(mat1))
assert_equal('b4abcd12c4e1103c3de87bf9ad854936', hash_img(mat2))
assert_equal('26f6b10e955125c91fd7e63a63cc06a3', hash_img(mat3))
assert_equal('cc4eb5d8eb7cb2c0b76941bc38fb91b1', hash_img(mat4))
mat2 = mat0.warp_affine(map_matrix, CV_INTER_NN | CV_WARP_FILL_OUTLIERS)
mat3 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
mat4 = mat0.warp_affine(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS | CV_WARP_INVERSE_MAP)
[mat1, mat2, mat3, mat4].each { |m|
assert_equal(mat0.cols, m.cols)
assert_equal(mat0.rows, m.rows)
assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) {
mat0.warp_affine(DUMMY_OBJ)
@ -435,9 +441,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) {
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
def test_rotation_matrix2D
@ -483,14 +489,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
map_matrix[8] = CvScalar.new(1.00000)
mat1 = mat0.warp_perspective(map_matrix)
mat2 = mat0.warp_perspective(map_matrix, :nn)
mat3 = mat0.warp_perspective(map_matrix, :linear, :inverse_map)
mat4 = mat0.warp_perspective(map_matrix, :linear, :fill_outliers, CvColor::Yellow)
mat2 = mat0.warp_perspective(map_matrix, CV_INTER_NN)
mat3 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR | CV_WARP_INVERSE_MAP)
mat4 = mat0.warp_perspective(map_matrix, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
assert_equal('bba3a5395f9dd9a400a0083ae74d8986', hash_img(mat1))
assert_equal('a0cc4f329f459410293b75b417fc4f25', hash_img(mat2))
assert_equal('3e34e6ed2404056bb72e86edf02610cb', hash_img(mat3))
assert_equal('71bd12857d2e4ac0c919652c2963b4e1', hash_img(mat4))
[mat1, mat2, mat3, mat4].each { |m|
assert_equal(mat0.cols, m.cols)
assert_equal(mat0.rows, m.rows)
assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) {
mat0.warp_perspective(DUMMY_OBJ)
@ -498,9 +506,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) {
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
def test_remap
@ -522,12 +530,15 @@ class TestCvMat_imageprocessing < OpenCVTestCase
}
mat1 = mat0.remap(matx, maty)
mat2 = mat0.remap(matx, maty, :nn)
mat3 = mat0.remap(matx, maty, :linear, :fill_outliers, CvColor::Yellow)
mat2 = mat0.remap(matx, maty, CV_INTER_NN)
mat3 = mat0.remap(matx, maty, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvColor::Yellow)
assert_equal('586716c0262a3e03a54b9fc6e671e5f7', hash_img(mat1))
assert_equal('5461ecdee23d5e8a9099500d631c9f0f', hash_img(mat2))
assert_equal('1f6b73925056298c566e8e727627d929', hash_img(mat3))
[mat1, mat2, mat3].each { |m|
assert_equal(mat0.cols, m.cols)
assert_equal(mat0.rows, m.rows)
assert_equal(mat0.depth, m.depth)
assert_equal(mat0.channel, m.channel)
}
assert_raise(TypeError) {
mat0.remap(DUMMY_OBJ, maty)
@ -538,9 +549,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_raise(TypeError) {
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
def test_log_polar

View file

@ -27,32 +27,26 @@ class TestIplImage < OpenCVTestCase
end
def test_load
img = IplImage.load(FILENAME_CAT)
assert_equal(IplImage, img.class)
assert_equal(375, img.width)
assert_equal(500, img.height)
assert_equal(:cv8u, img.depth)
assert_equal(3, img.channel)
assert_equal('f2e4dc5d6d3fc285203762ff53d150c7', hash_img(img))
img1 = IplImage.load(FILENAME_CAT)
assert_equal(IplImage, img1.class)
assert_equal(375, img1.width)
assert_equal(500, img1.height)
assert_equal(:cv8u, img1.depth)
assert_equal(3, img1.channel)
img = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
assert_equal(IplImage, img.class)
assert_equal(375, img.width)
assert_equal(500, img.height)
assert_equal(:cv8u, img.depth)
assert_equal(1, img.channel)
# The following test fails only when executed by test runner. (I don't know why...)
# $ ruby test/runner.rb #=> fail
# $ ruby test/test_iplimage.rb #=> pass
assert_equal('b1a0c1c5504961b62e15fa7d57a2e7e0', hash_img(img))
img2 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
assert_equal(IplImage, img2.class)
assert_equal(375, img2.width)
assert_equal(500, img2.height)
assert_equal(:cv8u, img2.depth)
assert_equal(1, img2.channel)
img = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR)
assert_equal(IplImage, img.class)
assert_equal(375, img.width)
assert_equal(500, img.height)
assert_equal(:cv8u, img.depth)
assert_equal(3, img.channel)
assert_equal('f2e4dc5d6d3fc285203762ff53d150c7', hash_img(img))
img3 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR)
assert_equal(IplImage, img3.class)
assert_equal(375, img3.width)
assert_equal(500, img3.height)
assert_equal(:cv8u, img3.depth)
assert_equal(3, img3.channel)
assert_raise(ArgumentError) {
IplImage.load
@ -66,6 +60,9 @@ class TestIplImage < OpenCVTestCase
assert_raise(StandardError) {
IplImage.load('file/does/not/exist')
}
# Uncomment the following lines to show the results
# snap img1, img2, img3
end
def test_decode

View file

@ -164,16 +164,6 @@ class TestOpenCV < OpenCVTestCase
assert_equal(2, INVERSION_METHOD[:svd_sym])
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
assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all])
assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds])