mirror of
				https://github.com/ruby-opencv/ruby-opencv
				synced 2023-03-27 23:22:12 -04:00 
			
		
		
		
	Merge branch 'master' into documentation
Conflicts: .gitignore ext/opencv/cvmat.cpp
This commit is contained in:
		
						commit
						d679ef49a8
					
				
					 17 changed files with 481 additions and 408 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -22,3 +22,4 @@ videowriter_result.avi
 | 
			
		|||
examples/contours/rotated-boxes-with-detected-bounding-rectangles.jpg
 | 
			
		||||
Gemfile.lock
 | 
			
		||||
.yardoc
 | 
			
		||||
.RUBYLIBDIR.*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,7 +58,7 @@ rb_open(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
      capture = cvCaptureFromCAM(FIX2INT(device));
 | 
			
		||||
      break;
 | 
			
		||||
    case T_SYMBOL: {
 | 
			
		||||
      VALUE cap_index = rb_hash_aref(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
 | 
			
		||||
      VALUE cap_index = rb_hash_lookup(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
 | 
			
		||||
      if (NIL_P(cap_index))
 | 
			
		||||
        rb_raise(rb_eArgError, "undefined interface.");
 | 
			
		||||
      capture = cvCaptureFromCAM(NUM2INT(cap_index));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,10 +17,10 @@ __NAMESPACE_BEGIN_OPENCV
 | 
			
		|||
__NAMESPACE_BEGIN_CVCHAIN
 | 
			
		||||
 | 
			
		||||
#define APPROX_CHAIN_OPTION(op) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
 | 
			
		||||
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_CHAIN_APPROX_SIMPLE)
 | 
			
		||||
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "parameter"))
 | 
			
		||||
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "minimal_perimeter"))
 | 
			
		||||
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
 | 
			
		||||
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_HASH(op, "method"), CV_CHAIN_APPROX_SIMPLE)
 | 
			
		||||
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_HASH(op, "parameter"))
 | 
			
		||||
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_HASH(op, "minimal_perimeter"))
 | 
			
		||||
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
 | 
			
		||||
 | 
			
		||||
VALUE rb_klass;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,9 +19,9 @@ __NAMESPACE_BEGIN_OPENCV
 | 
			
		|||
__NAMESPACE_BEGIN_CVCONTOUR
 | 
			
		||||
 | 
			
		||||
#define APPROX_POLY_OPTION(op) rb_get_option_table(rb_klass, "APPROX_OPTION", op)
 | 
			
		||||
#define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_POLY_APPROX_DP)
 | 
			
		||||
#define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_CVMETHOD(op, "accuracy"))
 | 
			
		||||
#define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
 | 
			
		||||
#define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", LOOKUP_HASH(op, "method"), CV_POLY_APPROX_DP)
 | 
			
		||||
#define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_HASH(op, "accuracy"))
 | 
			
		||||
#define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
 | 
			
		||||
 | 
			
		||||
VALUE rb_allocate(VALUE klass);
 | 
			
		||||
void cvcontour_free(void *ptr);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ VALUE rb_klass;
 | 
			
		|||
int
 | 
			
		||||
