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:
parent
56e0564ae3
commit
67845bc4cc
4 changed files with 68 additions and 13 deletions
|
@ -14,11 +14,11 @@
|
||||||
* Contour tree. CvContour#create_tree
|
* Contour tree. CvContour#create_tree
|
||||||
*
|
*
|
||||||
* C structure is here.
|
* C structure is here.
|
||||||
* typedef struct CvContourTree{
|
* typedef struct CvContourTree {
|
||||||
* CV_SEQUENCE_FIELDS()
|
* CV_SEQUENCE_FIELDS()
|
||||||
* CvPoint p1;
|
* CvPoint p1;
|
||||||
* CvPoint p2;
|
* CvPoint p2;
|
||||||
* }CvContourTree;
|
* } CvContourTree;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
__NAMESPACE_BEGIN_OPENCV
|
__NAMESPACE_BEGIN_OPENCV
|
||||||
|
@ -49,8 +49,7 @@ define_ruby_class()
|
||||||
rb_klass = rb_define_class_under(opencv, "CvContourTree", cvseq);
|
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, "p1", RUBY_METHOD_FUNC(rb_p1), 0);
|
||||||
rb_define_method(rb_klass, "p2", RUBY_METHOD_FUNC(rb_p2), 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
|
VALUE
|
||||||
|
@ -74,13 +73,17 @@ rb_p2(VALUE self)
|
||||||
* used for reconstruction, so it is possible to build approximated contour.
|
* used for reconstruction, so it is possible to build approximated contour.
|
||||||
*/
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_contour(int argc, VALUE *argv, VALUE self)
|
rb_contour(VALUE self, VALUE criteria)
|
||||||
{
|
{
|
||||||
VALUE criteria, storage;
|
VALUE storage = cCvMemStorage::new_object();
|
||||||
rb_scan_args(argc, argv, "01", &criteria);
|
CvSeq *contour = NULL;
|
||||||
storage = cCvMemStorage::new_object();
|
try {
|
||||||
CvSeq *contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
|
contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
|
||||||
VALUE_TO_CVTERMCRITERIA(criteria));
|
VALUE_TO_CVTERMCRITERIA(criteria));
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
raise_cverror(e);
|
||||||
|
}
|
||||||
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define RUBY_OPENCV_CVCONTOURTREE_H
|
#define RUBY_OPENCV_CVCONTOURTREE_H
|
||||||
#include "opencv.h"
|
#include "opencv.h"
|
||||||
|
|
||||||
#define __NAMESPACE_BEGIN_CVCONTOURTREE namespace cCvContourTree{
|
#define __NAMESPACE_BEGIN_CVCONTOURTREE namespace cCvContourTree {
|
||||||
#define __NAMESPACE_END_CVCONTOURTREE }
|
#define __NAMESPACE_END_CVCONTOURTREE }
|
||||||
|
|
||||||
__NAMESPACE_BEGIN_OPENCV
|
__NAMESPACE_BEGIN_OPENCV
|
||||||
|
@ -23,7 +23,7 @@ void define_ruby_class();
|
||||||
|
|
||||||
VALUE rb_p1(VALUE self);
|
VALUE rb_p1(VALUE self);
|
||||||
VALUE rb_p2(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();
|
VALUE new_object();
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,16 @@ class TestCvContour < OpenCVTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_tree
|
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
|
end
|
||||||
|
|
||||||
def test_in
|
def test_in
|
||||||
|
|
43
test/test_cvcontourtree.rb
Executable file
43
test/test_cvcontourtree.rb
Executable 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue