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

Implemented match_shapes for CvContour

This commit is contained in:
Martin Pilch 2016-06-17 14:57:12 +02:00
parent 0f1ddaf0cd
commit 4f8c9bfa10
2 changed files with 37 additions and 1 deletions

View file

@ -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;
}

View file

@ -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