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

modified CvMat#pyr_segmentation to consider ROI, and tested it

This commit is contained in:
ser1zw 2011-02-22 23:11:06 +09:00
parent 37e95115e0
commit 615fd63e0c
2 changed files with 16 additions and 2 deletions

View file

@ -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.");

View file

@ -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