mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fix PointSet#convexity_defects
This commit is contained in:
parent
56b33ca03d
commit
bfd4d81549
2 changed files with 17 additions and 9 deletions
|
@ -145,17 +145,14 @@ rb_convexity_defects(VALUE self, VALUE hull)
|
|||
{
|
||||
CvSeq *defects = NULL;
|
||||
CvSeq *hull_seq = CVSEQ_WITH_CHECK(hull);
|
||||
CvMemStorage *stg = hull_seq->storage;
|
||||
VALUE storage = cCvMemStorage::new_object();
|
||||
CvMemStorage *storage_ptr = CVMEMSTORAGE(storage);
|
||||
try {
|
||||
defects = cvConvexityDefects(CVSEQ(self), hull_seq, stg);
|
||||
defects = cvConvexityDefects(CVSEQ(self), hull_seq, storage_ptr);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
// FIXME: This storage is shared with the argument "hull".
|
||||
// This causes a severe problem that when "hull"'s memory is collected by GC, "defects"'s storage is
|
||||
// also collected.
|
||||
VALUE storage = Data_Wrap_Struct(cCvMemStorage::rb_class(), 0, cCvMemStorage::cvmemstorage_free, stg);
|
||||
return cCvSeq::new_sequence(cCvSeq::rb_class(), defects, cCvConvexityDefect::rb_class(), storage);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,13 +71,24 @@ class TestPointSet < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_convexity_defects
|
||||
flunk('FIXME: Currently PointSet#convexity_defects does not work well.')
|
||||
hull = @contour1.convex_hull2(true, false)
|
||||
defects = @contour1.convexity_defects(hull)
|
||||
puts defects.class
|
||||
puts defects[0].start.to_a.join(', ')
|
||||
assert_equal(CvSeq, defects.class)
|
||||
assert_equal(CvConvexityDefect, defects[0].class)
|
||||
assert_equal(32, defects.size)
|
||||
|
||||
d = defects[0]
|
||||
assert_equal(33, d.start.x)
|
||||
assert_equal(57, d.start.y)
|
||||
assert_equal(33, d.depth_point.x)
|
||||
assert_equal(63, d.depth_point.y)
|
||||
assert_equal(32, d.end.x)
|
||||
assert_equal(64, d.end.y)
|
||||
assert_in_delta(0.8485, d.depth, 0.001)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@contour1.convexity_defects(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_min_area_rect2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue