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

tested and fixed CvContourTree

This commit is contained in:
ser1zw 2011-07-31 00:37:45 +09:00
parent 56e0564ae3
commit 67845bc4cc
4 changed files with 68 additions and 13 deletions

View file

@ -49,8 +49,7 @@ define_ruby_class()
rb_klass = rb_define_class_under(opencv, "CvContourTree", cvseq);
rb_define_method(rb_klass, "p1", RUBY_METHOD_FUNC(rb_p1), 0);
rb_define_method(rb_klass, "p2", RUBY_METHOD_FUNC(rb_p2), 0);
rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 0);
rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 1);
}
VALUE
@ -74,13 +73,17 @@ rb_p2(VALUE self)
* used for reconstruction, so it is possible to build approximated contour.
*/
VALUE
rb_contour(int argc, VALUE *argv, VALUE self)
rb_contour(VALUE self, VALUE criteria)
{
VALUE criteria, storage;
rb_scan_args(argc, argv, "01", &criteria);
storage = cCvMemStorage::new_object();
CvSeq *contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
VALUE storage = cCvMemStorage::new_object();
CvSeq *contour = NULL;
try {
contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
VALUE_TO_CVTERMCRITERIA(criteria));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
}

View file

@ -23,7 +23,7 @@ void define_ruby_class();
VALUE rb_p1(VALUE self);
VALUE rb_p2(VALUE self);
VALUE rb_contour(int argc, VALUE *argv, VALUE self);
VALUE rb_contour(VALUE self, VALUE criteria);
VALUE new_object();

View file

@ -58,7 +58,16 @@ class TestCvContour < OpenCVTestCase
end
def test_create_tree
flunk('FIXME: CvContour#create_tree is not tested yet.')
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
}
contour = mat0.find_contours
tree = contour.create_tree
assert_equal(CvContourTree, tree.class)
assert_equal(34, tree.p1.x)
assert_equal(53, tree.p1.y)
assert_equal(0, tree.p2.x)
assert_equal(0, tree.p2.y)
end
def test_in

43
test/test_cvcontourtree.rb Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env ruby
# -*- mode: ruby; coding: utf-8-unix -*-
require 'test/unit'
require 'opencv'
require File.expand_path(File.dirname(__FILE__)) + '/helper'
include OpenCV
# Tests for OpenCV::CvContourTree
class TestCvContourTree < OpenCVTestCase
def setup
@tree = CvContourTree.new(CvPoint)
end
def test_initialize
tree = CvContourTree.new(CvPoint)
assert_equal(CvContourTree, tree.class)
assert(tree.is_a? CvSeq)
end
def test_p1
assert_equal(CvPoint, @tree.p1.class)
end
def test_p2
assert_equal(CvPoint, @tree.p2.class)
end
def test_contour
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
}
contour = mat0.find_contours
tree = contour.create_tree
contour = tree.contour(CvTermCriteria.new(100, 0.01))
assert_equal(CvContour, contour.class)
assert_raise(CvStsBadArg) {
tree.contour(CvTermCriteria.new(0, 0))
}
end
end