Module: OpenCV::PointSet

Included in:
CvContour
Defined in:
ext/opencv/pointset.cpp,
ext/opencv/cvcontour.cpp

Instance Method Summary collapse

Instance Method Details

#check_contour_convexityBoolean Also known as: convexity?

Tests whether the input contour is convex or not. The contour must be simple, i.e. without self-intersections.

Returns:

  • (Boolean)

101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/opencv/pointset.cpp', line 101

VALUE
rb_check_contour_convexity(VALUE self)
{
  int convexity = 0;
  try {
    convexity = cvCheckContourConvexity(CVARR(self));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return convexity ? Qtrue : Qfalse;
}

#contour_areaFloat

Calculates area of the whole contour or contour section.

note: Orientation of the contour affects the area sign, thus the method may return negative result.

Returns:

  • (Float)

34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/opencv/pointset.cpp', line 34

VALUE
rb_contour_area(int argc, VALUE *argv, VALUE self)
{
  VALUE slice;
  rb_scan_args(argc, argv, "01", &slice);
  double area = 0;
  try {
    area = cvContourArea(CVARR(self), NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return rb_float_new(area);
}

#convex_hull2([orientation_clockwise = true]) ⇒ Object

Finds convex hull of 2D point set using Sklansky's algorithm.

orientation_clockwise: Desired orientation of convex hull (true: clockwise, false: counter clockwise).


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/opencv/pointset.cpp', line 76

VALUE
rb_convex_hull2(int argc, VALUE *argv, VALUE self)
{
  VALUE clockwise, return_points;
  rb_scan_args(argc, argv, "02", &clockwise, &return_points);
  VALUE storage = cCvMemStorage::new_object();
  CvSeq *hull = NULL;
  int return_pts = TRUE_OR_FALSE(return_points, 1);
  try {
    hull = cvConvexHull2(CVSEQ(self), CVMEMSTORAGE(storage),
			 TRUE_OR_FALSE(clockwise, 1) ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE,
			 return_pts);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvSeq::new_sequence(cCvContour::rb_class(), hull, cCvPoint::rb_class(), storage);
}

#convexity_defects(hull) ⇒ cvseq(include CvConvexityDefect)

Finds convexity defects of contour.

Returns:


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'ext/opencv/pointset.cpp', line 120

VALUE
rb_convexity_defects(VALUE self, VALUE hull)
{
  CvSeq *defects = NULL;
  CvSeq *hull_seq = CVSEQ_WITH_CHECK(hull);
  VALUE storage = cCvMemStorage::new_object();
  CvMemStorage *storage_ptr = CVMEMSTORAGE(storage);
  try {
    defects = cvConvexityDefects(CVSEQ(self), hull_seq, storage_ptr);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvSeq::new_sequence(cCvSeq::rb_class(), defects, cCvConvexityDefect::rb_class(), storage);
}

#fit_ellipse2Object

Return fits ellipse to set of 2D points.


55
56
57
58
59
60
61
62
63
64
65
66
# File 'ext/opencv/pointset.cpp', line 55

VALUE
rb_fit_ellipse2(VALUE self)
{
  CvBox2D box;
  try {
    box = cvFitEllipse2(CVARR(self));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvBox2D::new_object(box);
}

#min_area_rect2Object

Finds circumscribed rectangle of minimal area for given 2D point set.


142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'ext/opencv/pointset.cpp', line 142

VALUE
rb_min_area_rect2(VALUE self)
{
  VALUE storage = cCvMemStorage::new_object();
  CvBox2D rect;
  try {
    rect = cvMinAreaRect2(CVARR(self), CVMEMSTORAGE(storage));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvBox2D::new_object(rect);
}

#min_enclosing_circleObject

Finds circumscribed circle of minimal area for given 2D point set.


162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'ext/opencv/pointset.cpp', line 162

VALUE
rb_min_enclosing_circle(VALUE self)
{
  VALUE circle = cCvCircle32f::rb_allocate(cCvCircle32f::rb_class());
  int success = 0;
  try {
    success = cvMinEnclosingCircle(CVARR(self), &CVCIRCLE32F(circle)->center,
				   &CVCIRCLE32F(circle)->radius);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return success ? circle : Qnil;
}