示例#1
0
/*
 * Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
 * @overload point_polygon_test(point, measure_dist)
 *   @param point [CvPoint2D32f] Point tested against the contour
 *   @param measure_dist [Boolean] If true, the method estimates the signed distance from the point to
 *      the nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.
 * @return [Number] When measure_dist = false, the return value is +1, -1 and 0, respectively.
 *   When measure_dist = true, it is a signed distance between the point and the nearest contour edge.
 * @opencv_func cvPointPolygonTest
 */
VALUE
rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
{
  int measure_dist_flag;

  if (measure_dist == Qtrue)
    measure_dist_flag = 1;
  else if (measure_dist == Qfalse)
    measure_dist_flag = 0;
  else
    measure_dist_flag = NUM2INT(measure_dist);

  double dist = Qnil;
  try {
    dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  
  /* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
  if ((!measure_dist_flag) && ((int)dist) != 0)
    dist = (dist > 0) ? 1 : -1;

  return rb_float_new(dist);
}
/* 
 * Create a CvSURFPoint
 *
 * @overload new(pt, laplacian, size, dir, hessian)
 *   @param pt [CvPoint2D32f] Position of the feature within the image
 *   @param laplacian [Integer] -1, 0 or +1. sign of the laplacian at the point.
 *     Can be used to speedup feature comparison 
 *     (normally features with laplacians of different signs can not match)
 *   @param size [Integer] Size of the feature
 *   @param dir [Number] Orientation of the feature: 0..360 degrees
 *   @param hessian [Number] Value of the hessian (can be used to
 *     approximately estimate the feature strengths)
 * @return [CvSURFPoint] self
 */
VALUE
rb_initialize(VALUE self, VALUE pt, VALUE laplacian, VALUE size, VALUE dir, VALUE hessian)
{
  CvSURFPoint *self_ptr = CVSURFPOINT(self);
  self_ptr->pt = VALUE_TO_CVPOINT2D32F(pt);
  self_ptr->laplacian = NUM2INT(laplacian);
  self_ptr->size = NUM2INT(size);
  self_ptr->dir = (float)NUM2DBL(dir);
  self_ptr->hessian = (float)NUM2DBL(hessian);

  return self;
}
示例#3
0
/*
 * Calculates distance between a point and the nearest contour edgex
 * @overload measure_distance(point)
 *   @param point [CvPoint2D32f] Point tested against the contour
 * @return Signed distance between the point and the nearest contour edge
 * @opencv_func cvPointPolygonTest
 */
VALUE
rb_measure_distance(VALUE self, VALUE point)
{
  double distance = 0;
  try {
    distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return rb_float_new(distance);
}
示例#4
0
/*
 * Performs a point-in-contour test.
 * The method determines whether the point is inside a contour, outside,
 * or lies on an edge (or coincides with a vertex).
 * @overload in?(point)
 *   @param point [CvPoint2D32f] Point tested against the contour
 * @return [Boolean] If the point is inside, returns true. If outside, returns false.
 *   If lies on an edge, returns nil.
 * @opencv_func cvPointPolygonTest
 */
VALUE
rb_in_q(VALUE self, VALUE point)
{
  double n = 0;
  try {
    n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
}
示例#5
0
/* 
 * call-seq:
 *   CvBox2D.new(<i>[center][, size][, angle]</i>) -> cvbox2d
 *
 * Create a box
 */
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE center, size, angle;
  rb_scan_args(argc, argv, "03", &center, &size, &angle);
  if (!NIL_P(center))
    CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(center);

  if (!NIL_P(size))
    CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(size);
  
  if (!NIL_P(size))
    CVBOX2D(self)->angle = NUM2DBL(angle);

  return self;
}
示例#6
0
/*
 * call-seq:
 *   center = <i>value</i>
 *
 * Set center to <i>value</i>
 */
VALUE
rb_set_center(VALUE self, VALUE value)
{
  CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
  return self;
}
/*
 * Set position of the feature.
 * 
 * @overload pt=(value)
 *   @param value [CvPoint2D32f] Valuet to set.
 */
VALUE
rb_set_pt(VALUE self, VALUE value)
{
  CVSURFPOINT(self)->pt = VALUE_TO_CVPOINT2D32F(value);
  return self;
}