rb_font_option_line_type(VALUE font_option)
 | 
			
		||||
{
 | 
			
		||||
  VALUE line_type = LOOKUP_CVMETHOD(font_option, "line_type");
 | 
			
		||||
  VALUE line_type = LOOKUP_HASH(font_option, "line_type");
 | 
			
		||||
  if (FIXNUM_P(line_type)) {
 | 
			
		||||
    return FIX2INT(line_type);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
  VALUE face, font_option;
 | 
			
		||||
  rb_scan_args(argc, argv, "11", &face, &font_option);
 | 
			
		||||
  Check_Type(face, T_SYMBOL);
 | 
			
		||||
  face = rb_hash_aref(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
 | 
			
		||||
  face = rb_hash_lookup(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
 | 
			
		||||
  if (NIL_P(face)) {
 | 
			
		||||
    rb_raise(rb_eArgError, "undefined face.");
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,11 +19,11 @@ __NAMESPACE_BEGIN_OPENCV
 | 
			
		|||
__NAMESPACE_BEGIN_CVFONT
 | 
			
		||||
 | 
			
		||||
#define FONT_OPTION(op) rb_get_option_table(rb_klass, "FONT_OPTION", op)
 | 
			
		||||
#define FO_ITALIC(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "italic"))
 | 
			
		||||
#define FO_HSCALE(op) NUM2DBL(LOOKUP_CVMETHOD(op, "hscale"))
 | 
			
		||||
#define FO_VSCALE(op) NUM2DBL(LOOKUP_CVMETHOD(op, "vscale"))
 | 
			
		||||
#define FO_SHEAR(op) NUM2DBL(LOOKUP_CVMETHOD(op, "shear"))
 | 
			
		||||
#define FO_THICKNESS(op) NUM2INT(LOOKUP_CVMETHOD(op, "thickness"))
 | 
			
		||||
#define FO_ITALIC(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "italic"))
 | 
			
		||||
#define FO_HSCALE(op) NUM2DBL(LOOKUP_HASH(op, "hscale"))
 | 
			
		||||
#define FO_VSCALE(op) NUM2DBL(LOOKUP_HASH(op, "vscale"))
 | 
			
		||||
#define FO_SHEAR(op) NUM2DBL(LOOKUP_HASH(op, "shear"))
 | 
			
		||||
#define FO_THICKNESS(op) NUM2INT(LOOKUP_HASH(op, "thickness"))
 | 
			
		||||
#define FO_LINE_TYPE(op) rb_font_option_line_type(op)
 | 
			
		||||
 | 
			
		||||
VALUE rb_class();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -100,14 +100,14 @@ rb_detect_objects(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
    storage_val = cCvMemStorage::new_object();
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    scale_factor = IF_DBL(LOOKUP_CVMETHOD(options, "scale_factor"), 1.1);
 | 
			
		||||
    flags = IF_INT(LOOKUP_CVMETHOD(options, "flags"), 0);
 | 
			
		||||
    min_neighbors = IF_INT(LOOKUP_CVMETHOD(options, "min_neighbors"), 3);
 | 
			
		||||
    VALUE min_size_val = LOOKUP_CVMETHOD(options, "min_size");
 | 
			
		||||
    scale_factor = IF_DBL(LOOKUP_HASH(options, "scale_factor"), 1.1);
 | 
			
		||||
    flags = IF_INT(LOOKUP_HASH(options, "flags"), 0);
 | 
			
		||||
    min_neighbors = IF_INT(LOOKUP_HASH(options, "min_neighbors"), 3);
 | 
			
		||||
    VALUE min_size_val = LOOKUP_HASH(options, "min_size");
 | 
			
		||||
    min_size = NIL_P(min_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(min_size_val);
 | 
			
		||||
    VALUE max_size_val = LOOKUP_CVMETHOD(options, "max_size");
 | 
			
		||||
    VALUE max_size_val = LOOKUP_HASH(options, "max_size");
 | 
			
		||||
    max_size = NIL_P(max_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(max_size_val);
 | 
			
		||||
    storage_val = CHECK_CVMEMSTORAGE(LOOKUP_CVMETHOD(options, "storage"));
 | 
			
		||||
    storage_val = CHECK_CVMEMSTORAGE(LOOKUP_HASH(options, "storage"));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  VALUE result = Qnil;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,49 +16,49 @@ __NAMESPACE_BEGIN_OPENCV
 | 
			
		|||
__NAMESPACE_BEGIN_CVMAT
 | 
			
		||||
 | 
			
		||||
#define DRAWING_OPTION(opt) rb_get_option_table(rb_klass, "DRAWING_OPTION", opt)
 | 
			
		||||
#define DO_COLOR(opt) VALUE_TO_CVSCALAR(LOOKUP_CVMETHOD(opt, "color"))
 | 
			
		||||
#define DO_THICKNESS(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "thickness"))
 | 
			
		||||
#define DO_COLOR(opt) VALUE_TO_CVSCALAR(LOOKUP_HASH(opt, "color"))
 | 
			
		||||
#define DO_THICKNESS(opt) NUM2INT(LOOKUP_HASH(opt, "thickness"))
 | 
			
		||||
#define DO_LINE_TYPE(opt) rb_drawing_option_line_type(opt)
 | 
			
		||||
#define DO_SHIFT(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "shift"))
 | 
			
		||||
#define DO_IS_CLOSED(opt) TRUE_OR_FALSE(LOOKUP_CVMETHOD(opt, "is_closed"))
 | 
			
		||||
#define DO_SHIFT(opt) NUM2INT(LOOKUP_HASH(opt, "shift"))
 | 
			
		||||
#define DO_IS_CLOSED(opt) TRUE_OR_FALSE(LOOKUP_HASH(opt, "is_closed"))
 | 
			
		||||
 | 
			
		||||
#define GOOD_FEATURES_TO_TRACK_OPTION(opt) rb_get_option_table(rb_klass, "GOOD_FEATURES_TO_TRACK_OPTION", opt)
 | 
			
		||||
#define GF_MAX(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "max"))
 | 
			
		||||
#define GF_MASK(opt) MASK(LOOKUP_CVMETHOD(opt, "mask"))
 | 
			
		||||
#define GF_BLOCK_SIZE(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "block_size"))
 | 
			
		||||
#define GF_USE_HARRIS(opt) TRUE_OR_FALSE(LOOKUP_CVMETHOD(opt, "use_harris"))
 | 
			
		||||
#define GF_K(opt) NUM2DBL(LOOKUP_CVMETHOD(opt, "k"))
 | 
			
		||||
#define GF_MAX(opt) NUM2INT(LOOKUP_HASH(opt, "max"))
 | 
			
		||||
#define GF_MASK(opt) MASK(LOOKUP_HASH(opt, "mask"))
 | 
			
		||||
#define GF_BLOCK_SIZE(opt) NUM2INT(LOOKUP_HASH(opt, "block_size"))
 | 
			
		||||
#define GF_USE_HARRIS(opt) TRUE_OR_FALSE(LOOKUP_HASH(opt, "use_harris"))
 | 
			
		||||
#define GF_K(opt) NUM2DBL(LOOKUP_HASH(opt, "k"))
 | 
			
		||||
 | 
			
		||||
#define FLOOD_FILL_OPTION(opt) rb_get_option_table(rb_klass, "FLOOD_FILL_OPTION", opt)
 | 
			
		||||
#define FF_CONNECTIVITY(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "connectivity"))
 | 
			
		||||
#define FF_FIXED_RANGE(opt) TRUE_OR_FALSE(LOOKUP_CVMETHOD(opt, "fixed_range"))
 | 
			
		||||
#define FF_MASK_ONLY(opt) TRUE_OR_FALSE(LOOKUP_CVMETHOD(opt, "mask_only"))
 | 
			
		||||
#define FF_CONNECTIVITY(opt) NUM2INT(LOOKUP_HASH(opt, "connectivity"))
 | 
			
		||||
#define FF_FIXED_RANGE(opt) TRUE_OR_FALSE(LOOKUP_HASH(opt, "fixed_range"))
 | 
			
		||||
#define FF_MASK_ONLY(opt) TRUE_OR_FALSE(LOOKUP_HASH(opt, "mask_only"))
 | 
			
		||||
 | 
			
		||||
#define FIND_CONTOURS_OPTION(opt) rb_get_option_table(rb_klass, "FIND_CONTOURS_OPTION", opt)
 | 
			
		||||
#define FC_MODE(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "mode"))
 | 
			
		||||
#define FC_METHOD(opt) NUM2INT(LOOKUP_CVMETHOD(opt, "method"))
 | 
			
		||||
#define FC_OFFSET(opt) VALUE_TO_CVPOINT(LOOKUP_CVMETHOD(opt, "offset"))
 | 
			
		||||
#define FC_MODE(opt) NUM2INT(LOOKUP_HASH(opt, "mode"))
 | 
			
		||||
#define FC_METHOD(opt) NUM2INT(LOOKUP_HASH(opt, "method"))
 | 
			
		||||
#define FC_OFFSET(opt) VALUE_TO_CVPOINT(LOOKUP_HASH(opt, "offset"))
 | 
			
		||||
 | 
			
		||||
#define OPTICAL_FLOW_HS_OPTION(opt) rb_get_option_table(rb_klass, "OPTICAL_FLOW_HS_OPTION", opt)
 | 
			
		||||
#define HS_LAMBDA(opt) NUM2DBL(LOOKUP_CVMETHOD(opt, "lambda"))
 | 
			
		||||
#define HS_CRITERIA(opt) VALUE_TO_CVTERMCRITERIA(LOOKUP_CVMETHOD(opt, "criteria"))
 | 
			
		||||
#define HS_LAMBDA(opt) NUM2DBL(LOOKUP_HASH(opt, "lambda"))
 | 
			
		||||
#define HS_CRITERIA(opt) VALUE_TO_CVTERMCRITERIA(LOOKUP_HASH(opt, "criteria"))
 | 
			
		||||
 | 
			
		||||
#define OPTICAL_FLOW_BM_OPTION(opt) rb_get_option_table(rb_klass, "OPTICAL_FLOW_BM_OPTION", opt)
 | 
			
		||||
#define BM_BLOCK_SIZE(opt) VALUE_TO_CVSIZE(LOOKUP_CVMETHOD(opt, "block_size"))
 | 
			
		||||
#define BM_SHIFT_SIZE(opt) VALUE_TO_CVSIZE(LOOKUP_CVMETHOD(opt, "shift_size"))
 | 
			
		||||
#define BM_MAX_RANGE(opt) VALUE_TO_CVSIZE(LOOKUP_CVMETHOD(opt, "max_range"))
 | 
			
		||||
#define BM_BLOCK_SIZE(opt) VALUE_TO_CVSIZE(LOOKUP_HASH(opt, "block_size"))
 | 
			
		||||
#define BM_SHIFT_SIZE(opt) VALUE_TO_CVSIZE(LOOKUP_HASH(opt, "shift_size"))
 | 
			
		||||
#define BM_MAX_RANGE(opt) VALUE_TO_CVSIZE(LOOKUP_HASH(opt, "max_range"))
 | 
			
		||||
 | 
			
		||||
#define FIND_FUNDAMENTAL_MAT_OPTION(opt) rb_get_option_table(rb_klass, "FIND_FUNDAMENTAL_MAT_OPTION", opt)
 | 
			
		||||
#define FFM_WITH_STATUS(opt) TRUE_OR_FALSE(LOOKUP_CVMETHOD(opt, "with_status"))
 | 
			
		||||
#define FFM_MAXIMUM_DISTANCE(opt) NUM2DBL(LOOKUP_CVMETHOD(opt, "maximum_distance"))
 | 
			
		||||
#define FFM_DESIRABLE_LEVEL(opt) NUM2DBL(LOOKUP_CVMETHOD(opt, "desirable_level"))
 | 
			
		||||
#define FFM_WITH_STATUS(opt) TRUE_OR_FALSE(LOOKUP_HASH(opt, "with_status"))
 | 
			
		||||
#define FFM_MAXIMUM_DISTANCE(opt) NUM2DBL(LOOKUP_HASH(opt, "maximum_distance"))
 | 
			
		||||
#define FFM_DESIRABLE_LEVEL(opt) NUM2DBL(LOOKUP_HASH(opt, "desirable_level"))
 | 
			
		||||
 | 
			
		||||
VALUE rb_klass;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
rb_drawing_option_line_type(VALUE drawing_option)
 | 
			
		||||
{
 | 
			
		||||
  VALUE line_type = LOOKUP_CVMETHOD(drawing_option, "line_type");
 | 
			
		||||
  VALUE line_type = LOOKUP_HASH(drawing_option, "line_type");
 | 
			
		||||
  if (FIXNUM_P(line_type)) {
 | 
			
		||||
    return FIX2INT(line_type);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -444,7 +444,7 @@ rb_height(VALUE self)
 | 
			
		|||
VALUE
 | 
			
		||||
rb_depth(VALUE self)
 | 
			
		||||
{
 | 
			
		||||
  return rb_hash_aref(rb_funcall(rb_const_get(rb_module_opencv(), rb_intern("DEPTH")), rb_intern("invert"), 0),
 | 
			
		||||
  return rb_hash_lookup(rb_funcall(rb_const_get(rb_module_opencv(), rb_intern("DEPTH")), rb_intern("invert"), 0),
 | 
			
		||||
			INT2FIX(CV_MAT_DEPTH(CVMAT(self)->type)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -741,44 +741,52 @@ rb_sub_rect(VALUE self, VALUE args)
 | 
			
		|||
  return DEPEND_OBJECT(rb_klass, mat, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_get_range_index(VALUE index, int* start, int *end) {
 | 
			
		||||
  if (rb_obj_is_kind_of(index, rb_cRange)) {
 | 
			
		||||
    *start = NUM2INT(rb_funcall3(index, rb_intern("begin"), 0, NULL));
 | 
			
		||||
    *end = NUM2INT(rb_funcall3(index, rb_intern("end"), 0, NULL));
 | 
			
		||||
    if (rb_funcall3(index, rb_intern("exclude_end?"), 0, NULL) == Qfalse) {
 | 
			
		||||
      (*end)++;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    *start = NUM2INT(index);
 | 
			
		||||
    *end = *start + 1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Returns array of row or row span.
 | 
			
		||||
 * @overload get_rows(index)
 | 
			
		||||
 * @overload get_rows(index, delta_row = 1)
 | 
			
		||||
 *   @param index [Integer] Zero-based index of the selected row
 | 
			
		||||
 *   @param delta_row [Integer] Index step in the row span.
 | 
			
		||||
 *   @return [CvMat] Selected row
 | 
			
		||||
 * @overload get_rows(range)
 | 
			
		||||
 * @overload get_rows(range, delta_row = 1)
 | 
			
		||||
 *   @param range [Range] Zero-based index range of the selected row
 | 
			
		||||
 *   @return [Array<CvMat>]Array of selected row
 | 
			
		||||
 * @opencv_func cvGetRow
 | 
			
		||||
 *   @param delta_row [Integer] Index step in the row span.
 | 
			
		||||
 *   @return [CvMat] Selected rows
 | 
			
		||||
 * @opencv_func cvGetRows
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_get_rows(VALUE self, VALUE args)
 | 
			
		||||
rb_get_rows(int argc, VALUE* argv, VALUE self)
 | 
			
		||||
{
 | 
			
		||||
  int len = RARRAY_LEN(args);
 | 
			
		||||
  if (len < 1)
 | 
			
		||||
    rb_raise(rb_eArgError, "wrong number of argument.(more than 1)");
 | 
			
		||||
  VALUE ary = rb_ary_new2(len);
 | 
			
		||||
  for (int i = 0; i < len; ++i) {
 | 
			
		||||
    VALUE value = rb_ary_entry(args, i);
 | 
			
		||||
  VALUE row_val, delta_val;
 | 
			
		||||
  rb_scan_args(argc, argv, "11", &row_val, &delta_val);
 | 
			
		||||
 | 
			
		||||
    CvMat* row = NULL;
 | 
			
		||||
  int start, end;
 | 
			
		||||
  rb_get_range_index(row_val, &start, &end);
 | 
			
		||||
  int delta = NIL_P(delta_val) ? 1 : NUM2INT(delta_val);
 | 
			
		||||
  CvMat* submat = RB_CVALLOC(CvMat);
 | 
			
		||||
  try {
 | 
			
		||||
      if (FIXNUM_P(value))
 | 
			
		||||
	row = cvGetRow(CVARR(self), RB_CVALLOC(CvMat), FIX2INT(value));
 | 
			
		||||
      else {
 | 
			
		||||
	CvSlice slice = VALUE_TO_CVSLICE(value);
 | 
			
		||||
	row = cvGetRows(CVARR(self), RB_CVALLOC(CvMat), slice.start_index, slice.end_index);
 | 
			
		||||
      }
 | 
			
		||||
    cvGetRows(CVARR(self), submat, start, end, delta);
 | 
			
		||||
  }
 | 
			
		||||
  catch (cv::Exception& e) {
 | 
			
		||||
      if (row != NULL)
 | 
			
		||||
	cvReleaseMat(&row);
 | 
			
		||||
    cvFree(&submat);
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
  }
 | 
			
		||||
    rb_ary_store(ary, i, DEPEND_OBJECT(rb_klass, row, self));
 | 
			
		||||
  }
 | 
			
		||||
  return RARRAY_LEN(ary) > 1 ? ary : rb_ary_entry(ary, 0);
 | 
			
		||||
 | 
			
		||||
  return DEPEND_OBJECT(rb_klass, submat, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -788,36 +796,24 @@ rb_get_rows(VALUE self, VALUE args)
 | 
			
		|||
 *   @return [CvMat] Selected column
 | 
			
		||||
 * @overload get_cols(range)
 | 
			
		||||
 *   @param range [Range] Zero-based index range of the selected column
 | 
			
		||||
 *   @return [Array<CvMat>]Array of selected column
 | 
			
		||||
 * @opencv_func cvGetCol
 | 
			
		||||
 *   @return [CvMat] Selected columns
 | 
			
		||||
 * @opencv_func cvGetCols
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_get_cols(VALUE self, VALUE args)
 | 
			
		||||
rb_get_cols(VALUE self, VALUE col)
 | 
			
		||||
{
 | 
			
		||||
  int len = RARRAY_LEN(args);
 | 
			
		||||
  if (len < 1)
 | 
			
		||||
    rb_raise(rb_eArgError, "wrong number of argument.(more than 1)");
 | 
			
		||||
  VALUE ary = rb_ary_new2(len);
 | 
			
		||||
  for (int i = 0; i < len; ++i) {
 | 
			
		||||
    VALUE value = rb_ary_entry(args, i);
 | 
			
		||||
    CvMat* col = NULL;
 | 
			
		||||
  int start, end;
 | 
			
		||||
  rb_get_range_index(col, &start, &end);
 | 
			
		||||
  CvMat* submat = RB_CVALLOC(CvMat);
 | 
			
		||||
  try {
 | 
			
		||||
      if (FIXNUM_P(value))
 | 
			
		||||
	col = cvGetCol(CVARR(self), RB_CVALLOC(CvMat), FIX2INT(value));
 | 
			
		||||
      else {
 | 
			
		||||
	CvSlice slice = VALUE_TO_CVSLICE(value);
 | 
			
		||||
	col = cvGetCols(CVARR(self), RB_CVALLOC(CvMat), slice.start_index, slice.end_index);
 | 
			
		||||
      }
 | 
			
		||||
    cvGetCols(CVARR(self), submat, start, end);
 | 
			
		||||
  }
 | 
			
		||||
  catch (cv::Exception& e) {
 | 
			
		||||
      if (col != NULL)
 | 
			
		||||
	cvReleaseMat(&col);
 | 
			
		||||
    cvFree(&submat);
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
  }
 | 
			
		||||
    rb_ary_store(ary, i, DEPEND_OBJECT(rb_klass, col, self));
 | 
			
		||||
  }
 | 
			
		||||
  return RARRAY_LEN(ary) > 1 ? ary : rb_ary_entry(ary, 0);
 | 
			
		||||
 | 
			
		||||
  return DEPEND_OBJECT(rb_klass, submat, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -1319,8 +1315,8 @@ VALUE
 | 
			
		|||
rb_reshape(VALUE self, VALUE hash)
 | 
			
		||||
{
 | 
			
		||||
  Check_Type(hash, T_HASH);
 | 
			
		||||
  VALUE channel = rb_hash_aref(hash, ID2SYM(rb_intern("channel")));
 | 
			
		||||
  VALUE rows = rb_hash_aref(hash, ID2SYM(rb_intern("rows")));
 | 
			
		||||
  VALUE channel = LOOKUP_HASH(hash, "channel");
 | 
			
		||||
  VALUE rows = LOOKUP_HASH(hash, "rows");
 | 
			
		||||
  CvMat *mat = NULL;
 | 
			
		||||
  try {
 | 
			
		||||
    mat = cvReshape(CVARR(self), RB_CVALLOC(CvMat), NIL_P(channel) ? 0 : NUM2INT(channel),
 | 
			
		||||
| 
						 | 
				
			
			@ -1576,9 +1572,9 @@ rb_convert_scale(VALUE self, VALUE hash)
 | 
			
		|||
{
 | 
			
		||||
  Check_Type(hash, T_HASH);
 | 
			
		||||
  CvMat* self_ptr = CVMAT(self);
 | 
			
		||||
  VALUE depth = rb_hash_aref(hash, ID2SYM(rb_intern("depth"))),
 | 
			
		||||
    scale = rb_hash_aref(hash, ID2SYM(rb_intern("scale"))),
 | 
			
		||||
    shift = rb_hash_aref(hash, ID2SYM(rb_intern("shift")));
 | 
			
		||||
  VALUE depth = LOOKUP_HASH(hash, "depth");
 | 
			
		||||
  VALUE scale = LOOKUP_HASH(hash, "scale");
 | 
			
		||||
  VALUE shift = LOOKUP_HASH(hash, "shift");
 | 
			
		||||
 | 
			
		||||
  VALUE dest = Qnil;
 | 
			
		||||
  try {
 | 
			
		||||
| 
						 | 
				
			
			@ -1608,8 +1604,8 @@ rb_convert_scale_abs(VALUE self, VALUE hash)
 | 
			
		|||
{
 | 
			
		||||
  Check_Type(hash, T_HASH);
 | 
			
		||||
  CvMat* self_ptr = CVMAT(self);
 | 
			
		||||
  VALUE scale = rb_hash_aref(hash, ID2SYM(rb_intern("scale"))),
 | 
			
		||||
    shift = rb_hash_aref(hash, ID2SYM(rb_intern("shift")));
 | 
			
		||||
  VALUE scale = LOOKUP_HASH(hash, "scale");
 | 
			
		||||
  VALUE shift = LOOKUP_HASH(hash, "shift");
 | 
			
		||||
  VALUE dest = Qnil;
 | 
			
		||||
  try {
 | 
			
		||||
    dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_8U, CV_MAT_CN(CVMAT(self)->type));
 | 
			
		||||
| 
						 | 
				
			
			@ -2398,9 +2394,9 @@ rb_mul_transposed(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
 | 
			
		||||
  if (rb_scan_args(argc, argv, "01", &options) > 0) {
 | 
			
		||||
    Check_Type(options, T_HASH);
 | 
			
		||||
    _delta = LOOKUP_CVMETHOD(options, "delta");
 | 
			
		||||
    _scale = LOOKUP_CVMETHOD(options, "scale");
 | 
			
		||||
    _order = LOOKUP_CVMETHOD(options, "order");
 | 
			
		||||
    _delta = LOOKUP_HASH(options, "delta");
 | 
			
		||||
    _scale = LOOKUP_HASH(options, "scale");
 | 
			
		||||
    _order = LOOKUP_HASH(options, "order");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  CvArr* delta = NIL_P(_delta) ? NULL : CVARR_WITH_CHECK(_delta);
 | 
			
		||||
| 
						 | 
				
			
			@ -4000,9 +3996,26 @@ rb_dilate_bang(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
  return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   morpholohy(<i>operation[,element = nil][,iteration = 1]</i>) -> cvmat
 | 
			
		||||
 *
 | 
			
		||||
 * Performs advanced morphological transformations.
 | 
			
		||||
 * <i>operation</i>
 | 
			
		||||
 * Type of morphological operation, one of:
 | 
			
		||||
 *   CV_MOP_OPEN - opening
 | 
			
		||||
 *   CV_MOP_CLOSE - closing
 | 
			
		||||
 *   CV_MOP_GRADIENT - morphological gradient
 | 
			
		||||
 *   CV_MOP_TOPHAT - top hat
 | 
			
		||||
 *   CV_MOP_BLACKHAT - black hat
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_morphology_internal(VALUE element, VALUE iteration, int operation, VALUE self)
 | 
			
		||||
rb_morphology(int argc, VALUE *argv, VALUE self)
 | 
			
		||||
{
 | 
			
		||||
  VALUE element, iteration, operation_val;
 | 
			
		||||
  rb_scan_args(argc, argv, "12", &operation_val, &element, &iteration);
 | 
			
		||||
 | 
			
		||||
  int operation = CVMETHOD("MORPHOLOGICAL_OPERATION", operation_val, -1);
 | 
			
		||||
  CvArr* self_ptr = CVARR(self);
 | 
			
		||||
  CvSize size = cvGetSize(self_ptr);
 | 
			
		||||
  VALUE dest = new_mat_kind_object(size, self);
 | 
			
		||||
| 
						 | 
				
			
			@ -4020,28 +4033,8 @@ rb_morphology_internal(VALUE element, VALUE iteration, int operation, VALUE self
 | 
			
		|||
  catch (cv::Exception& e) {
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
  }
 | 
			
		||||
  return dest;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   morpholohy(<i>operation[,element = nil][,iteration = 1]</i>) -> cvmat
 | 
			
		||||
 *
 | 
			
		||||
 * Performs advanced morphological transformations.
 | 
			
		||||
 * <i>operation</i>
 | 
			
		||||
 * Type of morphological operation, one of:
 | 
			
		||||
 *   CV_MOP_OPEN - opening
 | 
			
		||||
 *   CV_MOP_CLOSE - closing
 | 
			
		||||
 *   CV_MOP_GRADIENT - morphological gradient
 | 
			
		||||
 *   CV_MOP_TOPHAT - top hat
 | 
			
		||||
 *   CV_MOP_BLACKHAT - black hat
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_morphology(int argc, VALUE *argv, VALUE self)
 | 
			
		||||
{
 | 
			
		||||
  VALUE element, iteration, operation;
 | 
			
		||||
  rb_scan_args(argc, argv, "12", &operation, &element, &iteration);
 | 
			
		||||
  return rb_morphology_internal(element, iteration, CVMETHOD("MORPHOLOGICAL_OPERATION", operation, -1), self);
 | 
			
		||||
  return dest;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -4389,15 +4382,15 @@ rb_adaptive_threshold(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
  double param1 = 5;
 | 
			
		||||
  if (!NIL_P(options)) {
 | 
			
		||||
    Check_Type(options, T_HASH);
 | 
			
		||||
    threshold_type = CVMETHOD("THRESHOLD_TYPE", LOOKUP_CVMETHOD(options, "threshold_type"),
 | 
			
		||||
    threshold_type = CVMETHOD("THRESHOLD_TYPE", LOOKUP_HASH(options, "threshold_type"),
 | 
			
		||||
			      CV_THRESH_BINARY);
 | 
			
		||||
    adaptive_method = CVMETHOD("ADAPTIVE_METHOD", LOOKUP_CVMETHOD(options, "adaptive_method"),
 | 
			
		||||
    adaptive_method = CVMETHOD("ADAPTIVE_METHOD", LOOKUP_HASH(options, "adaptive_method"),
 | 
			
		||||
			       CV_ADAPTIVE_THRESH_MEAN_C);
 | 
			
		||||
    VALUE _block_size = LOOKUP_CVMETHOD(options, "block_size");
 | 
			
		||||
    VALUE _block_size = LOOKUP_HASH(options, "block_size");
 | 
			
		||||
    if (!NIL_P(_block_size)) {
 | 
			
		||||
      block_size = NUM2INT(_block_size);
 | 
			
		||||
    }
 | 
			
		||||
    VALUE _param1 = LOOKUP_CVMETHOD(options, "param1");
 | 
			
		||||
    VALUE _param1 = LOOKUP_HASH(options, "param1");
 | 
			
		||||
    if (!NIL_P(_param1)) {
 | 
			
		||||
      param1 = NUM2INT(_param1);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -4766,42 +4759,6 @@ rb_draw_chessboard_corners_bang(VALUE self, VALUE pattern_size, VALUE corners, V
 | 
			
		|||
  return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   pyr_segmentation(<i>level, threshold1, threshold2</i>) -> [cvmat, cvseq(include cvconnectedcomp)]
 | 
			
		||||
 *
 | 
			
		||||
 * Does image segmentation by pyramids.
 | 
			
		||||
 * The pyramid builds up to the level <i>level<i>.
 | 
			
		||||
 * The links between any pixel a on <i>level<i>i and
 | 
			
		||||
 * its candidate father pixel b on the adjacent level are established if
 | 
			
		||||
 *   p(c(a),c(b)) < threshold1. After the connected components are defined, they are joined into several clusters. Any two segments A and B belong to the same cluster, if
 | 
			
		||||
 *   p(c(A),c(B)) < threshold2. The input image has only one channel, then
 | 
			
		||||
 *   p(c^2,c^2)=|c^2-c^2|. If the input image has three channels (red, green and blue), then
 | 
			
		||||
 *   p(c^2,c^2)=0,3*(c^2 r-c^2 r)+0.59*(c^2 g-c^2 g)+0,11*(c^2 b-c^2 b) . There may be more than one connected component per a cluster.
 | 
			
		||||
 *
 | 
			
		||||
 * Return segmented image and sequence of connected components.
 | 
			
		||||
 * <b>support single-channel or 3-channel 8bit unsigned image only</b>
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_pyr_segmentation(VALUE self, VALUE level, VALUE threshold1, VALUE threshold2)
 | 
			
		||||
{
 | 
			
		||||
  IplImage* self_ptr = IPLIMAGE(self);
 | 
			
		||||
  CvSeq *comp = NULL;
 | 
			
		||||
  VALUE storage = cCvMemStorage::new_object();
 | 
			
		||||
  VALUE dest = Qnil;
 | 
			
		||||
  try {
 | 
			
		||||
    dest = cIplImage::new_object(cvGetSize(self_ptr), cvGetElemType(self_ptr));
 | 
			
		||||
    cvPyrSegmentation(self_ptr, IPLIMAGE(dest), CVMEMSTORAGE(storage), &comp,
 | 
			
		||||
		      NUM2INT(level), NUM2DBL(threshold1), NUM2DBL(threshold2));
 | 
			
		||||
  }
 | 
			
		||||
  catch (cv::Exception& e) {
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
  }
 | 
			
		||||
  if (!comp)
 | 
			
		||||
    comp = cvCreateSeq(CV_SEQ_CONNECTED_COMP, sizeof(CvSeq), sizeof(CvConnectedComp), CVMEMSTORAGE(storage));
 | 
			
		||||
  return rb_ary_new3(2, dest, cCvSeq::new_sequence(cCvSeq::rb_class(), comp, cCvConnectedComp::rb_class(), storage));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   pyr_mean_shift_filtering(<i>sp, sr[,max_level = 1][termcrit = CvTermCriteria.new(5,1)]</i>) -> cvmat
 | 
			
		||||
| 
						 | 
				
			
			@ -4877,7 +4834,7 @@ rb_watershed(VALUE self, VALUE markers)
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   moments -> array(include CvMoments)
 | 
			
		||||
 *   moments -> cvmoments
 | 
			
		||||
 *
 | 
			
		||||
 * Calculates moments.
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -4886,14 +4843,10 @@ rb_moments(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
{
 | 
			
		||||
  VALUE is_binary;
 | 
			
		||||
  rb_scan_args(argc, argv, "01", &is_binary);
 | 
			
		||||
  IplImage image = *IPLIMAGE(self);
 | 
			
		||||
  VALUE moments = rb_ary_new();
 | 
			
		||||
  CvArr *self_ptr = CVARR(self);
 | 
			
		||||
  VALUE moments = Qnil;
 | 
			
		||||
  try {
 | 
			
		||||
    int cn = CV_MAT_CN(cvGetElemType(CVARR(self)));
 | 
			
		||||
    for (int i = 1; i <= cn; ++i) {
 | 
			
		||||
      cvSetImageCOI(&image, i);
 | 
			
		||||
      rb_ary_push(moments, cCvMoments::new_object(&image, TRUE_OR_FALSE(is_binary, 0)));
 | 
			
		||||
    }
 | 
			
		||||
    moments = cCvMoments::new_object(self_ptr, TRUE_OR_FALSE(is_binary, 0));
 | 
			
		||||
  }
 | 
			
		||||
  catch (cv::Exception& e) {
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
| 
						 | 
				
			
			@ -5214,7 +5167,7 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
 | 
			
		|||
  VALUE _matches = rb_hash_new();
 | 
			
		||||
  for (size_t i=0; i<matches.size(); i++) {
 | 
			
		||||
    VALUE match = INT2FIX(matches[i].imgIdx);
 | 
			
		||||
    VALUE count = rb_hash_aref(_matches, match);
 | 
			
		||||
    VALUE count = rb_hash_lookup(_matches, match);
 | 
			
		||||
    if (NIL_P(count)) {
 | 
			
		||||
      count = INT2FIX(1);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -5787,8 +5740,8 @@ init_ruby_class()
 | 
			
		|||
  rb_define_method(rb_klass, "to_CvMat", RUBY_METHOD_FUNC(rb_to_CvMat), 0);
 | 
			
		||||
  rb_define_method(rb_klass, "sub_rect", RUBY_METHOD_FUNC(rb_sub_rect), -2);
 | 
			
		||||
  rb_define_alias(rb_klass, "subrect", "sub_rect");
 | 
			
		||||
  rb_define_method(rb_klass, "get_rows", RUBY_METHOD_FUNC(rb_get_rows), -2);
 | 
			
		||||
  rb_define_method(rb_klass, "get_cols", RUBY_METHOD_FUNC(rb_get_cols), -2);
 | 
			
		||||
  rb_define_method(rb_klass, "get_rows", RUBY_METHOD_FUNC(rb_get_rows), -1);
 | 
			
		||||
  rb_define_method(rb_klass, "get_cols", RUBY_METHOD_FUNC(rb_get_cols), 1);
 | 
			
		||||
  rb_define_method(rb_klass, "each_row", RUBY_METHOD_FUNC(rb_each_row), 0);
 | 
			
		||||
  rb_define_method(rb_klass, "each_col", RUBY_METHOD_FUNC(rb_each_col), 0);
 | 
			
		||||
  rb_define_alias(rb_klass, "each_column", "each_col");
 | 
			
		||||
| 
						 | 
				
			
			@ -5943,7 +5896,6 @@ init_ruby_class()
 | 
			
		|||
  rb_define_method(rb_klass, "draw_contours!", RUBY_METHOD_FUNC(rb_draw_contours_bang), -1);
 | 
			
		||||
  rb_define_method(rb_klass, "draw_chessboard_corners", RUBY_METHOD_FUNC(rb_draw_chessboard_corners), 3);
 | 
			
		||||
  rb_define_method(rb_klass, "draw_chessboard_corners!", RUBY_METHOD_FUNC(rb_draw_chessboard_corners_bang), 3);
 | 
			
		||||
  rb_define_method(rb_klass, "pyr_segmentation", RUBY_METHOD_FUNC(rb_pyr_segmentation), 3);
 | 
			
		||||
  rb_define_method(rb_klass, "pyr_mean_shift_filtering", RUBY_METHOD_FUNC(rb_pyr_mean_shift_filtering), -1);
 | 
			
		||||
  rb_define_method(rb_klass, "watershed", RUBY_METHOD_FUNC(rb_watershed), 1);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,8 +58,8 @@ VALUE rb_square_q(VALUE self);
 | 
			
		|||
VALUE rb_to_CvMat(VALUE self);
 | 
			
		||||
VALUE rb_to_IplImage(VALUE self);
 | 
			
		||||
VALUE rb_sub_rect(VALUE self, VALUE args);
 | 
			
		||||
VALUE rb_get_rows(VALUE self, VALUE args);
 | 
			
		||||
VALUE rb_get_cols(VALUE self, VALUE args);
 | 
			
		||||
VALUE rb_get_rows(int argc, VALUE* argv, VALUE self);
 | 
			
		||||
VALUE rb_get_cols(VALUE self, VALUE col);
 | 
			
		||||
VALUE rb_each_row(VALUE self);
 | 
			
		||||
VALUE rb_each_col(VALUE self);
 | 
			
		||||
VALUE rb_diag(int argc, VALUE *argv, VALUE self);
 | 
			
		||||
| 
						 | 
				
			
			@ -204,7 +204,6 @@ VALUE rb_draw_contours(int argc, VALUE *argv, VALUE self);
 | 
			
		|||
VALUE rb_draw_contours_bang(int argc, VALUE *argv, VALUE self);
 | 
			
		||||
VALUE rb_draw_chessboard_corners(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
 | 
			
		||||
VALUE rb_draw_chessboard_corners_bang(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
 | 
			
		||||
VALUE rb_pyr_segmentation(VALUE self, VALUE level, VALUE threshold1, VALUE threshold2);
 | 
			
		||||
VALUE rb_pyr_mean_shift_filtering(int argc, VALUE *argv, VALUE self);
 | 
			
		||||
VALUE rb_watershed(VALUE self, VALUE markers);
 | 
			
		||||
VALUE rb_moments(int argc, VALUE *argv, VALUE self);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,7 +60,7 @@ define_ruby_class()
 | 
			
		|||
  rb_define_method(rb_klass, "set_coi", RUBY_METHOD_FUNC(rb_set_coi), 1);
 | 
			
		||||
  rb_define_alias(rb_klass, "coi=", "set_coi");
 | 
			
		||||
  rb_define_method(rb_klass, "reset_coi", RUBY_METHOD_FUNC(rb_reset_coi), 0); 
 | 
			
		||||
 | 
			
		||||
  rb_define_method(rb_klass, "pyr_segmentation", RUBY_METHOD_FUNC(rb_pyr_segmentation), 3);
 | 
			
		||||
  rb_define_method(rb_klass, "smoothness", RUBY_METHOD_FUNC(rb_smoothness), -1);
 | 
			
		||||
 | 
			
		||||
  rb_define_singleton_method(rb_klass, "decode_image", RUBY_METHOD_FUNC(rb_decode_image), -1);
 | 
			
		||||
| 
						 | 
				
			
			@ -591,6 +591,42 @@ high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &
 | 
			
		|||
  outLow = (int)(lostPercentage * outHigh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * call-seq:
 | 
			
		||||
 *   pyr_segmentation(<i>level, threshold1, threshold2</i>) -> [iplimage, cvseq(include cvconnectedcomp)]
 | 
			
		||||
 *
 | 
			
		||||
 * Does image segmentation by pyramids.
 | 
			
		||||
 * The pyramid builds up to the level <i>level<i>.
 | 
			
		||||
 * The links between any pixel a on <i>level<i>i and
 | 
			
		||||
 * its candidate father pixel b on the adjacent level are established if
 | 
			
		||||
 *   p(c(a),c(b)) < threshold1. After the connected components are defined, they are joined into several clusters. Any two segments A and B belong to the same cluster, if
 | 
			
		||||
 *   p(c(A),c(B)) < threshold2. The input image has only one channel, then
 | 
			
		||||
 *   p(c^2,c^2)=|c^2-c^2|. If the input image has three channels (red, green and blue), then
 | 
			
		||||
 *   p(c^2,c^2)=0,3*(c^2 r-c^2 r)+0.59*(c^2 g-c^2 g)+0,11*(c^2 b-c^2 b) . There may be more than one connected component per a cluster.
 | 
			
		||||
 *
 | 
			
		||||
 * Return segmented image and sequence of connected components.
 | 
			
		||||
 * <b>support single-channel or 3-channel 8bit unsigned image only</b>
 | 
			
		||||
 */
 | 
			
		||||
VALUE
 | 
			
		||||
rb_pyr_segmentation(VALUE self, VALUE level, VALUE threshold1, VALUE threshold2)
 | 
			
		||||
{
 | 
			
		||||
  IplImage* self_ptr = IPLIMAGE(self);
 | 
			
		||||
  CvSeq *comp = NULL;
 | 
			
		||||
  VALUE storage = cCvMemStorage::new_object();
 | 
			
		||||
  VALUE dest = Qnil;
 | 
			
		||||
  try {
 | 
			
		||||
    dest = cIplImage::new_object(cvGetSize(self_ptr), cvGetElemType(self_ptr));
 | 
			
		||||
    cvPyrSegmentation(self_ptr, IPLIMAGE(dest), CVMEMSTORAGE(storage), &comp,
 | 
			
		||||
		      NUM2INT(level), NUM2DBL(threshold1), NUM2DBL(threshold2));
 | 
			
		||||
  }
 | 
			
		||||
  catch (cv::Exception& e) {
 | 
			
		||||
    raise_cverror(e);
 | 
			
		||||
  }
 | 
			
		||||
  if (!comp) {
 | 
			
		||||
    comp = cvCreateSeq(CV_SEQ_CONNECTED_COMP, sizeof(CvSeq), sizeof(CvConnectedComp), CVMEMSTORAGE(storage));
 | 
			
		||||
  }
 | 
			
		||||
  return rb_ary_new3(2, dest, cCvSeq::new_sequence(cCvSeq::rb_class(), comp, cCvConnectedComp::rb_class(), storage));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VALUE
 | 
			
		||||
new_object(int width, int height, int type)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,8 @@ VALUE rb_get_coi(VALUE self);
 | 
			
		|||
VALUE rb_set_coi(VALUE self, VALUE coi);
 | 
			
		||||
VALUE rb_reset_coi(VALUE self);
 | 
			
		||||
 | 
			
		||||
VALUE rb_pyr_segmentation(VALUE self, VALUE level, VALUE threshold1, VALUE threshold2);
 | 
			
		||||
 | 
			
		||||
VALUE rb_smoothness(int argc, VALUE *argv, VALUE self);
 | 
			
		||||
typedef enum { SMOOTH = 1, BLANK = 2, MESSY = 3 } Smoothness;
 | 
			
		||||
Smoothness compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, const double blankDensity, const double messyDensity, const double highFreqRatio, double &outLowDensity, double &outHighDensity);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -341,129 +341,129 @@ define_ruby_module()
 | 
			
		|||
  VALUE inversion_method = rb_hash_new();
 | 
			
		||||
  /* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
 | 
			
		||||
  rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
 | 
			
		||||
  REGISTER_CVMETHOD(inversion_method, "lu", CV_LU);
 | 
			
		||||
  REGISTER_CVMETHOD(inversion_method, "svd", CV_SVD);
 | 
			
		||||
  REGISTER_CVMETHOD(inversion_method, "svd_sym", CV_SVD_SYM);
 | 
			
		||||
  REGISTER_CVMETHOD(inversion_method, "svd_symmetric", CV_SVD_SYM);
 | 
			
		||||
  REGISTER_HASH(inversion_method, "lu", CV_LU);
 | 
			
		||||
  REGISTER_HASH(inversion_method, "svd", CV_SVD);
 | 
			
		||||
  REGISTER_HASH(inversion_method, "svd_sym", CV_SVD_SYM);
 | 
			
		||||
  REGISTER_HASH(inversion_method, "svd_symmetric", CV_SVD_SYM);
 | 
			
		||||
    
 | 
			
		||||
  VALUE homography_calc_method = rb_hash_new();
 | 
			
		||||
  /* {:all, :ransac, :lmeds}: Methods used to computed homography matrix */
 | 
			
		||||
  rb_define_const(rb_module, "HOMOGRAPHY_CALC_METHOD", homography_calc_method);
 | 
			
		||||
  REGISTER_CVMETHOD(homography_calc_method, "all", 0);
 | 
			
		||||
  REGISTER_CVMETHOD(homography_calc_method, "ransac", CV_RANSAC);
 | 
			
		||||
  REGISTER_CVMETHOD(homography_calc_method, "lmeds", CV_LMEDS);
 | 
			
		||||
  REGISTER_HASH(homography_calc_method, "all", 0);
 | 
			
		||||
  REGISTER_HASH(homography_calc_method, "ransac", CV_RANSAC);
 | 
			
		||||
  REGISTER_HASH(homography_calc_method, "lmeds", CV_LMEDS);
 | 
			
		||||
 | 
			
		||||
  VALUE depth = rb_hash_new();
 | 
			
		||||
  /* {:cv8u, :cv8s, :cv16u, :cv16s, :cv32s, :cv32f, :cv64f}: Depth of each pixel. */
 | 
			
		||||
  rb_define_const(rb_module, "DEPTH", depth);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv8u", CV_8U);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv8s", CV_8S);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv16u", CV_16U);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv16s", CV_16S);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv32s", CV_32S);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv32f", CV_32F);
 | 
			
		||||
  REGISTER_CVMETHOD(depth, "cv64f", CV_64F);
 | 
			
		||||
  REGISTER_HASH(depth, "cv8u", CV_8U);
 | 
			
		||||
  REGISTER_HASH(depth, "cv8s", CV_8S);
 | 
			
		||||
  REGISTER_HASH(depth, "cv16u", CV_16U);
 | 
			
		||||
  REGISTER_HASH(depth, "cv16s", CV_16S);
 | 
			
		||||
  REGISTER_HASH(depth, "cv32s", CV_32S);
 | 
			
		||||
  REGISTER_HASH(depth, "cv32f", CV_32F);
 | 
			
		||||
  REGISTER_HASH(depth, "cv64f", CV_64F);
 | 
			
		||||
  
 | 
			
		||||
  VALUE connectivity = rb_hash_new();
 | 
			
		||||
  /* {:aa(:anti_alias)}: Determined by the closeness of pixel values */
 | 
			
		||||
  rb_define_const(rb_module, "CONNECTIVITY", connectivity);
 | 
			
		||||
  REGISTER_CVMETHOD(connectivity, "aa", CV_AA);
 | 
			
		||||
  REGISTER_CVMETHOD(connectivity, "anti_alias", CV_AA);
 | 
			
		||||
  REGISTER_HASH(connectivity, "aa", CV_AA);
 | 
			
		||||
  REGISTER_HASH(connectivity, "anti_alias", CV_AA);
 | 
			
		||||
 | 
			
		||||
  VALUE structuring_element_shape = rb_hash_new();
 | 
			
		||||
  /* {:rect, :cross, :ellipse, :custom}: Shape of the structuring elements */
 | 
			
		||||
  rb_define_const(rb_module, "STRUCTURING_ELEMENT_SHAPE", structuring_element_shape);
 | 
			
		||||
  REGISTER_CVMETHOD(structuring_element_shape, "rect", CV_SHAPE_RECT);
 | 
			
		||||
  REGISTER_CVMETHOD(structuring_element_shape, "cross", CV_SHAPE_CROSS);
 | 
			
		||||
  REGISTER_CVMETHOD(structuring_element_shape, "ellipse", CV_SHAPE_ELLIPSE);
 | 
			
		||||
  REGISTER_CVMETHOD(structuring_element_shape, "custom", CV_SHAPE_CUSTOM);
 | 
			
		||||
  REGISTER_HASH(structuring_element_shape, "rect", CV_SHAPE_RECT);
 | 
			
		||||
  REGISTER_HASH(structuring_element_shape, "cross", CV_SHAPE_CROSS);
 | 
			
		||||
  REGISTER_HASH(structuring_element_shape, "ellipse", CV_SHAPE_ELLIPSE);
 | 
			
		||||
  REGISTER_HASH(structuring_element_shape, "custom", CV_SHAPE_CUSTOM);
 | 
			
		||||
 | 
			
		||||
  VALUE retrieval_mode = rb_hash_new();
 | 
			
		||||
  /* {:external, :list, :ccomp, :tree}: Retrieval mode */
 | 
			
		||||
  rb_define_const(rb_module, "RETRIEVAL_MODE", retrieval_mode);
 | 
			
		||||
  REGISTER_CVMETHOD(retrieval_mode, "external", CV_RETR_EXTERNAL);
 | 
			
		||||
  REGISTER_CVMETHOD(retrieval_mode, "list", CV_RETR_LIST);
 | 
			
		||||
  REGISTER_CVMETHOD(retrieval_mode, "ccomp", CV_RETR_CCOMP);
 | 
			
		||||
  REGISTER_CVMETHOD(retrieval_mode, "tree", CV_RETR_TREE);
 | 
			
		||||
  REGISTER_HASH(retrieval_mode, "external", CV_RETR_EXTERNAL);
 | 
			
		||||
  REGISTER_HASH(retrieval_mode, "list", CV_RETR_LIST);
 | 
			
		||||
  REGISTER_HASH(retrieval_mode, "ccomp", CV_RETR_CCOMP);
 | 
			
		||||
  REGISTER_HASH(retrieval_mode, "tree", CV_RETR_TREE);
 | 
			
		||||
 | 
			
		||||
  VALUE approx_chain_method = rb_hash_new();
 | 
			
		||||
  /* {:code, :approx_none, :approx_simple, :apporx_tc89_11, :approx_tc89_kcos}: Approximation method */
 | 
			
		||||
  rb_define_const(rb_module, "APPROX_CHAIN_METHOD", approx_chain_method);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_chain_method, "code", CV_CHAIN_CODE);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_chain_method, "approx_none", CV_CHAIN_APPROX_NONE);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_chain_method, "approx_simple", CV_CHAIN_APPROX_SIMPLE);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_chain_method, "approx_tc89_l1", CV_CHAIN_APPROX_TC89_L1);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_chain_method, "approx_tc89_kcos", CV_CHAIN_APPROX_TC89_KCOS);
 | 
			
		||||
  REGISTER_HASH(approx_chain_method, "code", CV_CHAIN_CODE);
 | 
			
		||||
  REGISTER_HASH(approx_chain_method, "approx_none", CV_CHAIN_APPROX_NONE);
 | 
			
		||||
  REGISTER_HASH(approx_chain_method, "approx_simple", CV_CHAIN_APPROX_SIMPLE);
 | 
			
		||||
  REGISTER_HASH(approx_chain_method, "approx_tc89_l1", CV_CHAIN_APPROX_TC89_L1);
 | 
			
		||||
  REGISTER_HASH(approx_chain_method, "approx_tc89_kcos", CV_CHAIN_APPROX_TC89_KCOS);
 | 
			
		||||
  
 | 
			
		||||
  VALUE approx_poly_method = rb_hash_new();
 | 
			
		||||
  /* {:dp}: Approximation method (polygon) */
 | 
			
		||||
  rb_define_const(rb_module, "APPROX_POLY_METHOD", approx_poly_method);
 | 
			
		||||
  REGISTER_CVMETHOD(approx_poly_method, "dp", CV_POLY_APPROX_DP);
 | 
			
		||||
  REGISTER_HASH(approx_poly_method, "dp", CV_POLY_APPROX_DP);
 | 
			
		||||
 | 
			
		||||
  VALUE match_template_method = rb_hash_new();
 | 
			
		||||
  /* {:sqdiff, :sqdiff_normed, :ccorr, :ccorr_normed, :ccoeff, :ccoeff_normed}: Match template method */
 | 
			
		||||
  rb_define_const(rb_module, "MATCH_TEMPLATE_METHOD", match_template_method);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "sqdiff", CV_TM_SQDIFF);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "sqdiff_normed", CV_TM_SQDIFF_NORMED);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "ccorr", CV_TM_CCORR);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "ccorr_normed", CV_TM_CCORR_NORMED);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "ccoeff", CV_TM_CCOEFF);
 | 
			
		||||
  REGISTER_CVMETHOD(match_template_method, "ccoeff_normed", CV_TM_CCOEFF_NORMED);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "sqdiff", CV_TM_SQDIFF);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "sqdiff_normed", CV_TM_SQDIFF_NORMED);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "ccorr", CV_TM_CCORR);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "ccorr_normed", CV_TM_CCORR_NORMED);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "ccoeff", CV_TM_CCOEFF);
 | 
			
		||||
  REGISTER_HASH(match_template_method, "ccoeff_normed", CV_TM_CCOEFF_NORMED);
 | 
			
		||||
 | 
			
		||||
  VALUE morphological_operation = rb_hash_new();
 | 
			
		||||
  /* {:open, :close, :gradient, :tophat, :blackhat}: Types of morphological operations */
 | 
			
		||||
  rb_define_const(rb_module, "MORPHOLOGICAL_OPERATION", morphological_operation);
 | 
			
		||||
  REGISTER_CVMETHOD(morphological_operation, "open", CV_MOP_OPEN);
 | 
			
		||||
  REGISTER_CVMETHOD(morphological_operation, "close", CV_MOP_CLOSE);
 | 
			
		||||
  REGISTER_CVMETHOD(morphological_operation, "gradient", CV_MOP_GRADIENT);
 | 
			
		||||
  REGISTER_CVMETHOD(morphological_operation, "tophat", CV_MOP_TOPHAT);
 | 
			
		||||
  REGISTER_CVMETHOD(morphological_operation, "blackhat", CV_MOP_BLACKHAT);
 | 
			
		||||
  REGISTER_HASH(morphological_operation, "open", CV_MOP_OPEN);
 | 
			
		||||
  REGISTER_HASH(morphological_operation, "close", CV_MOP_CLOSE);
 | 
			
		||||
  REGISTER_HASH(morphological_operation, "gradient", CV_MOP_GRADIENT);
 | 
			
		||||
  REGISTER_HASH(morphological_operation, "tophat", CV_MOP_TOPHAT);
 | 
			
		||||
  REGISTER_HASH(morphological_operation, "blackhat", CV_MOP_BLACKHAT);
 | 
			
		||||
 | 
			
		||||
  VALUE smoothing_type = rb_hash_new();
 | 
			
		||||
  /* {:blur_no_scale, :blur, :gaussian, :median, :bilateral}: Types of smoothing */
 | 
			
		||||
  rb_define_const(rb_module, "SMOOTHING_TYPE", smoothing_type);
 | 
			
		||||
  REGISTER_CVMETHOD(smoothing_type, "blur_no_scale", CV_BLUR_NO_SCALE);
 | 
			
		||||
  REGISTER_CVMETHOD(smoothing_type, "blur", CV_BLUR);
 | 
			
		||||
  REGISTER_CVMETHOD(smoothing_type, "gaussian", CV_GAUSSIAN);
 | 
			
		||||
  REGISTER_CVMETHOD(smoothing_type, "median", CV_MEDIAN);
 | 
			
		||||
  REGISTER_CVMETHOD(smoothing_type, "bilateral", CV_BILATERAL);
 | 
			
		||||
  REGISTER_HASH(smoothing_type, "blur_no_scale", CV_BLUR_NO_SCALE);
 | 
			
		||||
  REGISTER_HASH(smoothing_type, "blur", CV_BLUR);
 | 
			
		||||
  REGISTER_HASH(smoothing_type, "gaussian", CV_GAUSSIAN);
 | 
			
		||||
  REGISTER_HASH(smoothing_type, "median", CV_MEDIAN);
 | 
			
		||||
  REGISTER_HASH(smoothing_type, "bilateral", CV_BILATERAL);
 | 
			
		||||
 | 
			
		||||
  VALUE adaptive_method = rb_hash_new();
 | 
			
		||||
  /* {:mean_c, :gaussian_c}: Adaptive thresholding algorithm */
 | 
			
		||||
  rb_define_const(rb_module, "ADAPTIVE_METHOD", adaptive_method);
 | 
			
		||||
  REGISTER_CVMETHOD(adaptive_method, "mean_c", CV_ADAPTIVE_THRESH_MEAN_C);
 | 
			
		||||
  REGISTER_CVMETHOD(adaptive_method, "gaussian_c", CV_ADAPTIVE_THRESH_GAUSSIAN_C);
 | 
			
		||||
  REGISTER_HASH(adaptive_method, "mean_c", CV_ADAPTIVE_THRESH_MEAN_C);
 | 
			
		||||
  REGISTER_HASH(adaptive_method, "gaussian_c", CV_ADAPTIVE_THRESH_GAUSSIAN_C);
 | 
			
		||||
 | 
			
		||||
  VALUE threshold_type = rb_hash_new();
 | 
			
		||||
  /* {:binary, :binary_inv, :trunc, :tozero, :tozero_inv, :otsu} : Thresholding types */
 | 
			
		||||
  rb_define_const(rb_module, "THRESHOLD_TYPE", threshold_type);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "binary", CV_THRESH_BINARY);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "binary_inv", CV_THRESH_BINARY_INV);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "trunc", CV_THRESH_TRUNC);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "tozero", CV_THRESH_TOZERO);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "tozero_inv", CV_THRESH_TOZERO_INV);
 | 
			
		||||
  REGISTER_CVMETHOD(threshold_type, "otsu", CV_THRESH_OTSU);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "binary", CV_THRESH_BINARY);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "binary_inv", CV_THRESH_BINARY_INV);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "trunc", CV_THRESH_TRUNC);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "tozero", CV_THRESH_TOZERO);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "tozero_inv", CV_THRESH_TOZERO_INV);
 | 
			
		||||
  REGISTER_HASH(threshold_type, "otsu", CV_THRESH_OTSU);
 | 
			
		||||
 | 
			
		||||
  VALUE hough_transform_method = rb_hash_new();
 | 
			
		||||
  /* {:standard, :probabilistic, :multi_scale} : Hough transform method */
 | 
			
		||||
  rb_define_const(rb_module, "HOUGH_TRANSFORM_METHOD", hough_transform_method);
 | 
			
		||||
  REGISTER_CVMETHOD(hough_transform_method, "standard", CV_HOUGH_STANDARD);
 | 
			
		||||
  REGISTER_CVMETHOD(hough_transform_method, "probabilistic", CV_HOUGH_PROBABILISTIC);
 | 
			
		||||
  REGISTER_CVMETHOD(hough_transform_method, "multi_scale", CV_HOUGH_MULTI_SCALE);
 | 
			
		||||
  REGISTER_CVMETHOD(hough_transform_method, "gradient", CV_HOUGH_GRADIENT);
 | 
			
		||||
  REGISTER_HASH(hough_transform_method, "standard", CV_HOUGH_STANDARD);
 | 
			
		||||
  REGISTER_HASH(hough_transform_method, "probabilistic", CV_HOUGH_PROBABILISTIC);
 | 
			
		||||
  REGISTER_HASH(hough_transform_method, "multi_scale", CV_HOUGH_MULTI_SCALE);
 | 
			
		||||
  REGISTER_HASH(hough_transform_method, "gradient", CV_HOUGH_GRADIENT);
 | 
			
		||||
 | 
			
		||||
  VALUE inpaint_method = rb_hash_new();
 | 
			
		||||
  /* {:ns, :telea} : Inpaint method */
 | 
			
		||||
  rb_define_const(rb_module, "INPAINT_METHOD", inpaint_method);
 | 
			
		||||
  REGISTER_CVMETHOD(inpaint_method, "ns", CV_INPAINT_NS);
 | 
			
		||||
  REGISTER_CVMETHOD(inpaint_method, "telea", CV_INPAINT_TELEA);
 | 
			
		||||
  REGISTER_HASH(inpaint_method, "ns", CV_INPAINT_NS);
 | 
			
		||||
  REGISTER_HASH(inpaint_method, "telea", CV_INPAINT_TELEA);
 | 
			
		||||
 | 
			
		||||
  VALUE comparison_method = rb_hash_new();
 | 
			
		||||
  /* Comparison method */
 | 
			
		||||
  rb_define_const(rb_module, "COMPARISON_METHOD", comparison_method);
 | 
			
		||||
  REGISTER_CVMETHOD(comparison_method, "i1", CV_CONTOURS_MATCH_I1);
 | 
			
		||||
  REGISTER_CVMETHOD(comparison_method, "i2", CV_CONTOURS_MATCH_I2);
 | 
			
		||||
  REGISTER_CVMETHOD(comparison_method, "i3", CV_CONTOURS_MATCH_I3);
 | 
			
		||||
  REGISTER_HASH(comparison_method, "i1", CV_CONTOURS_MATCH_I1);
 | 
			
		||||
  REGISTER_HASH(comparison_method, "i2", CV_CONTOURS_MATCH_I2);
 | 
			
		||||
  REGISTER_HASH(comparison_method, "i3", CV_CONTOURS_MATCH_I3);
 | 
			
		||||
 | 
			
		||||
  /* color convert methods */
 | 
			
		||||
  rb_define_module_function(rb_module, "BGR2BGRA", RUBY_METHOD_FUNC(rb_BGR2BGRA), 1);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -147,8 +147,8 @@ extern "C" {
 | 
			
		|||
 | 
			
		||||
#define IF_DEPTH(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
 | 
			
		||||
 | 
			
		||||
#define REGISTER_CVMETHOD(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
 | 
			
		||||
#define LOOKUP_CVMETHOD(hash, key_as_cstr) (rb_hash_lookup(hash, ID2SYM(rb_intern(key_as_cstr))))
 | 
			
		||||
#define REGISTER_HASH(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
 | 
			
		||||
#define LOOKUP_HASH(hash, key_as_cstr) (rb_hash_lookup(hash, ID2SYM(rb_intern(key_as_cstr))))
 | 
			
		||||
 | 
			
		||||
#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -264,7 +264,7 @@ CVMETHOD(const char *name, VALUE method, int ifnone = 0)
 | 
			
		|||
  case T_STRING:
 | 
			
		||||
    method = rb_str_intern(method);
 | 
			
		||||
  case T_SYMBOL:
 | 
			
		||||
    value = rb_hash_aref(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
 | 
			
		||||
    value = rb_hash_lookup(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
 | 
			
		||||
    return NIL_P(value) ? ifnone : FIX2INT(value);
 | 
			
		||||
  default:
 | 
			
		||||
    raise_typeerror(method, rb_cSymbol);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -143,5 +143,24 @@ class OpenCVTestCase < Test::Unit::TestCase
 | 
			
		|||
    }
 | 
			
		||||
    puts s.join("\n")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def count_threshold(mat, threshold, &block)
 | 
			
		||||
    n = 0
 | 
			
		||||
    block = lambda { |a, b| a > b } unless block_given?
 | 
			
		||||
    (mat.rows * mat.cols).times { |i|
 | 
			
		||||
      n += 1 if block.call(mat[i][0], threshold)
 | 
			
		||||
    }
 | 
			
		||||
    n
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def color_hists(mat)
 | 
			
		||||
    hists = [0] * mat.channel
 | 
			
		||||
    (mat.rows * mat.cols).times { |i|
 | 
			
		||||
      hists.size.times { |c|
 | 
			
		||||
        hists[c] += mat[i][c]
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    hists
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -439,48 +439,77 @@ class TestCvMat < OpenCVTestCase
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  def test_get_rows
 | 
			
		||||
    m1 = create_cvmat(10, 20)
 | 
			
		||||
    m1 = create_cvmat(10, 20) { |j, i, c| CvScalar.new(c) }
 | 
			
		||||
 | 
			
		||||
    m2 = m1.get_rows(2)
 | 
			
		||||
    assert_equal(1, m2.height)
 | 
			
		||||
    assert_equal(m1.width, m2.width)
 | 
			
		||||
    m1.width.times { |i|
 | 
			
		||||
      assert_cvscalar_equal(m1[2, i], m2[i])
 | 
			
		||||
    row = 2
 | 
			
		||||
    m2 = m1.get_rows(row)
 | 
			
		||||
    assert_equal(1, m2.rows)
 | 
			
		||||
    assert_equal(m1.cols, m2.cols)
 | 
			
		||||
    m1.cols.times { |i|
 | 
			
		||||
      assert_cvscalar_equal(m1[row, i], m2[i])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m2, m3 = m1.get_rows(1, 2)
 | 
			
		||||
    [m2, m3].each { |m|
 | 
			
		||||
      assert_equal(1, m.height)
 | 
			
		||||
      assert_equal(m1.width, m.width)
 | 
			
		||||
    row1 = 3..7
 | 
			
		||||
    row2 = 2...8
 | 
			
		||||
    [row1, row2].each { |row|
 | 
			
		||||
      m3 = m1.get_rows(row)
 | 
			
		||||
      w = (row.exclude_end?) ? row.last - row.begin : row.last - row.begin + 1
 | 
			
		||||
      assert_equal(w, m3.rows)
 | 
			
		||||
      assert_equal(m1.cols, m3.cols)
 | 
			
		||||
 | 
			
		||||
      m3.rows.times { |j|
 | 
			
		||||
        m3.cols.times { |i|
 | 
			
		||||
          assert_cvscalar_equal(m1[row.begin + j, i], m3[j, i])
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [row1, row2].each { |row|
 | 
			
		||||
      delta = 2
 | 
			
		||||
      m3 = m1.get_rows(row, 2)
 | 
			
		||||
      w = (((row.exclude_end?) ? row.last - row.begin : row.last - row.begin + 1).to_f / delta).ceil
 | 
			
		||||
      assert_equal(w, m3.rows)
 | 
			
		||||
      assert_equal(m1.cols, m3.cols)
 | 
			
		||||
 | 
			
		||||
      m3.rows.times { |j|
 | 
			
		||||
        m3.cols.times { |i|
 | 
			
		||||
          assert_cvscalar_equal(m1[row.begin + j * delta, i], m3[j, i])
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    m1.width.times { |i|
 | 
			
		||||
      assert_cvscalar_equal(m1[1, i], m2[i])
 | 
			
		||||
      assert_cvscalar_equal(m1[2, i], m3[i])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      m1.get_rows(DUMMY_OBJ)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      m1.get_rows(1, DUMMY_OBJ)
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_get_cols
 | 
			
		||||
    m1 = create_cvmat(10, 20)
 | 
			
		||||
    m1 = create_cvmat(10, 20) { |j, i, c| CvScalar.new(c) }
 | 
			
		||||
 | 
			
		||||
    m2 = m1.get_cols(2)
 | 
			
		||||
    assert_equal(1, m2.width)
 | 
			
		||||
    assert_equal(m1.height, m2.height)
 | 
			
		||||
    col = 2
 | 
			
		||||
    m2 = m1.get_cols(col)
 | 
			
		||||
    assert_equal(m1.rows, m2.rows)
 | 
			
		||||
    assert_equal(1, m2.cols)
 | 
			
		||||
    m1.height.times { |j|
 | 
			
		||||
      assert_cvscalar_equal(m1[j, 2], m2[j])
 | 
			
		||||
      assert_cvscalar_equal(m1[j, col], m2[j])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m2, m3 = m1.get_cols(1, 2)
 | 
			
		||||
    [m2, m3].each { |m|
 | 
			
		||||
      assert_equal(1, m.width)
 | 
			
		||||
      assert_equal(m1.height, m.height)
 | 
			
		||||
    col1 = 3..7
 | 
			
		||||
    col2 = 2...8
 | 
			
		||||
    [col1, col2].each { |col|
 | 
			
		||||
      m3 = m1.get_cols(col)
 | 
			
		||||
      w = (col.exclude_end?) ? col.last - col.begin : col.last - col.begin + 1
 | 
			
		||||
      assert_equal(m1.rows, m3.rows)
 | 
			
		||||
      assert_equal(w, m3.cols)
 | 
			
		||||
 | 
			
		||||
      m3.rows.times { |j|
 | 
			
		||||
        m3.cols.times { |i|
 | 
			
		||||
          assert_cvscalar_equal(m1[j, col.begin + i], m3[j, i])
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    m1.height.times { |j|
 | 
			
		||||
      assert_cvscalar_equal(m1[j, 1], m2[j])
 | 
			
		||||
      assert_cvscalar_equal(m1[j, 2], m3[j])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -115,9 +115,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    mat2 = mat0.pre_corner_detect(3)
 | 
			
		||||
    mat3 = mat0.pre_corner_detect(5)
 | 
			
		||||
 | 
			
		||||
    assert_equal('1ec909dfa2e497c7f454e39aefd764f5', hash_img(mat1))
 | 
			
		||||
    assert_equal('1ec909dfa2e497c7f454e39aefd764f5', hash_img(mat2))
 | 
			
		||||
    assert_equal('42e7443ffd389d15343d3c6bdc42f553', hash_img(mat3))
 | 
			
		||||
    assert_in_delta(0, count_threshold(mat1, 0.1), 30)
 | 
			
		||||
    assert_in_delta(0, count_threshold(mat2, 0.1), 30)
 | 
			
		||||
    assert_in_delta(380, count_threshold(mat3, 0.1), 30)
 | 
			
		||||
 | 
			
		||||
    # Uncomment the following lines to show the images
 | 
			
		||||
    # snap(['original', mat0], ['pre_coner_detect', mat1],
 | 
			
		||||
| 
						 | 
				
			
			@ -165,10 +165,14 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    mat3 = mat0.corner_harris(3, 3, 0.04)
 | 
			
		||||
    mat4 = mat0.corner_harris(3, 7, 0.01)
 | 
			
		||||
 | 
			
		||||
    assert_equal('fbb4e04c86f906c83fe17fd148675f90', hash_img(mat1))
 | 
			
		||||
    assert_equal('fbb4e04c86f906c83fe17fd148675f90', hash_img(mat2))
 | 
			
		||||
    assert_equal('fbb4e04c86f906c83fe17fd148675f90', hash_img(mat3))
 | 
			
		||||
    assert_equal('6515d75f6223806f077cebc7b3927a13', hash_img(mat4))
 | 
			
		||||
    [mat1, mat2, mat3].each { |mat|
 | 
			
		||||
      assert_equal(mat0.rows, mat.rows)
 | 
			
		||||
      assert_equal(mat0.cols, mat.cols)
 | 
			
		||||
      assert_in_delta(0, count_threshold(mat, 10), 10)
 | 
			
		||||
    }
 | 
			
		||||
    assert_equal(mat0.rows, mat4.rows)
 | 
			
		||||
    assert_equal(mat0.cols, mat4.cols)
 | 
			
		||||
    assert_in_delta(90, count_threshold(mat4, 10), 10)
 | 
			
		||||
 | 
			
		||||
    # Uncomment the following lines to show the images
 | 
			
		||||
    # snap(['original', mat0], ['corner_harris(3)', mat1], ['corner_harris(3,3)', mat2],
 | 
			
		||||
| 
						 | 
				
			
			@ -558,14 +562,26 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    mat0 = CvMat.load(FILENAME_FRUITS, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
 | 
			
		||||
    mat1 = mat0.log_polar(CvSize.new(255, 255), CvPoint2D32f.new(mat0.width / 2, mat0.height / 2), 40)
 | 
			
		||||
    assert_equal('d0425614b2f6e63ab2b6ef6637b4efcb', hash_img(mat1))
 | 
			
		||||
    mat1 = mat0.log_polar(CvSize.new(255, 255), CvPoint2D32f.new(mat0.width / 2, mat0.height / 2), 40,
 | 
			
		||||
    mat2 = mat0.log_polar(CvSize.new(255, 255), CvPoint2D32f.new(mat0.width / 2, mat0.height / 2), 40,
 | 
			
		||||
                          CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS)
 | 
			
		||||
    assert_equal('d0425614b2f6e63ab2b6ef6637b4efcb', hash_img(mat1))
 | 
			
		||||
    
 | 
			
		||||
    mat2 = mat1.log_polar(mat0.size, CvPoint2D32f.new(mat0.width / 2, mat0.height / 2), 40,
 | 
			
		||||
    mat3 = mat1.log_polar(mat0.size, CvPoint2D32f.new(mat0.width / 2, mat0.height / 2), 40,
 | 
			
		||||
                          CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS | CV_WARP_INVERSE_MAP)
 | 
			
		||||
    assert_equal('52587e593fec1b0383731be53147e8cd', hash_img(mat2))
 | 
			
		||||
 | 
			
		||||
    [mat1, mat2].each { |mat|
 | 
			
		||||
      assert_equal(mat0.depth, mat.depth)
 | 
			
		||||
      assert_equal(mat0.channel, mat.channel)
 | 
			
		||||
      b, g, r =  color_hists(mat)
 | 
			
		||||
      assert_in_delta(4000000, b, 100000)
 | 
			
		||||
      assert_in_delta(5860000, g, 100000)
 | 
			
		||||
      assert_in_delta(7700000, r, 100000)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    b, g, r =  color_hists(mat3)
 | 
			
		||||
    assert_equal(mat0.depth, mat3.depth)
 | 
			
		||||
    assert_equal(mat0.channel, mat3.channel)
 | 
			
		||||
    assert_in_delta(11200000, b, 1000000)
 | 
			
		||||
    assert_in_delta(20800000, g, 1000000)
 | 
			
		||||
    assert_in_delta(26900000, r, 1000000)
 | 
			
		||||
 | 
			
		||||
    # Uncomment the following line to show the results
 | 
			
		||||
    # snap mat0, mat1, mat2
 | 
			
		||||
| 
						 | 
				
			
			@ -1134,8 +1150,18 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    mat1 = mat0.pyr_up
 | 
			
		||||
    mat2 = mat0.pyr_up(:gaussian_5x5)
 | 
			
		||||
 | 
			
		||||
    assert_equal('02430c6cf143d3d104e25bc829f1fa93', hash_img(mat1))
 | 
			
		||||
    assert_equal('02430c6cf143d3d104e25bc829f1fa93', hash_img(mat2))
 | 
			
		||||
    [mat1, mat2].each { |mat|
 | 
			
		||||
      assert_equal(mat0.cols * 2, mat.cols)
 | 
			
		||||
      assert_equal(mat0.rows * 2, mat.rows)
 | 
			
		||||
      assert_equal(mat0.depth, mat.depth)
 | 
			
		||||
      assert_equal(mat0.channel, mat.channel)
 | 
			
		||||
      b, g, r = color_hists(mat)
 | 
			
		||||
      assert_in_delta(27500000, b, 1000000)
 | 
			
		||||
      assert_in_delta(26000000, g, 1000000)
 | 
			
		||||
      assert_in_delta(47000000, r, 1000000)
 | 
			
		||||
    }
 | 
			
		||||
    # Uncomment the following lines to show the result
 | 
			
		||||
    # snap mat0, mat1, mat2
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      mat0.pyr_up(DUMMY_OBJ)
 | 
			
		||||
| 
						 | 
				
			
			@ -1316,53 +1342,18 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pyr_segmentation
 | 
			
		||||
    mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
    mat1, seq1 = mat0.pyr_segmentation(4, 255, 50)
 | 
			
		||||
    assert_equal('ebd9bad0bbc90b1d4a25289b7d59c958', hash_img(mat1))
 | 
			
		||||
    assert_equal(5, seq1.total)
 | 
			
		||||
 | 
			
		||||
    img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
    img0.set_roi(CvRect.new(0, 0, 256, 512))
 | 
			
		||||
    img2, seq2 = img0.pyr_segmentation(2, 255, 50)
 | 
			
		||||
    assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img2))
 | 
			
		||||
    assert_equal(11, seq2.total)
 | 
			
		||||
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(-1, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(1000, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(4, -1, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(4, 255, -1)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(DUMMY_OBJ, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(4, DUMMY_OBJ, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(4, 255, DUMMY_OBJ)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvBadDepth) {
 | 
			
		||||
      IplImage.new(10, 10, :cv32f, 2).pyr_segmentation(4, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pyr_mean_shift_filtering
 | 
			
		||||
    mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
    mat1 = mat0.pyr_mean_shift_filtering(30, 30)
 | 
			
		||||
    mat2 = mat0.pyr_mean_shift_filtering(30, 30, 2)
 | 
			
		||||
    mat3 = mat0.pyr_mean_shift_filtering(30, 30, nil, CvTermCriteria.new(3, 0.01))
 | 
			
		||||
 | 
			
		||||
    assert_equal('6887e96bc5dfd552f76ac5411b394775', hash_img(mat1))
 | 
			
		||||
    assert_equal('3cd9c4983fcabeafa04be200d5e08841', hash_img(mat2))
 | 
			
		||||
    assert_equal('e37f0157f93fe2a98312ae6b768e8295', hash_img(mat3))
 | 
			
		||||
    [mat1, mat2, mat3].each { |mat|
 | 
			
		||||
      b, g, r = color_hists(mat)
 | 
			
		||||
      assert_in_delta(6900000, b, 100000)
 | 
			
		||||
      assert_in_delta(6500000, g, 100000)
 | 
			
		||||
      assert_in_delta(11800000, r, 100000)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      mat0.pyr_mean_shift_filtering(DUMMY_OBJ, 30)
 | 
			
		||||
| 
						 | 
				
			
			@ -1405,9 +1396,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    moments2 = mat.moments(false)
 | 
			
		||||
    moments3 = mat.moments(true)
 | 
			
		||||
 | 
			
		||||
    [moments1, moments2].each { |moments|
 | 
			
		||||
      assert_equal(1, moments.size)
 | 
			
		||||
      m = moments[0]
 | 
			
		||||
    [moments1, moments2].each { |m|
 | 
			
		||||
      assert_in_delta(2221056, m.spatial(0, 0), 0.1)
 | 
			
		||||
      assert_in_delta(2221056, m.central(0, 0), 0.1)
 | 
			
		||||
      assert_in_delta(1, m.normalized_central(0, 0), 0.1)
 | 
			
		||||
| 
						 | 
				
			
			@ -1446,9 +1435,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
      assert_in_delta(0.000671, m.inv_sqrt_m00, 0.000001)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert_equal(1, moments3.size)
 | 
			
		||||
    m = moments3[0]
 | 
			
		||||
 | 
			
		||||
    m = moments3
 | 
			
		||||
    assert_in_delta(10240, m.spatial(0, 0), 0.1)
 | 
			
		||||
    assert_in_delta(10240, m.central(0, 0), 0.1)
 | 
			
		||||
    assert_in_delta(1, m.normalized_central(0, 0), 0.1)
 | 
			
		||||
| 
						 | 
				
			
			@ -1594,11 +1581,11 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
 | 
			
		||||
    [CV_INPAINT_NS, :ns].each { |method|
 | 
			
		||||
      result_ns = mat.inpaint(method, mask, 10)
 | 
			
		||||
      assert_equal('d3df4dda8642c83512fb417ffa5e1457', hash_img(result_ns))
 | 
			
		||||
      assert_in_delta(14000, count_threshold(result_ns, 128), 1000)
 | 
			
		||||
    }
 | 
			
		||||
    [CV_INPAINT_TELEA, :telea].each { |method|
 | 
			
		||||
      result_telea = mat.inpaint(method, mask, 10)
 | 
			
		||||
      assert_equal('d45bec22d03067578703f2ec68567167', hash_img(result_telea))
 | 
			
		||||
      assert_in_delta(13500, count_threshold(result_telea, 128), 1000)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # Uncomment the following lines to show the results
 | 
			
		||||
| 
						 | 
				
			
			@ -1640,42 +1627,58 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    mat = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
    templ = CvMat.load(FILENAME_LENA_EYES, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
 | 
			
		||||
    expected_pt = CvPoint.new(100, 120)
 | 
			
		||||
 | 
			
		||||
    # sqdiff
 | 
			
		||||
    result = mat.match_template(templ)
 | 
			
		||||
    assert_equal('88663ec44be797ca883fc87bb6d7c09b', hash_img(result))
 | 
			
		||||
    pt = result.min_max_loc[2]
 | 
			
		||||
    assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
    assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
 | 
			
		||||
    [CV_TM_SQDIFF, :sqdiff].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('88663ec44be797ca883fc87bb6d7c09b', hash_img(result))
 | 
			
		||||
      assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
      assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # sqdiff_normed
 | 
			
		||||
    [CV_TM_SQDIFF_NORMED, :sqdiff_normed].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('75c812f87184b2ccd8f83b70a8436356', hash_img(result))
 | 
			
		||||
      pt =  result.min_max_loc[2]
 | 
			
		||||
      assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
      assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # ccorr
 | 
			
		||||
    [CV_TM_CCORR, :ccorr].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('6ebe7e48edf8fc64bcc0fd7f1e96555c', hash_img(result))
 | 
			
		||||
      pt =  result.min_max_loc[3]
 | 
			
		||||
      assert_in_delta(110, pt.x, 20)
 | 
			
		||||
      assert_in_delta(60, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # ccorr_normed
 | 
			
		||||
    [CV_TM_CCORR_NORMED, :ccorr_normed].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('4cf8ebcec870f8295d615a9aa345ae4d', hash_img(result))
 | 
			
		||||
      pt =  result.min_max_loc[3]
 | 
			
		||||
      assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
      assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # ccoeff
 | 
			
		||||
    [CV_TM_CCOEFF, :ccoeff].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('248a391c5a1e1dbcf7a19f3310b5cd7a', hash_img(result))
 | 
			
		||||
      pt =  result.min_max_loc[3]
 | 
			
		||||
      assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
      assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    # ccoeff_normed
 | 
			
		||||
    [CV_TM_CCOEFF_NORMED, :ccoeff_normed].each { |method|
 | 
			
		||||
      result = mat.match_template(templ, method)
 | 
			
		||||
      assert_equal('27a4e9b45ed648848f0498356bd2c5b5', hash_img(result))
 | 
			
		||||
      pt =  result.min_max_loc[3]
 | 
			
		||||
      assert_in_delta(expected_pt.x, pt.x, 20)
 | 
			
		||||
      assert_in_delta(expected_pt.y, pt.y, 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # Uncomment the following lines to show the result
 | 
			
		||||
| 
						 | 
				
			
			@ -1685,7 +1688,6 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    # mat.rectangle!(pt1, pt2, :color => CvColor::Black, :thickness => 3)
 | 
			
		||||
    # snap mat, templ, result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      mat.match_template(DUMMY_OBJ)
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1836,30 +1838,30 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
 | 
			
		||||
    [curr.optical_flow_hs(prev, nil, nil, :lambda => 0.0005, :criteria => CvTermCriteria.new(1, 0.001)),
 | 
			
		||||
     curr.optical_flow_hs(prev)].each { |velx, vely|
 | 
			
		||||
      assert_equal('d437cd896365c509b5d16fd5f2d7e498', hash_img(velx))
 | 
			
		||||
      assert_equal('36ccbcafcd58b4d07dab058fb60eede6', hash_img(vely))
 | 
			
		||||
      assert_in_delta(60, count_threshold(velx, 1), 20)
 | 
			
		||||
      assert_in_delta(50, count_threshold(vely, 1), 20)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_hs(prev, nil, nil, :lambda => 0.001)
 | 
			
		||||
    assert_equal('6a0133bcfa5057ef3d607429753d1f27', hash_img(velx))
 | 
			
		||||
    assert_equal('dffbc0e267b08f3ca0098f27ecf61f6e', hash_img(vely))
 | 
			
		||||
    assert_in_delta(60, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(50, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_hs(prev, nil, nil, :criteria => CvTermCriteria.new(10, 0.01))
 | 
			
		||||
    assert_equal('5dc2bb2aaee70383da8b12c99cbf388b', hash_img(velx))
 | 
			
		||||
    assert_equal('b53cec7a363ba7491cde61540813b827', hash_img(vely))
 | 
			
		||||
    assert_in_delta(130, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(110, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    prev_velx, prev_vely = curr.optical_flow_hs(prev)
 | 
			
		||||
    velx, vely = curr.optical_flow_hs(prev, prev_velx, prev_vely)
 | 
			
		||||
    assert_equal('08b50f3d4cb4cbbe443fada293e6af02', hash_img(velx))
 | 
			
		||||
    assert_equal('4d302c8267388995ec85a4a26da5ffcc', hash_img(vely))
 | 
			
		||||
    assert_in_delta(70, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(60, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_hs(prev, prev_velx, prev_vely, :lambda => 0.001)
 | 
			
		||||
    assert_equal('8bb08ee394719a70e24bfb8b428662cd', hash_img(velx))
 | 
			
		||||
    assert_equal('f6c09e73160f0792e4527cdeea0e5573', hash_img(vely))
 | 
			
		||||
    assert_in_delta(80, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(70, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_hs(prev, prev_velx, prev_vely, :criteria => CvTermCriteria.new(10, 0.01))
 | 
			
		||||
    assert_equal('c32a8483e3aec3cd6c33bceeefb8d2f2', hash_img(velx))
 | 
			
		||||
    assert_equal('da33e266aece70ed69dcf074acd8fd4e', hash_img(vely))
 | 
			
		||||
    assert_in_delta(150, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(130, count_threshold(vely, 1), 20)
 | 
			
		||||
    
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      curr.optical_flow_hs(DUMMY_OBJ)
 | 
			
		||||
| 
						 | 
				
			
			@ -1896,12 +1898,12 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    }
 | 
			
		||||
    
 | 
			
		||||
    velx, vely = curr.optical_flow_lk(prev, CvSize.new(3, 3))
 | 
			
		||||
    assert_equal('13333362f0daf6ad732006bd2a32e177', hash_img(velx))
 | 
			
		||||
    assert_equal('45dc42034ab606dd61e34a5adc6a1c1b', hash_img(vely))
 | 
			
		||||
    assert_in_delta(100, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(90, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_lk(prev, CvSize.new(5, 5))
 | 
			
		||||
    assert_equal('d83c57805f9c074d0ad33a7522a75952', hash_img(velx))
 | 
			
		||||
    assert_equal('df8fb2010b00d89090e7d9653781a68d', hash_img(vely))
 | 
			
		||||
    assert_in_delta(180, count_threshold(velx, 1), 20)
 | 
			
		||||
    assert_in_delta(150, count_threshold(vely, 1), 20)
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      curr.optical_flow_lk(DUMMY_OBJ, CvSize.new(3, 3))
 | 
			
		||||
| 
						 | 
				
			
			@ -1934,26 +1936,26 @@ class TestCvMat_imageprocessing < OpenCVTestCase
 | 
			
		|||
    [curr.optical_flow_bm(prev, nil, nil, :block_size => CvSize.new(4, 4),
 | 
			
		||||
                          :shift_size => CvSize.new(1, 1), :max_range => CvSize.new(4, 4)),
 | 
			
		||||
     curr.optical_flow_bm(prev)].each { |velx, vely|
 | 
			
		||||
      assert_equal('08e73a6fa9af7684a5eddc4f30fd46e7', hash_img(velx))
 | 
			
		||||
      assert_equal('aabaf1b7393b950c2297f567b6f57d5d', hash_img(vely))
 | 
			
		||||
      assert_in_delta(350, count_threshold(velx, 1), 30)
 | 
			
		||||
      assert_in_delta(250, count_threshold(vely, 1), 30)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_bm(prev, nil, nil, :block_size => CvSize.new(3, 3))
 | 
			
		||||
    assert_equal('fe540dc1f0aec2d70b774286eafa3602', hash_img(velx))
 | 
			
		||||
    assert_equal('c7cc0f055fe4708396ba6046c0f1c6b5', hash_img(vely))
 | 
			
		||||
    assert_in_delta(280, count_threshold(velx, 1), 30)
 | 
			
		||||
    assert_in_delta(200, count_threshold(vely, 1), 30)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_bm(prev, nil, nil, :shift_size => CvSize.new(2, 2))
 | 
			
		||||
    assert_equal('00ad7854afb6eb4e46f0fb31c312c5eb', hash_img(velx))
 | 
			
		||||
    assert_equal('33215ec0bfa7f6b1424d6fadb2a48e0f', hash_img(vely))
 | 
			
		||||
    assert_in_delta(80, count_threshold(velx, 1), 30)
 | 
			
		||||
    assert_in_delta(60, count_threshold(vely, 1), 30)
 | 
			
		||||
 | 
			
		||||
    velx, vely = curr.optical_flow_bm(prev, nil, nil, :max_range => CvSize.new(5, 5))
 | 
			
		||||
    assert_equal('ac10837eeee45fd80a24695cfaf9cfc7', hash_img(velx))
 | 
			
		||||
    assert_equal('8c7011c26ac53eaf1fae1aa9324e5979', hash_img(vely))
 | 
			
		||||
    assert_in_delta(400, count_threshold(velx, 1), 30)
 | 
			
		||||
    assert_in_delta(300, count_threshold(vely, 1), 30)
 | 
			
		||||
    
 | 
			
		||||
    prev_velx, prev_vely = curr.optical_flow_bm(prev)
 | 
			
		||||
    velx, vely = curr.optical_flow_bm(prev, prev_velx, prev_vely)
 | 
			
		||||
    assert_equal('6ad6b7a5c935379c0df4b9ec5666f3de', hash_img(velx))
 | 
			
		||||
    assert_equal('b317b0b9d4fdb0e5cd40beb0dd4143b4', hash_img(vely))
 | 
			
		||||
    assert_in_delta(350, count_threshold(velx, 1), 30)
 | 
			
		||||
    assert_in_delta(270, count_threshold(vely, 1), 30)
 | 
			
		||||
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      curr.optical_flow_bm(DUMMY_OBJ)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -198,6 +198,39 @@ class TestIplImage < OpenCVTestCase
 | 
			
		|||
      should_classify_images_as image, :blank
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pyr_segmentation
 | 
			
		||||
    img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
 | 
			
		||||
    img0.set_roi(CvRect.new(0, 0, 256, 512))
 | 
			
		||||
    img1, seq1 = img0.pyr_segmentation(2, 255, 50)
 | 
			
		||||
    assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img1))
 | 
			
		||||
    assert_equal(11, seq1.total)
 | 
			
		||||
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(-1, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(1000, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(4, -1, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvStsAssert) {
 | 
			
		||||
      img0.pyr_segmentation(4, 255, -1)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(DUMMY_OBJ, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(4, DUMMY_OBJ, 50)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(TypeError) {
 | 
			
		||||
      img0.pyr_segmentation(4, 255, DUMMY_OBJ)
 | 
			
		||||
    }
 | 
			
		||||
    assert_raise(CvBadDepth) {
 | 
			
		||||
      IplImage.new(10, 10, :cv32f, 2).pyr_segmentation(4, 255, 50)
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue