From 615fd63e0c438af912ed3885acd94aae65c76843 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Tue, 22 Feb 2011 23:11:06 +0900 Subject: [PATCH] modified CvMat#pyr_segmentation to consider ROI, and tested it --- ext/cvmat.cpp | 5 +++-- test/test_cvmat_imageprocessing.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/cvmat.cpp b/ext/cvmat.cpp index 07247b4..5ce8855 100644 --- a/ext/cvmat.cpp +++ b/ext/cvmat.cpp @@ -4260,9 +4260,10 @@ rb_pyr_segmentation(int argc, VALUE *argv, VALUE self) IplImage *src = IPLIMAGE(self); int l = FIX2INT(level); double t1 = NUM2DBL(threshold1), t2 = NUM2DBL(threshold2); - if (!(l >0)) + CvRect roi = cvGetImageROI(src); + if (l <= 0) rb_raise(rb_eArgError, "argument 1 (level) should be > 0."); - if(((src->width | src->height) & ((1 << l) -1 )) != 0) + if(((roi.width | roi.height) & ((1 << l) - 1)) != 0) rb_raise(rb_eArgError, "bad image size on level %d.", FIX2INT(level)); if (t1 < 0) rb_raise(rb_eArgError, "argument 2 (threshold for establishing the link) should be >= 0."); diff --git a/test/test_cvmat_imageprocessing.rb b/test/test_cvmat_imageprocessing.rb index 7bbfdbd..cf1e293 100755 --- a/test/test_cvmat_imageprocessing.rb +++ b/test/test_cvmat_imageprocessing.rb @@ -1238,5 +1238,18 @@ class TestCvMat_imageprocessing < OpenCVTestCase assert_equal(4, contours.total) assert_equal(4, contours.h_next.total) end + + def test_pyr_segmentation + mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH) + mat1, seq1 = mat0.pyr_segmentation(4, 255, 50) + assert_equal('ebd9bad0bbc90b1d4a25289b7d59c958', hash_img(mat1)) + assert_equal(5, seq1.total) + + img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH) + img0.set_roi(CvRect.new(0, 0, 256, 512)) + img2, seq2 = img0.pyr_segmentation(2, 255, 50) + assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img2)) + assert_equal(11, seq2.total) + end end