Skip to content

Commit

Permalink
Implemented match_shapes for CvContour
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpilch committed Jun 17, 2016
1 parent 0f1ddaf commit 4f8c9bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
35 changes: 34 additions & 1 deletion ext/opencv/cvcontour.cpp
Expand Up @@ -292,9 +292,42 @@ rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
return rb_float_new(dist);
}

/*
* call-seq:
* match_shapes(object, method) -> float
*
* Compares two shapes(self and object). <i>object</i> should be CvContour.
*
* A - object1, B - object2:
* * method=CV_CONTOURS_MATCH_I1
* I1(A,B)=sumi=1..7abs(1/mAi - 1/mBi)
* * method=CV_CONTOURS_MATCH_I2
* I2(A,B)=sumi=1..7abs(mAi - mBi)
* * method=CV_CONTOURS_MATCH_I3
* I3(A,B)=sumi=1..7abs(mAi - mBi)/abs(mAi)
*/
VALUE
rb_match_shapes(int argc, VALUE *argv, VALUE self)
{
VALUE object, method, param;
rb_scan_args(argc, argv, "21", &object, &method, &param);
int method_flag = CVMETHOD("COMPARISON_METHOD", method);
if (!rb_obj_is_kind_of(object, cCvContour::rb_class()))
rb_raise(rb_eTypeError, "argument 1 (shape) should be %s",
rb_class2name(cCvContour::rb_class()));
double result = 0;
try {
result = cvMatchShapes(CVARR(self), CVARR(object), method_flag);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_float_new(result);
}

VALUE new_object()
{
VALUE object = rb_allocate(rb_klass);
VALUE object = rb_allocate(rb_klass);
rb_initialize(0, NULL, object);
return object;
}
Expand Down
3 changes: 3 additions & 0 deletions ext/opencv/cvcontour.h
Expand Up @@ -33,6 +33,9 @@ VALUE rb_in_q(VALUE self, VALUE point);
VALUE rb_measure_distance(VALUE self, VALUE point);
VALUE rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist);

/* Matching*/
VALUE rb_match_shapes(int argc, VALUE *argv, VALUE self);

VALUE new_object();
__NAMESPACE_END_CVCONTOUR

Expand Down

0 comments on commit 4f8c9bf

Please sign in to comment.