Class: Cv::Mat

Inherits:
Object
  • Object
show all
Defined in:
lib/opencv-ruby/core/mat.rb

Instance Method Summary collapse

Instance Method Details

#absdiff(other) ⇒ Object



299
300
301
302
303
# File 'lib/opencv-ruby/core/mat.rb', line 299

def absdiff(other)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::absdiff(self.input_array, other.input_array, dest.output_array)
  dest
end

#adaptive_threshold(max_value, adaptive_method, threshold_type, block_size, c) ⇒ Object



305
306
307
308
309
# File 'lib/opencv-ruby/core/mat.rb', line 305

def adaptive_threshold(max_value, adaptive_method, threshold_type, block_size, c)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::adaptive_threshold(self.input_array, dest.output_array, max_value, adaptive_method, threshold_type, block_size, c)
  dest
end

#apply_color_map(colormap) ⇒ Object



311
312
313
314
315
# File 'lib/opencv-ruby/core/mat.rb', line 311

def apply_color_map(colormap)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::apply_color_map(self.input_array, dest.output_array, colormap)
  dest
end

#bilateral_filter(d, sigma_color, sigma_space, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



317
318
319
320
321
# File 'lib/opencv-ruby/core/mat.rb', line 317

def bilateral_filter(d, sigma_color, sigma_space, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::bilateral_filter(self.input_array, dest.output_array, d, sigma_color, sigma_space, border_type)
  dest
end

#bitwise_and(other, mask: nil) ⇒ Object



275
276
277
278
279
# File 'lib/opencv-ruby/core/mat.rb', line 275

def bitwise_and(other, mask: nil)
  dest = self.clone
  Cv::bitwise_and(self.input_array, other.input_array, dest.output_array, mask&.input_array)
  dest
end

#bitwise_not(mask: nil) ⇒ Object



293
294
295
296
297
# File 'lib/opencv-ruby/core/mat.rb', line 293

def bitwise_not(mask: nil)
  dest = self.clone
  Cv::bitwise_not(self.input_array, dest.output_array, mask&.input_array)
  dest
end

#bitwise_or(other, mask: nil) ⇒ Object



281
282
283
284
285
# File 'lib/opencv-ruby/core/mat.rb', line 281

def bitwise_or(other, mask: nil)
  dest = self.clone
  Cv::bitwise_or(self.input_array, other.input_array, dest.output_array, mask&.input_array)
  dest
end

#bitwise_xor(other, mask: nil) ⇒ Object



287
288
289
290
291
# File 'lib/opencv-ruby/core/mat.rb', line 287

def bitwise_xor(other, mask: nil)
  dest = self.clone
  Cv::bitwise_xor(self.input_array, other.input_array, dest.output_array, mask&.input_array)
  dest
end

#blur(ksize, anchor: Cv::Point.new(-1,-1), border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



323
324
325
326
327
# File 'lib/opencv-ruby/core/mat.rb', line 323

def blur(ksize, anchor: Cv::Point.new(-1,-1), border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::blur(self.input_array, dest.output_array, ksize, anchor, border_type)
  dest
end

#circle(center, radius, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object

Drawing functions



668
669
670
671
# File 'lib/opencv-ruby/core/mat.rb', line 668

def circle(center, radius, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0)
  Cv::circle(self.input_output_array, center, radius, color, thickness, line_type, shift)
  self
end

#compare(other, operation) ⇒ Object

Provide more Ruby like API to OpenCV



221
222
223
224
225
# File 'lib/opencv-ruby/core/mat.rb', line 221

def compare(other, operation)
    dest = self.class.new(self.rows, self.cols, self.type)
    Cv::compare(self.input_array, other.input_array, dest.output_array, operation)
  dest
end

#convert_scale_abs(alpha: 1, beta: 0) ⇒ Object



329
330
331
332
333
# File 'lib/opencv-ruby/core/mat.rb', line 329

def convert_scale_abs(alpha: 1, beta: 0)
  dest = self.class.new
  Cv::convert_scale_abs(self.input_array, dest.output_array, alpha, beta)
  dest
end

#convert_to(type, alpha, double, beta = 0) ⇒ Object



336
337
338
339
340
# File 'lib/opencv-ruby/core/mat.rb', line 336

def convert_to(type, alpha, double, beta = 0)
  dest = self.class.new(self.rows, self.cols, self.type)
  self.convert_to_cpp(dest.output_array, alpha, double, beta)
  dest
end

#convert_to_cppObject



335
# File 'lib/opencv-ruby/core/mat.rb', line 335

alias :convert_to_cpp :convert_to

#copy_make_border(top, bottom, left, right, border_type, value: Cv::Scalar.new) ⇒ Object



342
343
344
345
346
# File 'lib/opencv-ruby/core/mat.rb', line 342

def copy_make_border(top, bottom, left, right, border_type, value: Cv::Scalar.new)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::copy_make_border(self.input_array, dest.output_array, top, bottom, left, right, border_type, value)
  dest
end

#corner_eigen_vals_and_vecs(block_size, ksize, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



348
349
350
351
352
# File 'lib/opencv-ruby/core/mat.rb', line 348

def corner_eigen_vals_and_vecs(block_size, ksize, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = Cv::Mat6f.new(self.rows, self.cols)
  Cv::corner_eigen_vals_and_vecs(self.input_array, dest.output_array, block_size, ksize, border_type)
  dest
end

#corner_harris(block_size, ksize, k, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



354
355
356
357
358
# File 'lib/opencv-ruby/core/mat.rb', line 354

def corner_harris(block_size, ksize, k, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = Cv::Mat1f.new(self.rows, self.cols)
  Cv::corner_harris(self.input_array, dest.output_array, block_size, ksize, k, border_type)
  dest
end

#corner_min_eigen_val(block_size, ksize: 3, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



360
361
362
363
364
# File 'lib/opencv-ruby/core/mat.rb', line 360

def corner_min_eigen_val(block_size, ksize: 3, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = Cv::Mat1f.new(self.rows, self.cols)
  Cv::corner_min_eigen_val(self.input_array, dest.output_array, block_size, ksize, border_type)
  dest
end

#corner_sub_pix(corners, win_size, zero_zone, criteria) ⇒ Object



366
367
368
369
# File 'lib/opencv-ruby/core/mat.rb', line 366

def corner_sub_pix(corners, win_size, zero_zone, criteria)
  Cv::corner_sub_pix(self.input_array, corners.input_output_array, win_size, zero_zone, criteria)
  corners
end

#count_non_zeroObject



371
372
373
# File 'lib/opencv-ruby/core/mat.rb', line 371

def count_non_zero
  Cv.count_non_zero(self.input_array)
end

#cvt_color(color_conversion_code, dst_cn: 0, hint: Cv::AlgorithmHint::ALGO_HINT_DEFAULT) ⇒ Object



375
376
377
378
379
# File 'lib/opencv-ruby/core/mat.rb', line 375

def cvt_color(color_conversion_code, dst_cn: 0, hint: Cv::AlgorithmHint::ALGO_HINT_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::cvt_color(self.input_array, dest.output_array, color_conversion_code, dst_cn, hint)
  dest
end

#determinantObject



381
382
383
# File 'lib/opencv-ruby/core/mat.rb', line 381

def determinant
  Cv.determinant(self.input_array)
end

#dilate(kernel, anchor = Cv::Point.new(-1,-1), iterations = 1, border_type = Cv::BorderTypes::BORDER_CONSTANT, border_value = Cv::morphology_default_border_value) ⇒ Object



385
386
387
388
389
390
# File 'lib/opencv-ruby/core/mat.rb', line 385

def dilate(kernel, anchor = Cv::Point.new(-1,-1), iterations = 1,
           border_type = Cv::BorderTypes::BORDER_CONSTANT, border_value = Cv::morphology_default_border_value)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::dilate(self.input_array, dest.output_array, kernel.input_array, anchor, iterations, border_type, border_value)
  dest
end

#draw_chessboard_corners(pattern_size, corners, pattern_was_found) ⇒ Object



392
393
394
395
# File 'lib/opencv-ruby/core/mat.rb', line 392

def draw_chessboard_corners(pattern_size, corners, pattern_was_found)
  Cv.draw_chessboard_corners(self.input_output_array, pattern_size, corners, pattern_was_found)
  self
end

#draw_contours(contours, contour_idx, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, hierarchy: Cv::no_array, max_level: INT_MAX, offset: Cv::Point.new) ⇒ Object



397
398
399
400
401
402
403
# File 'lib/opencv-ruby/core/mat.rb', line 397

def draw_contours(contours, contour_idx, color, thickness: 1, line_type: Cv::LineTypes::LINE_8,
                  hierarchy: Cv::no_array, max_level: INT_MAX, offset: Cv::Point.new)
  contours_input = Cv::InputArray.new(contours)
  hierarchy_input = Cv::InputArray.new(hierarchy)
  Cv.draw_contours(self.input_output_array, contours_input, contour_idx, color, thickness, line_type,
                   hierarchy_input, max_level, offset)
end

#eigenObject



405
406
407
408
409
410
# File 'lib/opencv-ruby/core/mat.rb', line 405

def eigen
  eigen_values = self.class.new
  eigen_vectors = self.class.new(self.cols, self.rows, self.type)
  Cv.eigen(self.input_array, eigen_values.output_array, eigen_vectors.output_array)
  [eigen_values, eigen_vectors]
end

#ellipse(center, axes, angle, start_angle, end_angle, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object



673
674
675
676
677
678
# File 'lib/opencv-ruby/core/mat.rb', line 673

def ellipse(center, axes, angle, start_angle, end_angle,
            color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0)
  Cv::ellipse(self.input_output_array, center, axes, angle, start_angle, end_angle,
              color, thickness, line_type, shift)
  self
end

#ellipse_box(box, color, thickness: 1, line_type: Cv::LineTypes::LINE_8) ⇒ Object



680
681
682
683
# File 'lib/opencv-ruby/core/mat.rb', line 680

def ellipse_box(box, color, thickness: 1, line_type: Cv::LineTypes::LINE_8)
  Cv::ellipse(self.input_output_array, box, color, thickness, line_type)
  self
end

#eq(other) ⇒ Object



251
252
253
# File 'lib/opencv-ruby/core/mat.rb', line 251

def eq(other)
  compare(other, Cv::CmpTypes::CMP_EQ)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/opencv-ruby/core/mat.rb', line 227

def eql?(other)
  return false if self.class != other.class
  return false if self.dims != other.dims
  return false if self.size != other.size
  return false if self.elem_size != other.elem_size
  return false if self.continuous? != other.continuous?

  # Ok compare contents. A Google search shows various ways to do this.
  # We will use the built in comparison operators.
  #
  # The Mat== operator compares element by element. If two elements meet the criteria,
  # in this case ==, then the returned value is 255 otherwise 0. See
  # https://docs.opencv.org/4.x/d1/d10/classcv_1_1MatExpr.html#details
  #
  # So if we check for inequality, then pixels that are the same would return 0 and ones
  # that are not the same would return 255. It is a lot easier to check the sum if it
  # adds up to zero, so we use inequality.
  # Also see https://stackoverflow.com/a/32440830

  expr = self != other
  result = expr.to_mat.sum
  result == Cv::Scalar.new(0, 0, 0, 0) ? true : false
end

#equalize_histObject



412
413
414
415
416
# File 'lib/opencv-ruby/core/mat.rb', line 412

def equalize_hist
  dest = self.class.new(self.cols, self.rows, self.type)
  Cv.equalize_hist(self.input_array, dest.output_array)
  dest
end

#erode(kernel, anchor: Cv::Point.new(-1,-1), iterations: 1, border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::morphology_default_border_value) ⇒ Object



418
419
420
421
422
423
# File 'lib/opencv-ruby/core/mat.rb', line 418

def erode(kernel, anchor: Cv::Point.new(-1,-1), iterations: 1,
          border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::morphology_default_border_value)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::erode(self.input_array, dest.output_array, kernel.input_array, anchor, iterations, border_type, border_value)
  dest
end

#fill_convex_poly(pts, color, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object



685
686
687
688
# File 'lib/opencv-ruby/core/mat.rb', line 685

def fill_convex_poly(pts, color, line_type: Cv::LineTypes::LINE_8, shift: 0)
  Cv::fill_convex_poly(self.input_output_array, pts, color, line_type, shift)
  self
end

#fill_poly(pts, color, line_type: Cv::LineTypes::LINE_8, shift: 0, offset: Cv::Point.new) ⇒ Object



690
691
692
693
# File 'lib/opencv-ruby/core/mat.rb', line 690

def fill_poly(pts, color, line_type: Cv::LineTypes::LINE_8, shift: 0, offset: Cv::Point.new)
  Cv::fill_poly(self.input_output_array, pts, color, line_type, shift, offset)
  self
end

#filter_2d(ddepth, kernel, anchor: Cv::Point.new(-1,-1), delta: 0, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



425
426
427
428
429
# File 'lib/opencv-ruby/core/mat.rb', line 425

def filter_2d(ddepth, kernel, anchor: Cv::Point.new(-1,-1), delta: 0, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::filter_2d(self.input_array, dest.output_array, ddepth, kernel.input_array, anchor, delta, border_type)
  dest
end

#find_chessboard_corners(pattern_size, flags: Cv::CALIB_CB_ADAPTIVE_THRESH | Cv::CALIB_CB_NORMALIZE_IMAGE) ⇒ Object



431
432
433
434
435
436
# File 'lib/opencv-ruby/core/mat.rb', line 431

def find_chessboard_corners(pattern_size, flags: Cv::CALIB_CB_ADAPTIVE_THRESH | Cv::CALIB_CB_NORMALIZE_IMAGE)
  mat = Cv::Mat2f.new
  corners = Cv::OutputArray.new(mat)
  found = Cv::find_chessboard_corners(self.input_array, pattern_size, corners, flags)
  [mat, found]
end

#find_contours(mode, method, offset: Cv::Point.new) ⇒ Object



438
439
440
441
442
443
444
445
446
447
# File 'lib/opencv-ruby/core/mat.rb', line 438

def find_contours(mode, method, offset: Cv::Point.new)
  contours = Std::Vector

#flip(flip_code) ⇒ Object



449
450
451
452
453
# File 'lib/opencv-ruby/core/mat.rb', line 449

def flip(flip_code)
  dest = self.class.new(self.cols, self.rows, self.type)
  Cv.flip(self.input_array, dest.output_array, flip_code)
  dest
end

#flood_fill(mask, seed_point, new_val, lo_diff: Cv::Scalar.new, up_diff: Cv::Scalar.new, connectivity: 4, fill_value: 1, fill_flags: 0) ⇒ Object



455
456
457
458
459
460
461
462
# File 'lib/opencv-ruby/core/mat.rb', line 455

def flood_fill(mask, seed_point, new_val, lo_diff: Cv::Scalar.new, up_diff: Cv::Scalar.new,
               connectivity: 4, fill_value: 1, fill_flags: 0)
  rect = Cv::Rect.new
  flags = connectivity | (fill_value << 8) | fill_flags
  area = Cv::flood_fill(self.input_output_array, mask.input_output_array, seed_point, new_val,
                       rect, lo_diff, up_diff, flags)
  [area, rect]
end

#gaussian_blur(ksize, sigma_x, sigma_y: 0, border_type: Cv::BorderTypes::BORDER_DEFAULT, hint: Cv::AlgorithmHint::ALGO_HINT_DEFAULT) ⇒ Object



464
465
466
467
468
# File 'lib/opencv-ruby/core/mat.rb', line 464

def gaussian_blur(ksize, sigma_x, sigma_y: 0, border_type: Cv::BorderTypes::BORDER_DEFAULT, hint: Cv::AlgorithmHint::ALGO_HINT_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::gaussian_blur(self.input_array, dest.output_array, ksize, sigma_x, sigma_y, border_type, hint)
  dest
end

#ge(other) ⇒ Object



259
260
261
# File 'lib/opencv-ruby/core/mat.rb', line 259

def ge(other)
  compare(other, Cv::CmpTypes::CMP_GE)
end

#get_rect_sub_pix(patch_size, center, patch_type: -1)) ⇒ Object



470
471
472
473
474
# File 'lib/opencv-ruby/core/mat.rb', line 470

def get_rect_sub_pix(patch_size, center, patch_type: -1)
  patch = Cv::Mat.new
  Cv::get_rect_sub_pix(self.input_array, patch_size, center, patch.output_array, patch_type)
  patch
end

#good_features_to_track(max_corners, quality_level, min_distance, mask: nil, block_size: 3, use_harris_detector: false, k: 0.04) ⇒ Object



476
477
478
479
480
481
482
# File 'lib/opencv-ruby/core/mat.rb', line 476

def good_features_to_track(max_corners, quality_level, min_distance,
                           mask: nil, block_size: 3, use_harris_detector: false, k: 0.04)
  corners = Cv::Mat.new
  Cv::good_features_to_track(self.input_array, corners.output_array, max_corners, quality_level, min_distance,
                             mask ? mask.input_array : Cv::no_array, block_size, use_harris_detector, k)
  corners
end

#gt(other) ⇒ Object



255
256
257
# File 'lib/opencv-ruby/core/mat.rb', line 255

def gt(other)
  compare(other, Cv::CmpTypes::CMP_GT)
end

#hough_circles(method, dp, min_dist, param1: 100, param2: 100, min_radius: 0, max_radius: 0) ⇒ Object



484
485
486
487
488
489
# File 'lib/opencv-ruby/core/mat.rb', line 484

def hough_circles(method, dp, min_dist, param1: 100, param2: 100, min_radius: 0, max_radius: 0)
  result = Std::Vector

#hough_lines(rho, theta, threshold, srn: 0, stn: 0, min_theta: 0, max_theta: CV_PI, use_edgeval: false) ⇒ Object



491
492
493
494
495
496
# File 'lib/opencv-ruby/core/mat.rb', line 491

def hough_lines(rho, theta, threshold, srn: 0, stn: 0, min_theta: 0, max_theta: CV_PI, use_edgeval: false)
  result = Std::Vector

#in_range(lowerb, upperb) ⇒ Object



504
505
506
507
508
# File 'lib/opencv-ruby/core/mat.rb', line 504

def in_range(lowerb, upperb)
  dest = self.class.new(self.rows, self.cols, CV_8UC1)
  Cv::in_range(self.input_array, lowerb.input_array, upperb.input_array, dest.output_array)
  dest
end

#inpaint(mask, inpaint_radius, flags) ⇒ Object



498
499
500
501
502
# File 'lib/opencv-ruby/core/mat.rb', line 498

def inpaint(mask, inpaint_radius, flags)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::inpaint(self.input_array, mask.input_array, dest.output_array, inpaint_radius, flags)
  dest
end

#integral(sdepth: -1,, sqdepth: -1)) ⇒ Object



510
511
512
513
514
515
516
517
# File 'lib/opencv-ruby/core/mat.rb', line 510

def integral(sdepth: -1, sqdepth: -1)
  sum = Cv::Mat.new
  sqsum = Cv::Mat.new
  tilted = Cv::Mat.new

  Cv::integral(self.input_array, sum.output_array, sqsum.output_array, tilted.output_array, sdepth, sqdepth)
  [sum, sqsum, tilted]
end

#invert(flags: Cv::DecompTypes::DECOMP_LU) ⇒ Object



519
520
521
522
523
# File 'lib/opencv-ruby/core/mat.rb', line 519

def invert(flags: Cv::DecompTypes::DECOMP_LU)
  dest = self.class.new(self.cols, self.rows, self.type)
  Cv.invert(self.input_array, dest.output_array, flags)
  dest
end

#le(other) ⇒ Object



267
268
269
# File 'lib/opencv-ruby/core/mat.rb', line 267

def le(other)
  compare(other, Cv::CmpTypes::CMP_LE)
end

#line(pt1, pt2, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object



695
696
697
698
# File 'lib/opencv-ruby/core/mat.rb', line 695

def line(pt1, pt2, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0)
  Cv::line(self.input_output_array, pt1, pt2, color, thickness, line_type, shift)
  self
end

#log_polar(center, m, flags) ⇒ Object



525
526
527
528
529
# File 'lib/opencv-ruby/core/mat.rb', line 525

def log_polar(center, m, flags)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::log_polar(self.input_array, dest.output_array, center, m, flags)
  dest
end

#lt(other) ⇒ Object



263
264
265
# File 'lib/opencv-ruby/core/mat.rb', line 263

def lt(other)
  compare(other, Cv::CmpTypes::CMP_LT)
end

#lut(lut) ⇒ Object



531
532
533
534
535
# File 'lib/opencv-ruby/core/mat.rb', line 531

def lut(lut)
  dest = self.class.new(self.rows, self.cols, lut.type)
  Cv::lut(self.input_array, lut.input_array, dest.output_array)
  dest
end

#mat_klassObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/opencv-ruby/core/mat.rb', line 74

def mat_klass
  case self.type
    when CV_8UC1
      Cv::Mat1b
    when CV_8UC2
      Cv::Mat2b
    when CV_8UC3
      Cv::Mat3b
    when CV_8UC4
      Cv::Mat4b
    when CV_8SC1
      raise("CV_8SC1 has not corresponding Mat_ class")
    when CV_8SC2
      raise("CV_8SC2 has not corresponding Mat_ class")
    when CV_8SC3
      raise("CV_8SC3 has not corresponding Mat_ class")
    when CV_8SC4
      raise("CV_8SC4 has not corresponding Mat_ class")
    when CV_16UC1
      Cv::Mat1w
    when CV_16UC2
      Cv::Mat2w
    when CV_16UC3
      Cv::Mat3w
    when CV_16UC4
      Cv::Mat4w
    when CV_16SC1
      Cv::Mat1s
    when CV_16SC2
      Cv::Mat2s
    when CV_16SC3
      Cv::Mat3s
    when CV_16SC4
      Cv::Mat4s
    when CV_32SC1
      Cv::Mat1i
    when CV_32SC2
      Cv::Mat2i
    when CV_32SC3
      Cv::Mat3i
    when CV_32SC4
      Cv::Mat4i
    when CV_32FC1
      Cv::Mat1f
    when CV_32FC2
      Cv::Mat2f
    when CV_32FC3
      Cv::Mat3f
    when CV_32FC4
      Cv::Mat4f
    when CV_64FC1
      Cv::Mat1d
    when CV_64FC2
      Cv::Mat2d
    when CV_64FC3
      Cv::Mat3d
    when CV_64FC4
      Cv::Mat4d
    when CV_16FC1
      raise("CV_16FC1 has not corresponding Mat_ class")
    when CV_16FC2
      raise("CV_16FC2 has not corresponding Mat_ class")
    when CV_16FC3
      raise("CV_16FC3 has not corresponding Mat_ class")
    when CV_16FC4
      raise("CV_16FC4 has not corresponding Mat_ class")
    else
      raise("Uknown type: #{self.type}")
  end
end

#match_template(template, method, mask: Cv::no_array) ⇒ Object



537
538
539
540
541
# File 'lib/opencv-ruby/core/mat.rb', line 537

def match_template(template, method, mask: Cv::no_array)
  dest = Cv::Mat.new
  Cv::match_template(self.input_array, template.input_array, dest.output_array, method, mask = Cv::no_array)
  dest
end

#median_blur(ksize) ⇒ Object



543
544
545
546
547
# File 'lib/opencv-ruby/core/mat.rb', line 543

def median_blur(ksize)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::median_blur(self.input_array, dest.output_array, ksize)
  dest
end

#min_max_loc(mask: nil) ⇒ Object



549
550
551
# File 'lib/opencv-ruby/core/mat.rb', line 549

def min_max_loc(mask: nil)
  Cv.min_max_loc(self.input_array, mask ? mask.input_array : Cv::no_array)
end

#morphology_ex(op, kernel, anchor: Cv::Point.new(-1,-1), iterations: 1, border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::morphology_default_border_value) ⇒ Object



553
554
555
556
557
558
# File 'lib/opencv-ruby/core/mat.rb', line 553

def morphology_ex(op, kernel, anchor: Cv::Point.new(-1,-1), iterations: 1,
                  border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::morphology_default_border_value)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::morphology_ex(self.input_array, dest.output_array, op, kernel.input_array, anchor, iterations, border_type, border_value)
  dest
end

#mul_transposed(ata: true, delta: Cv::no_array, scale: 1, dtype: -1)) ⇒ Object



560
561
562
563
564
# File 'lib/opencv-ruby/core/mat.rb', line 560

def mul_transposed(ata: true, delta: Cv::no_array, scale: 1, dtype: -1)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv.mul_transposed(self.input_array, dest.output_array, ata, delta, scale, dtype)
  dest
end

#ne(other) ⇒ Object



271
272
273
# File 'lib/opencv-ruby/core/mat.rb', line 271

def ne(other)
  compare(other, Cv::CmpTypes::CMP_NE)
end

#normalize(alpha: 1, beta: 0, norm_type: Cv::NormTypes::NORM_L2, dtype: -1,, mask: nil) ⇒ Object



566
567
568
569
570
# File 'lib/opencv-ruby/core/mat.rb', line 566

def normalize(alpha: 1, beta: 0, norm_type: Cv::NormTypes::NORM_L2, dtype: -1, mask: nil)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv.normalize(self.input_array, dest.input_output_array, alpha, beta, norm_type, dtype, mask ? mask.input_array : Cv::no_array)
  dest
end

#perspective_transform(matrix) ⇒ Object



572
573
574
575
576
# File 'lib/opencv-ruby/core/mat.rb', line 572

def perspective_transform(matrix)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv.perspective_transform(self.input_array, dest.output_array, matrix.input_array)
  dest
end

#polylines(pts, is_closed, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object



700
701
702
703
# File 'lib/opencv-ruby/core/mat.rb', line 700

def polylines(pts, is_closed, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0)
  Cv::polylines(self.input_output_array, pts, is_closed, color, thickness, line_type, shift)
  self
end

#pre_corner_detect(ksize, border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



578
579
580
581
582
# File 'lib/opencv-ruby/core/mat.rb', line 578

def pre_corner_detect(ksize, border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::pre_corner_detect(self.input_array, dest.output_array, ksize, border_type)
  dest
end

#put_text(text, org, font_face, font_scale, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, bottom_left_origin: false) ⇒ Object



705
706
707
708
# File 'lib/opencv-ruby/core/mat.rb', line 705

def put_text(text, org, font_face, font_scale, color, thickness: 1, line_type: Cv::LineTypes::LINE_8, bottom_left_origin: false)
  Cv::put_text(self.input_output_array, text, org, font_face, font_scale, color, thickness, line_type, bottom_left_origin)
  self
end

#pyr_down(dstsize: Cv::Size.new(), border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



584
585
586
587
588
# File 'lib/opencv-ruby/core/mat.rb', line 584

def pyr_down(dstsize: Cv::Size.new(), border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(dstsize, self.type)
  Cv::pyr_down(self.input_array, dest.output_array, dstsize, border_type)
  dest
end

#pyr_mean_shift_filtering(sp, sr, max_level: 1, termcrit: Cv::TermCriteria.new(Cv::TermCriteria::Type::MAX_ITER | Cv::TermCriteria::Type::EPS, 5, 1)) ⇒ Object



590
591
592
593
594
# File 'lib/opencv-ruby/core/mat.rb', line 590

def pyr_mean_shift_filtering(sp, sr, max_level: 1, termcrit: Cv::TermCriteria.new(Cv::TermCriteria::Type::MAX_ITER | Cv::TermCriteria::Type::EPS, 5, 1))
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv::pyr_mean_shift_filtering(self.input_array, dest.output_array, sp, sr, max_level, termcrit)
  dest
end

#pyr_up(dstsize: Cv::Size.new(), border_type: Cv::BorderTypes::BORDER_DEFAULT) ⇒ Object



596
597
598
599
600
# File 'lib/opencv-ruby/core/mat.rb', line 596

def pyr_up(dstsize: Cv::Size.new(), border_type: Cv::BorderTypes::BORDER_DEFAULT)
  dest = self.class.new(dstsize, self.type)
  Cv::pyr_up(self.input_array, dest.output_array, dstsize, border_type)
  dest
end

#rand_shuffle(iter_factor: 1.0, rng: nil) ⇒ Object



602
603
604
605
# File 'lib/opencv-ruby/core/mat.rb', line 602

def rand_shuffle(iter_factor: 1.0, rng: nil)
      Cv::rand_shuffle(self.input_output_array, iter_factor, rng)
      self
end

#rectangle(rect: nil, pt1: nil, pt2: nil, color:, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0) ⇒ Object



710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/opencv-ruby/core/mat.rb', line 710

def rectangle(rect: nil, pt1: nil, pt2: nil, color:, thickness: 1, line_type: Cv::LineTypes::LINE_8, shift: 0)
  if rect.nil? && (pt1.nil? || pt2.nil?)
    raise("Must specify pt1 and pt2 or rect")
  elsif !rect.nil? && (!pt1.nil? && !pt2.nil?)
    raise("Must specify pt1 and pt2 or rect")
  end
  if rect.nil?
    Cv::rectangle(self.input_output_array, pt1, pt2, color, thickness, line_type, shift)
  else
    Cv::rectangle(self.input_output_array, rect, color, thickness, line_type, shift)
  end

  self
end

#remap(map1, map2, interpolation, border_mode: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new) ⇒ Object



607
608
609
610
611
612
613
# File 'lib/opencv-ruby/core/mat.rb', line 607

def remap(map1, map2, interpolation, border_mode: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new)
  dest = self.class.new(map1.rows, map1.cols, self.type)
  Cv::remap(self.input_array, dest.output_array,
            map1.input_array, map2.input_array,
            interpolation, border_mode, border_value)
  dest
end

#splitObject



615
616
617
618
619
620
# File 'lib/opencv-ruby/core/mat.rb', line 615

def split
  channels = Std::Vector

#sumObject



622
623
624
# File 'lib/opencv-ruby/core/mat.rb', line 622

def sum
  Cv.sum(self.input_array)
end

#threshold(threshold, max_value, threshold_type) ⇒ Object



626
627
628
629
630
# File 'lib/opencv-ruby/core/mat.rb', line 626

def threshold(threshold, max_value, threshold_type)
  dest = self.class.new(self.rows, self.cols, self.type)
  computed = Cv::threshold(self.input_array, dest.output_array, threshold, max_value, threshold_type)
  [dest, computed]
end

#to_sObject



216
217
218
# File 'lib/opencv-ruby/core/mat.rb', line 216

def to_s
  "<#{self.class.name}:#{self.rows}x#{self.cols},type=#{self.type_to_string},channel=#{self.channels}>"
end

#traceObject



632
633
634
# File 'lib/opencv-ruby/core/mat.rb', line 632

def trace
  Cv.trace(self.input_array)
end

#transform(matrix) ⇒ Object



636
637
638
639
640
# File 'lib/opencv-ruby/core/mat.rb', line 636

def transform(matrix)
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv.transform(self.input_array, dest.output_array, matrix.input_array)
  dest
end

#transposeObject



642
643
644
645
646
# File 'lib/opencv-ruby/core/mat.rb', line 642

def transpose
  dest = self.class.new(self.rows, self.cols, self.type)
  Cv.transpose(self.input_array, dest.output_array)
  dest
end

#type_to_stringObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/opencv-ruby/core/mat.rb', line 3

def type_to_string
  case self.type
    when CV_8UC1
      "CV_8UC1"
    when CV_8UC2
      "CV_8UC2"
    when CV_8UC3
      "CV_8UC3"
    when CV_8UC4
      "CV_8UC4"
    when CV_8SC1
      "CV_8SC1"
    when CV_8SC2
      "CV_8SC2"
    when CV_8SC3
      "CV_8SC3"
    when CV_8SC4
      "CV_8SC4"
    when CV_16UC1
      "CV_16UC1"
    when CV_16UC2
      "CV_16UC2"
    when CV_16UC3
      "CV_16UC3"
    when CV_16UC4
      "CV_16UC4"
    when CV_16SC1
      "CV_16SC1"
    when CV_16SC2
      "CV_16SC2"
    when CV_16SC3
      "CV_16SC3"
    when CV_16SC4
      "CV_16SC4"
    when CV_32SC1
      "CV_32SC1"
    when CV_32SC2
      "CV_32SC2"
    when CV_32SC3
      "CV_32SC3"
    when CV_32SC4
      "CV_32SC4"
    when CV_32FC1
      "CV_32FC1"
    when CV_32FC2
      "CV_32FC2"
    when CV_32FC3
      "CV_32FC3"
    when CV_32FC4
      "CV_32FC4"
    when CV_64FC1
      "CV_64FC1"
    when CV_64FC2
      "CV_64FC2"
    when CV_64FC3
      "CV_64FC3"
    when CV_64FC4
      "CV_64FC4"
    when CV_16FC1
      "CV_16FC1"
    when CV_16FC2
      "CV_16FC2"
    when CV_16FC3
      "CV_16FC3"
    when CV_16FC4
      "CV_16FC4"
    else
      raise("Uknown type: #{self.type}")
  end
end

#vec_klassObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/opencv-ruby/core/mat.rb', line 145

def vec_klass
  case self.type
    when CV_8UC1
      Cv::Vec1b
    when CV_8UC2
      Cv::Vec2b
    when CV_8UC3
      Cv::Vec3b
    when CV_8UC4
      Cv::Vec4b
    when CV_8SC1
      raise("CV_8SC1 has not corresponding Mat_ class")
    when CV_8SC2
      raise("CV_8SC2 has not corresponding Mat_ class")
    when CV_8SC3
      raise("CV_8SC3 has not corresponding Mat_ class")
    when CV_8SC4
      raise("CV_8SC4 has not corresponding Mat_ class")
    when CV_16UC1
      Cv::Vec1w
    when CV_16UC2
      Cv::Vec2w
    when CV_16UC3
      Cv::Vec3w
    when CV_16UC4
      Cv::Vec4w
    when CV_16SC1
      Cv::Vec1s
    when CV_16SC2
      Cv::Vec2s
    when CV_16SC3
      Cv::Vec3s
    when CV_16SC4
      Cv::Vec4s
    when CV_32SC1
      Cv::Vec1i
    when CV_32SC2
      Cv::Vec2i
    when CV_32SC3
      Cv::Vec3i
    when CV_32SC4
      Cv::Vec4i
    when CV_32FC1
      Cv::Vec1f
    when CV_32FC2
      Cv::Vec2f
    when CV_32FC3
      Cv::Vec3f
    when CV_32FC4
      Cv::Vec4f
    when CV_64FC1
      Cv::Vec1d
    when CV_64FC2
      Cv::Vec2d
    when CV_64FC3
      Cv::Vec3d
    when CV_64FC4
      Cv::Vec4d
    when CV_16FC1
      raise("CV_16FC1 has not corresponding Mat_ class")
    when CV_16FC2
      raise("CV_16FC2 has not corresponding Mat_ class")
    when CV_16FC3
      raise("CV_16FC3 has not corresponding Mat_ class")
    when CV_16FC4
      raise("CV_16FC4 has not corresponding Mat_ class")
    else
      raise("Uknown type: #{self.type}")
  end
end

#warp_affine(m, dsize, flags: Cv::InterpolationFlags::INTER_LINEAR, border_mode: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new) ⇒ Object



648
649
650
651
652
653
654
# File 'lib/opencv-ruby/core/mat.rb', line 648

def warp_affine(m, dsize, flags: Cv::InterpolationFlags::INTER_LINEAR,
                border_mode: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new)
  result = Cv::Mat.new
  Cv::warp_affine(self.input_array, result.output_array, m.input_array,
                  dsize, flags, border_mode, border_value)
  result
end

#warp_perspective(transformation, dsize, flags: Cv::InterpolationFlags::INTER_LINEAR, border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new) ⇒ Object



656
657
658
659
660
# File 'lib/opencv-ruby/core/mat.rb', line 656

def warp_perspective(transformation, dsize, flags: Cv::InterpolationFlags::INTER_LINEAR, border_type: Cv::BorderTypes::BORDER_CONSTANT, border_value: Cv::Scalar.new)
  dest = Cv::Mat.new
  Cv::warp_perspective(self.input_array, dest.output_array, transformation.input_array, dsize, flags, border_type, border_value)
  dest
end

#watershed(markers) ⇒ Object



662
663
664
665
# File 'lib/opencv-ruby/core/mat.rb', line 662

def watershed(markers)
  Cv::watershed(self.input_array, markers.input_output_array)
  markers
end