Class: OpenCV::CvMat
- Inherits:
-
Object
- Object
- OpenCV::CvMat
- Defined in:
- ext/opencv/cvmat.cpp,
ext/opencv/iplimage.cpp
Direct Known Subclasses
Constant Summary collapse
- DRAWING_OPTION =
drawing_option- GOOD_FEATURES_TO_TRACK_OPTION =
good_features_to_track_option- FLOOD_FILL_OPTION =
flood_fill_option- FIND_CONTOURS_OPTION =
find_contours_option- OPTICAL_FLOW_HS_OPTION =
optical_flow_hs_option- OPTICAL_FLOW_BM_OPTION =
optical_flow_bm_option- FIND_FUNDAMENTAL_MAT_OPTION =
find_fundamental_matrix_option- ORB_OPTION =
orb_option- HIST_OPTION =
hist_option
Class Method Summary collapse
-
.add_weighted(src1, alpha, src2, beta, gamma) ⇒ CvMat
Computes the weighted sum of two arrays.
-
.compute_correspond_epilines(points, which_image, fundamental_matrix) ⇒ Object
For points in one image of stereo pair computes the corresponding epilines in the other image.
-
.decode_image(buf, iscolor = 1) ⇒ CvMat
Reads an image from a buffer in memory.
-
.decode_image(buf, iscolor = 1) ⇒ CvMat
Reads an image from a buffer in memory.
-
.find_fundamental_mat(points1, points2[,options = {}]) ⇒ nil
Calculates fundamental matrix from corresponding points.
-
.find_homography(src_points, dst_points, method = :all, ransac_reproj_threshold = 3, get_mask = false) ⇒ CvMat+
Finds a perspective transformation between two planes.
-
.get_perspective_transform(src, dst) ⇒ CvMat
Calculates a perspective transform from four pairs of the corresponding points.
-
.load(filename, iscolor = 1) ⇒ CvMat
Load an image from the specified file.
-
.merge(src1 = nil, src2 = nil, src3 = nil, src4 = nil) ⇒ CvMat
Composes a multi-channel array from several single-channel arrays.
-
.rotation_matrix2D(center, angle, scale) ⇒ CvMat
Calculates an affine matrix of 2D rotation.
-
.solve(src1, src2, inversion_method = :lu) ⇒ Number
Solves one or more linear systems or least-squares problems.
Instance Method Summary collapse
-
#[](args) ⇒ CvScalar
(also: #at)
Returns a specific array element.
-
#[]=(args) ⇒ CvMat
Changes the particular array element.
-
#abs_diff(val) ⇒ CvMat
Computes the per-element absolute difference between two arrays or between an array and a scalar.
-
#adaptive_threshold(max_value, options) ⇒ CvMat
Applies an adaptive threshold to an array.
-
#add(val, mask = nil) ⇒ CvMat
(also: #+)
Computes the per-element sum of two arrays or an array and a scalar.
-
#and(val, mask = nil) ⇒ CvMat
(also: #&)
Calculates the per-element bit-wise conjunction of two arrays or an array and a scalar.
- #and_into(other, dest) ⇒ Object
-
#apply_color_map(colormap) ⇒ Object
Applies a GNU Octave/MATLAB equivalent colormap on a given image.
-
#avg(mask = nil) ⇒ CvScalar
Calculates an average (mean) of array elements.
-
#avg_sdv(mask = nil) ⇒ Array<CvScalar>
Calculates a mean and standard deviation of array elements.
- #avg_value(mask) ⇒ Object
-
#calc_hist(<i>[hist_options]) ⇒ Object
Return.
-
#cam_shift(window, criteria) ⇒ Array
Implements CAMSHIFT object tracking algrorithm.
-
#canny(thresh1, thresh2, aperture_size = 3) ⇒ CvMat
Finds edges in an image using the [Canny86] algorithm.
-
#channel ⇒ Integer
Returns number of channels of the matrix.
-
#circle(center, radius, options = nil) ⇒ CvMat
Returns an image that is drawn a circle.
-
#circle!(center, radius, options = nil) ⇒ CvMat
Draws a circle.
- #cmp(val, dest, operand) ⇒ Object
-
#convert_scale(params) ⇒ CvMat
Converts one array to another with optional linear transformation.
-
#convert_scale_abs(params) ⇒ CvMat
Scales, computes absolute values, and converts the result to 8-bit.
-
#copy(dst = nil, mask = nil) ⇒ CvMat
Copies one array to another.
-
#copy_make_border(border_type, size, offset[,value = CvScalar.new(0)]) ⇒ Object
Copies image and makes border around it.
-
#corner_eigenvv(block_size, aperture_size = 3) ⇒ CvMat
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
-
#corner_harris(block_size, aperture_size = 3, k = 0.04) ⇒ CvMat
Harris edge detector.
-
#corner_min_eigen_val(block_size, aperture_size = 3) ⇒ CvMat
Calculates the minimal eigenvalue of gradient matrices for corner detection.
-
#count_non_zero ⇒ Integer
Counts non-zero array elements.
-
#create_mask ⇒ CvMat
Creates a mask (1-channel 8bit unsinged image whose elements are 0) from the matrix.
-
#cross_product(mat) ⇒ CvMat
Calculates the cross product of two 3D vectors.
-
#data ⇒ Object
deprecated
Deprecated.
This method will be removed.
-
#set_data(data) ⇒ CvMat
Assigns user data to the array header.
-
#dct(flags = CV_DXT_FORWARD) ⇒ CvMat
Performs forward or inverse Discrete Cosine Transform(DCT) of 1D or 2D floating-point array.
-
#depth ⇒ Symbol
Returns depth type of the matrix.
-
#det ⇒ Number
(also: #determinant)
Returns the determinant of a square floating-point matrix.
-
#dft(flags = CV_DXT_FORWARD, nonzero_rows = 0) ⇒ CvMat
Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.
-
#diag(val = 0) ⇒ CvMat
(also: #diagonal)
Returns a specified diagonal of the matrix.
-
#dilate([element = nil][,iteration = 1]) ⇒ Object
Create dilates image by using arbitrary structuring element.
-
#dilate!([element = nil][,iteration = 1]) ⇒ self
Dilate image by using arbitrary structuring element.
- #dilate_into(dest, element, iteration) ⇒ Object
-
#dim_size(index) ⇒ Integer
Returns array size along the specified dimension.
-
#dims ⇒ Array<Integer>
Returns array dimensions sizes.
- #distance_transform(<i>labels, distance_type, mask_size</i>)) ⇒ Object
-
#div(val, scale = 1.0) ⇒ CvMat
(also: #/)
Performs per-element division of two arrays or a scalar by an array.
-
#dot_product(mat) ⇒ Number
WBH started this but didn't end up needing it, so didn't complete debugging (used bounding_rect instead) Note that WBH of 11/2014 tried to revisit this method and was beset with 3 hours of frustration based around the fact that the ROI can only be set via a constructor, but constructing a new object means allocating and returning memory associated with that new object.
-
#draw_chessboard_corners(pattern_size, corners, pattern_was_found) ⇒ nil
Returns an image which is rendered the detected chessboard corners.
-
#draw_chessboard_corners!(pattern_size, corners, pattern_was_found) ⇒ self
Renders the detected chessboard corners.
-
#draw_contours(contour, external_color, hole_color, max_level, options) ⇒ Object
Draws contour outlines or interiors in an image.
-
#draw_contours!(contour, external_color, hole_color, max_level, options) ⇒ Object
Draws contour outlines or interiors in an image.
-
#each_col {|col| ... } ⇒ CvMat
(also: #each_column)
Calls block once for each column in the matrix, passing that column as a parameter.
-
#each_row {|row| ... } ⇒ CvMat
Calls block once for each row in the matrix, passing that row as a parameter.
-
#eigenvv ⇒ Array<CvMat>
Computes eigenvalues and eigenvectors of symmetric matrix.
-
#ellipse(center, axes, angle, start_angle, end_angle, options = nil) ⇒ CvMat
Returns an image that is drawn a simple or thick elliptic arc or fills an ellipse sector.
-
#ellipse!(center, axes, angle, start_angle, end_angle, options = nil) ⇒ CvMat
Draws a simple or thick elliptic arc or fills an ellipse sector.
-
#ellipse_box(box, options = nil) ⇒ CvMat
Returns an image that is drawn a simple or thick elliptic arc or fills an ellipse sector.
-
#ellipse_box!(box, options = nil) ⇒ CvMat
Draws a simple or thick elliptic arc or fills an ellipse sector.
-
#encode_image(ext, params = nil) ⇒ Array<Integer>
(also: #encode)
Encodes an image into a memory buffer.
-
#eq(val) ⇒ CvMat
Performs the per-element comparison "equal" of two arrays or an array and scalar value.
-
#equalize_hist ⇒ Object
Equalize histgram of grayscale of image.
-
#erode([element = nil, iteration = 1]) ⇒ Object
Create erodes image by using arbitrary structuring element.
-
#erode!([element = nil][,iteration = 1]) ⇒ self
Erodes image by using arbitrary structuring element.
-
#rb_extract_orb(params[,mask]) ⇒ Array
Extracts ORB Features from an image.
-
#extract_surf(params, mask = nil) ⇒ Array<CvSeq<CvSURFPoint>, Array<float>>
Extracts Speeded Up Robust Features from an image.
-
#fill_convex_poly(points, options = nil) ⇒ CvMat
Returns an image that is filled a convex polygon.
-
#fill_convex_poly!(points, options = nil) ⇒ CvMat
Fills a convex polygon.
-
#fill_poly(points, options = nil) ⇒ CvMat
Returns an image that is filled the area bounded by one or more polygons.
-
#fill_poly!(points, options = nil) ⇒ CvMat
Fills the area bounded by one or more polygons.
-
#filter2d(kernel[,anchor]) ⇒ Object
Convolves image with the kernel.
-
#find_chessboard_corners(pattern_size, flag = CV_CALIB_CB_ADAPTIVE_THRESH) ⇒ Array<Array<CvPoint2D32f>, Boolean>
Finds the positions of internal corners of the chessboard.
-
#find_contours(find_contours_options) ⇒ CvContour, CvChain
Finds contours in binary image.
-
#find_contours!(find_contours_options) ⇒ CvContour, CvChain
Finds contours in binary image.
-
#find_corner_sub_pix(corners, win_size, zero_zone, criteria) ⇒ Array<CvPoint2D32f>
Refines the corner locations.
- #fit_ellipse ⇒ CvBox2D
-
#fit_line ⇒ Object
self should be 2-channel or 3-channel mat (where channels are [x,y] or [x,y,z]).
-
#flip(flip_mode) ⇒ CvMat
Returns a fliped 2D array around vertical, horizontal, or both axes.
-
#flip!(flip_mode) ⇒ CvMat
Flips a 2D array around vertical, horizontal, or both axes.
-
#flood_fill(seed_point, new_val, lo_diff = CvScalar.new(0), up_diff = CvScalar.new(0), flood_fill_option = nil) ⇒ Array<CvMat, CvConnectedComp>
Fills a connected component with the given color.
-
#flood_fill!(seed_point, new_val, lo_diff = CvScalar.new(0), up_diff = CvScalar.new(0), flood_fill_option = nil) ⇒ Object
Fills a connected component with the given color.
- #flood_fill_mask(seed_point, mask, lo_diff, up_diff, connectivity, fixed_range) ⇒ Object
-
#ge(val) ⇒ CvMat
Performs the per-element comparison "greater than or equal" of two arrays or an array and scalar value.
-
#get_cols(args) ⇒ Object
Return column(or columns) of matrix.
-
#get_rows(args) ⇒ Object
Return row(or rows) of matrix.
-
#good_features_to_track(quality_level, min_distance, good_features_to_track_option = {}) ⇒ Array<CvPoint2D32f>
Determines strong corners on an image.
-
#grab_cut ⇒ Object
Does grab cut segmentation.
-
#grab_cut2 ⇒ Array, ...
Does grab cut segmentation.
-
#gt(val) ⇒ CvMat
Performs the per-element comparison "greater than" of two arrays or an array and scalar value.
-
#rows ⇒ Integer
(also: #rows)
Returns number of rows of the matrix.
-
#hough_circles(method, dp, min_dist, param1, param2, min_radius = 0, max_radius = 0) ⇒ CvSeq<CvCircle32f>
Finds circles in a grayscale image using the Hough transform.
-
#hough_lines(method, rho, theta, threshold, param1, param2) ⇒ CvSeq<CvLine, CvTwoPoints>
Finds lines in binary image using a Hough transform.
-
#identity(value) ⇒ CvMat
Returns a scaled identity matrix.
-
#identity!(value) ⇒ CvMat
Initializes a scaled identity matrix.
-
#in_range(min, max) ⇒ CvMat
Checks if array elements lie between the elements of two other arrays.
-
#inpaint(inpaint_method, mask, radius) ⇒ Object
Inpaints the selected region in the image The radius of circlular neighborhood of each point inpainted that is considered by the algorithm.
-
#inside?(object) ⇒ Boolean
Tests whether a coordinate or rectangle is inside of the matrix.
-
#integral(need_sqsum = false, need_tilted_sum = false) ⇒ Array?
Calculates integral images.
-
#invert(inversion_method = :lu) ⇒ Number
Finds inverse or pseudo-inverse of matrix.
- #kmeans(k, termcrit) ⇒ Object
-
#laplace(aperture_size = 3) ⇒ Object
Calculates the Laplacian of an image.
-
#laplace2(<i>ksize = 1, scale = 1, delta = 0</i>)) ⇒ Object
Calculates first, second, third or mixed image derivatives using extended Sobel operator.
-
#le(val) ⇒ CvMat
Performs the per-element comparison "less than or equal" of two arrays or an array and scalar value.
-
#line(p1, p2, options = nil) ⇒ CvMat
Returns an image that is drawn a line segment connecting two points.
-
#line!(p1, p2, options = nil) ⇒ CvMat
Draws a line segment connecting two points.
-
#log ⇒ Object
Calculates the natural logarithm of every array element.
-
#log_polar(size, center, magnitude, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS) ⇒ CvMat
Remaps an image to log-polar space.
-
#lt(val) ⇒ CvMat
Performs the per-element comparison "less than" of two arrays or an array and scalar value.
-
#lut(lut) ⇒ CvMat
Performs a look-up table transform of an array.
-
#magnitude(y) ⇒ Object
Calculates the magnitude of 2D vectors.
-
#mat_mul(val, shiftvec = nil) ⇒ CvMat
(also: #*)
Calculates the product of two arrays.
-
#match_shapes(object, method) ⇒ Float
Compares two shapes(self and object).
-
#match_template(template, method = CV_TM_SQDIFF) ⇒ Object
Compares template against overlapped image regions.
- #max(anothermat) ⇒ Object
-
#mean_shift(window, criteria) ⇒ Object
Implements CAMSHIFT object tracking algrorithm.
-
#method_missing(*args) ⇒ Object
nodoc.
- #min(anothermat) ⇒ Object
-
#min_max_loc(mask = nil) ⇒ Array<Number, CvPoint>
Finds the global minimum and maximum in an array.
-
#moments ⇒ Object
Calculates moments.
-
#morphology(operation, element = nil, iteration = 1) ⇒ CvMat
Performs advanced morphological transformations using erosion and dilation as basic operations.
-
#mul(val, scale = 1.0) ⇒ CvMat
Calculates the per-element scaled product of two arrays.
-
#mul_transposed(options) ⇒ CvMat
Calculates the product of a matrix and its transposition.
-
#ne(val) ⇒ CvMat
Performs the per-element comparison "not equal" of two arrays or an array and scalar value.
-
#normalize(alpha = 1.0, beta = 0.0, norm_type = NORM_L2, dtype = -1, mask = nil) ⇒ CvMat
Normalizes the norm or value range of an array.
-
#not ⇒ CvMat
Returns an array which elements are bit-wise invertion of source array.
-
#not! ⇒ CvMat
Inverts every bit of an array.
-
#optical_flow_bm(prev[,velx = nil][,vely = nil][,option]) ⇒ Array
Calculates optical flow for two images (previous -> self) using block matching method.
-
#optical_flow_hs(prev[,velx = nil][,vely = nil][,options]) ⇒ Array
Calculates optical flow for two images (previous -> self) using Horn & Schunck algorithm.
-
#optical_flow_lk(prev, win_size) ⇒ Array
Calculates optical flow for two images (previous -> self) using Lucas & Kanade algorithm Return horizontal component of the optical flow and vertical component of the optical flow.
-
#or(val, mask = nil) ⇒ CvMat
(also: #|)
Calculates the per-element bit-wise disjunction of two arrays or an array and a scalar.
-
#perspective_transform(mat) ⇒ CvMat
Performs the perspective matrix transformation of vectors.
- #pixel_value(index) ⇒ Object
-
#poly_line(points, options = nil) ⇒ CvMat
Returns an image that is drawn several polygonal curves.
-
#poly_line!(points, options = nil) ⇒ CvMat
Draws several polygonal curves.
-
#pre_corner_detect(aperture_size = 3) ⇒ CvMat
Calculates a feature map for corner detection.
-
#put_text(text, org, font, color = CvColor::Black) ⇒ CvMat
Returns an image which is drawn a text string.
-
#put_text!(text, org, font, color = CvColor::Black) ⇒ CvMat
Draws a text string.
-
#pyr_down([filter = :gaussian_5x5]) ⇒ Object
Return downsamples image.
-
#pyr_mean_shift_filtering(sp, sr[,max_level = 1][termcrit = CvTermCriteria.new(5,1)]) ⇒ Object
Does meanshift image segmentation.
-
#pyr_up([filter = :gaussian_5x5]) ⇒ Object
Return upsamples image.
-
#quadrangle_sub_pix(map_matrix, size = self.size) ⇒ CvMat
Applies an affine transformation to an image.
-
#rand_shuffle(seed = -1, iter_factor = 1) ⇒ CvMat
Returns shuffled matrix by swapping randomly chosen pairs of the matrix elements on each iteration (where each element may contain several components in case of multi-channel arrays).
-
#rand_shuffle!(seed = -1, iter_factor = 1) ⇒ CvMat
Shuffles the matrix by swapping randomly chosen pairs of the matrix elements on each iteration (where each element may contain several components in case of multi-channel arrays).
-
#range(start, end) ⇒ CvMat
Returns initialized matrix as following: arr(i,j)=(end-start)(icols(arr)+j)/(cols(arr)*rows(arr)).
-
#range!(start, end) ⇒ CvMat
Initializes the matrix as following: arr(i,j)=(end-start)(icols(arr)+j)/(cols(arr)*rows(arr)).
-
#clone ⇒ CvMat
Makes a clone of an object.
-
#rect_sub_pix(center, size = self.size) ⇒ CvMat
Retrieves a pixel rectangle from an image with sub-pixel accuracy.
-
#rectangle(p1, p2, options = nil) ⇒ CvMat
Returns an image that is drawn a simple, thick, or filled up-right rectangle.
-
#rectangle!(p1, p2, options = nil) ⇒ CvMat
Draws a simple, thick, or filled up-right rectangle.
-
#remap(mapx, mapy, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies a generic geometrical transformation to an image.
-
#repeat(dst) ⇒ CvMat
Fills the destination array with repeated copies of the source array.
-
#reshape(cn, rows = 0) ⇒ CvMat
Changes shape of matrix/image without copying data.
-
#resize(size, interpolation = :linear) ⇒ CvMat
Resizes an image.
-
#save_image(filename) ⇒ CvMat
(also: #save)
Saves an image to a specified file.
-
#sobel(<i>xorder, yorder[,aperture_size = 3]) ⇒ Object
Calculates first, second, third or mixed image derivatives using extended Sobel operator.
-
#sdv(mask = nil) ⇒ CvScalar
Calculates a standard deviation of array elements.
-
#set(value, mask = nil) ⇒ CvMat
(also: #fill)
Returns a matrix which is set every element to a given value.
-
#set!(value, mask = nil) ⇒ CvMat
(also: #fill!)
Sets every element of the matrix to a given value.
-
#set_data(data) ⇒ CvMat
Assigns user data to the array header.
-
#set_zero ⇒ CvMat
(also: #clear, #zero)
Returns cleared array.
-
#set_zero! ⇒ CvMat
(also: #clear!, #zero!)
Clears the array.
-
#size ⇒ CvSize
Returns size of the matrix.
-
#smooth(smoothtype, size1 = 3, size2 = 0, sigma1 = 0, sigma2 = 0) ⇒ CvMat
Smooths the image in one of several ways.
-
#snake_image(points, alpha, beta, gamma, window, criteria[, calc_gradient = true]) ⇒ Object
Updates snake in order to minimize its total energy that is a sum of internal energy that depends on contour shape (the smoother contour is, the smaller internal energy is) and external energy that depends on the energy field and reaches minimum at the local energy extremums that correspond to the image edges in case of image gradient.
-
#sobel(xorder, yorder, aperture_size = 3) ⇒ CvMat
Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
-
#split ⇒ Array<CvMat>
Divides a multi-channel array into several single-channel arrays.
-
#sqrt ⇒ Object
Calculates a square root of array elements.
-
#square? ⇒ Boolean
Returns whether the matrix is a square.
-
#sub(val, mask = nil) ⇒ CvMat
(also: #-)
Calculates the per-element difference between two arrays or array and a scalar.
-
#sub_rect(args) ⇒ CvMat
(also: #subrect)
Returns matrix corresponding to the rectangular sub-array of input image or matrix.
- #subspace_project(w, mean) ⇒ Object
- #subspace_reconstruct(w, mean) ⇒ Object
-
#sum ⇒ CvScalar
Calculates the sum of array elements.
-
#svd(flag = 0) ⇒ Array<CvMat>
Performs SVD of a matrix.
-
#threshold(*args) ⇒ Object
Applies a fixed-level threshold to each array element.
-
#to_16s ⇒ CvMat
Converts the matrix to 16bit signed.
-
#to_16u ⇒ CvMat
Converts the matrix to 16bit unsigned.
-
#to_32f ⇒ CvMat
Converts the matrix to 32bit float.
-
#to_32s ⇒ CvMat
Converts the matrix to 32bit signed.
-
#to_64f ⇒ CvMat
Converts the matrix to 64bit float.
-
#to_8s ⇒ CvMat
Converts the matrix to 8bit signed.
-
#to_8u ⇒ CvMat
Converts the matrix to 8bit unsigned.
-
#to_CvMat ⇒ CvMat
Converts an object to CvMat.
-
#to_IplConvKernel(anchor) ⇒ IplConvKernel
Creates a structuring element from the matrix for morphological operations.
-
#to_s ⇒ String
String representation of the matrix.
-
#trace ⇒ CvScalar
Returns the trace of a matrix.
-
#transform(transmat, shiftvec = nil) ⇒ CvMat
Performs the matrix transformation of every array element.
-
#transpose ⇒ CvMat
(also: #t)
Transposes a matrix.
-
#vector? ⇒ Boolean
Returns whether the matrix is a vector.
- #vector_magnitude! ⇒ Object
-
#warp_affine(map_matrix, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies an affine transformation to an image.
-
#warp_perspective(map_matrix, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies a perspective transformation to an image.
-
#watershed(markers) ⇒ CvMat
Performs a marker-based image segmentation using the watershed algorithm.
-
#width ⇒ Integer
(also: #columns, #cols)
Returns number of columns of the matrix.
-
#xor(val, mask = nil) ⇒ CvMat
(also: #^)
Calculates the per-element bit-wise "exclusive or" operation on two arrays or an array and a scalar.
- #zero?(x, y) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
nodoc
338 339 340 341 342 343 344 345 346 347 |
# File 'ext/opencv/cvmat.cpp', line 338 VALUE rb_method_missing(int argc, VALUE *argv, VALUE self) { VALUE name, args, method; rb_scan_args(argc, argv, "1*", &name, &args); method = rb_funcall(name, rb_intern("to_s"), 0); if (RARRAY_LEN(args) != 0 || !rb_respond_to(rb_module_opencv(), rb_intern(StringValuePtr(method)))) return rb_call_super(argc, argv); return rb_funcall(rb_module_opencv(), rb_intern(StringValuePtr(method)), 1, self); } |
Class Method Details
.add_weighted(src1, alpha, src2, beta, gamma) ⇒ CvMat
Computes the weighted sum of two arrays. This function calculates the weighted sum of two arrays as follows:
dst(I) = src1(I) * alpha + src2(I) * beta + gamma
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 |
# File 'ext/opencv/cvmat.cpp', line 1947 VALUE rb_add_weighted(VALUE klass, VALUE src1, VALUE alpha, VALUE src2, VALUE beta, VALUE gamma) { CvArr* src1_ptr = CVARR_WITH_CHECK(src1); VALUE dst = new_mat_kind_object(cvGetSize(src1_ptr), src1); try { cvAddWeighted(src1_ptr, NUM2DBL(alpha), CVARR_WITH_CHECK(src2), NUM2DBL(beta), NUM2DBL(gamma), CVARR(dst)); } catch (cv::Exception& e) { raise_cverror(e); } return dst; } |
.compute_correspond_epilines(points, which_image, fundamental_matrix) ⇒ Object
For points in one image of stereo pair computes the corresponding epilines in the other image. Finds equation of a line that contains the corresponding point (i.e. projection of the same 3D point) in the other image. Each line is encoded by a vector of 3 elements l=[a,b,c]T, so that:
lT*[x, y, 1]T=0,
or ax + by + c = 0 From the fundamental matrix definition (see cvFindFundamentalMatrix discussion), line l2 for a point p1 in the first image (which_image=1) can be computed as:
l2=F*p1
and the line l1 for a point p2 in the second image (which_image=1) can be computed as:
l1=FT*p2
Line coefficients are defined up to a scale. They are normalized (a2+b2=1) are stored into correspondent_lines.
6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 |
# File 'ext/opencv/cvmat.cpp', line 6319 VALUE rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_image, VALUE fundamental_matrix) { VALUE correspondent_lines; CvMat* points_ptr = CVMAT_WITH_CHECK(points); int n; if (points_ptr->cols <= 3 && points_ptr->rows >= 7) n = points_ptr->rows; else if (points_ptr->rows <= 3 && points_ptr->cols >= 7) n = points_ptr->cols; else rb_raise(rb_eArgError, "input points should 2xN, Nx2 or 3xN, Nx3 matrix(N >= 7)."); correspondent_lines = cCvMat::new_object(n, 3, CV_MAT_DEPTH(points_ptr->type)); try { cvComputeCorrespondEpilines(points_ptr, NUM2INT(which_image), CVMAT_WITH_CHECK(fundamental_matrix), CVMAT(correspondent_lines)); } catch (cv::Exception& e) { raise_cverror(e); } return correspondent_lines; } |
.decode_image(buf, iscolor = 1) ⇒ CvMat
Reads an image from a buffer in memory.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'ext/opencv/cvmat.cpp', line 316 VALUE rb_decode_imageM(int argc, VALUE *argv, VALUE self) { int iscolor, need_release; CvMat* buff = prepare_decoding(argc, argv, &iscolor, &need_release); CvMat* mat_ptr = NULL; try { mat_ptr = cvDecodeImageM(buff, iscolor); if (need_release) { cvReleaseMat(&buff); } } catch (cv::Exception& e) { raise_cverror(e); } return OPENCV_OBJECT(rb_klass, mat_ptr); } |
.decode_image(buf, iscolor = 1) ⇒ CvMat
Reads an image from a buffer in memory.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'ext/opencv/cvmat.cpp', line 316 VALUE rb_decode_imageM(int argc, VALUE *argv, VALUE self) { int iscolor, need_release; CvMat* buff = prepare_decoding(argc, argv, &iscolor, &need_release); CvMat* mat_ptr = NULL; try { mat_ptr = cvDecodeImageM(buff, iscolor); if (need_release) { cvReleaseMat(&buff); } } catch (cv::Exception& e) { raise_cverror(e); } return OPENCV_OBJECT(rb_klass, mat_ptr); } |
.find_fundamental_mat(points1, points2[,options = {}]) ⇒ nil
Calculates fundamental matrix from corresponding points. Size of the output fundamental matrix is 3x3 or 9x3 (7-point method may return up to 3 matrices)
points1 and points2 should be 2xN, Nx2, 3xN or Nx3 1-channel, or 1xN or Nx1 multi-channel matrix. method is method for computing the fundamental matrix
- CV_FM_7POINT for a 7-point algorithm. (N = 7)
- CV_FM_8POINT for an 8-point algorithm. (N >= 8)
- CV_FM_RANSAC for the RANSAC algorithm. (N >= 8)
- CV_FM_LMEDS for the LMedS algorithm. (N >= 8) option should be Hash include these keys. :with_status (true or false) If set true, return fundamental_matrix and status. [fundamental_matrix, status] Otherwise return fundamental matrix only(default). :maximum_distance The parameter is used for RANSAC. It is the maximum distance from point to epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution and the image noise. :desirable_level The optional output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in RANSAC and LMedS methods. For other methods it is set to all 1's.
note: option's default value is CvMat::FIND_FUNDAMENTAL_MAT_OPTION.
6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 |
# File 'ext/opencv/cvmat.cpp', line 6263 VALUE rb_find_fundamental_mat(int argc, VALUE *argv, VALUE klass) { VALUE points1, points2, method, option, fundamental_matrix, status; int num = 0; rb_scan_args(argc, argv, "31", &points1, &points2, &method, &option); option = FIND_FUNDAMENTAL_MAT_OPTION(option); int fm_method = FIX2INT(method); CvMat *points1_ptr = CVMAT_WITH_CHECK(points1); if (fm_method == CV_FM_7POINT) fundamental_matrix = cCvMat::new_object(9, 3, CV_MAT_DEPTH(points1_ptr->type)); else fundamental_matrix = cCvMat::new_object(3, 3, CV_MAT_DEPTH(points1_ptr->type)); if (FFM_WITH_STATUS(option)) { int status_len = (points1_ptr->rows > points1_ptr->cols) ? points1_ptr->rows : points1_ptr->cols; status = cCvMat::new_object(1, status_len, CV_8UC1); try { num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), fm_method, FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), CVMAT(status)); } catch (cv::Exception& e) { raise_cverror(e); } return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status); } else { try { num = cvFindFundamentalMat(points1_ptr, CVMAT_WITH_CHECK(points2), CVMAT(fundamental_matrix), fm_method, FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), NULL); } catch (cv::Exception& e) { raise_cverror(e); } return num == 0 ? Qnil : fundamental_matrix; } } |
.find_homography(src_points, dst_points, method = :all, ransac_reproj_threshold = 3, get_mask = false) ⇒ CvMat+
Finds a perspective transformation between two planes.
4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 |
# File 'ext/opencv/cvmat.cpp', line 4250 VALUE rb_find_homography(int argc, VALUE *argv, VALUE self) { VALUE src_points, dst_points, method, ransac_reproj_threshold, get_status; rb_scan_args(argc, argv, "23", &src_points, &dst_points, &method, &ransac_reproj_threshold, &get_status); VALUE homography = new_object(cvSize(3, 3), CV_32FC1); int _method = CVMETHOD("HOMOGRAPHY_CALC_METHOD", method, 0); double _ransac_reproj_threshold = NIL_P(ransac_reproj_threshold) ? 0.0 : NUM2DBL(ransac_reproj_threshold); if ((_method != 0) && (!NIL_P(get_status)) && IF_BOOL(get_status, 1, 0, 0)) { CvMat *src = CVMAT_WITH_CHECK(src_points); int num_points = MAX(src->rows, src->cols); VALUE status = new_object(cvSize(num_points, 1), CV_8UC1); try { cvFindHomography(src, CVMAT_WITH_CHECK(dst_points), CVMAT(homography), _method, _ransac_reproj_threshold, CVMAT(status)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_assoc_new(homography, status); } else { try { cvFindHomography(CVMAT(src_points), CVMAT(dst_points), CVMAT(homography), _method, _ransac_reproj_threshold, NULL); } catch (cv::Exception& e) { raise_cverror(e); } return homography; } } |
.get_perspective_transform(src, dst) ⇒ CvMat
Calculates a perspective transform from four pairs of the corresponding points.
4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 |
# File 'ext/opencv/cvmat.cpp', line 4320 VALUE rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest) { Check_Type(source, T_ARRAY); Check_Type(dest, T_ARRAY); int count = RARRAY_LEN(source); CvPoint2D32f* source_buff = ALLOCA_N(CvPoint2D32f, count); CvPoint2D32f* dest_buff = ALLOCA_N(CvPoint2D32f, count); for (int i = 0; i < count; i++) { source_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(source)[i])); dest_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(dest)[i])); } VALUE map_matrix = new_object(cvSize(3, 3), CV_MAKETYPE(CV_32F, 1)); try { cvGetPerspectiveTransform(source_buff, dest_buff, CVMAT(map_matrix)); } catch (cv::Exception& e) { raise_cverror(e); } return map_matrix; } |
.load(filename, iscolor = 1) ⇒ CvMat
Load an image from the specified file
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 |
# File 'ext/opencv/cvmat.cpp', line 172 VALUE rb_load_imageM(int argc, VALUE *argv, VALUE self) { VALUE filename, iscolor; rb_scan_args(argc, argv, "11", &filename, &iscolor); Check_Type(filename, T_STRING); int _iscolor; if (NIL_P(iscolor)) { _iscolor = CV_LOAD_IMAGE_COLOR; } else { Check_Type(iscolor, T_FIXNUM); _iscolor = FIX2INT(iscolor); } CvMat *mat = NULL; try { mat = cvLoadImageM(StringValueCStr(filename), _iscolor); } catch (cv::Exception& e) { raise_cverror(e); } if (mat == NULL) { rb_raise(rb_eStandardError, "file does not exist or invalid format image."); } return OPENCV_OBJECT(rb_klass, mat); } |
.merge(src1 = nil, src2 = nil, src3 = nil, src4 = nil) ⇒ CvMat
Composes a multi-channel array from several single-channel arrays.
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'ext/opencv/cvmat.cpp', line 1585 VALUE rb_merge(VALUE klass, VALUE args) { int len = RARRAY_LEN(args); if (len <= 0 || len > 4) { rb_raise(rb_eArgError, "wrong number of argument (%d for 1..4)", len); } CvMat *src[] = { NULL, NULL, NULL, NULL }, *prev_src = NULL; for (int i = 0; i < len; ++i) { VALUE object = rb_ary_entry(args, i); if (NIL_P(object)) src[i] = NULL; else { src[i] = CVMAT_WITH_CHECK(object); if (CV_MAT_CN(src[i]->type) != 1) rb_raise(rb_eArgError, "image should be single-channel CvMat."); if (prev_src == NULL) prev_src = src[i]; else { if (!CV_ARE_SIZES_EQ(prev_src, src[i])) rb_raise(rb_eArgError, "image size should be same."); if (!CV_ARE_DEPTHS_EQ(prev_src, src[i])) rb_raise(rb_eArgError, "image depth should be same."); } } } // TODO: adapt IplImage VALUE dest = Qnil; try { dest = new_object(cvGetSize(src[0]), CV_MAKETYPE(CV_MAT_DEPTH(src[0]->type), len)); cvMerge(src[0], src[1], src[2], src[3], CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
.rotation_matrix2D(center, angle, scale) ⇒ CvMat
Calculates an affine matrix of 2D rotation.
4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 |
# File 'ext/opencv/cvmat.cpp', line 4297 VALUE rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale) { VALUE map_matrix = new_object(cvSize(3, 2), CV_MAKETYPE(CV_32F, 1)); try { cv2DRotationMatrix(VALUE_TO_CVPOINT2D32F(center), NUM2DBL(angle), NUM2DBL(scale), CVMAT(map_matrix)); } catch (cv::Exception& e) { raise_cverror(e); } return map_matrix; } |
.solve(src1, src2, inversion_method = :lu) ⇒ Number
Solves one or more linear systems or least-squares problems.
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 |
# File 'ext/opencv/cvmat.cpp', line 2843 VALUE rb_solve(int argc, VALUE *argv, VALUE self) { VALUE src1, src2, symbol; rb_scan_args(argc, argv, "21", &src1, &src2, &symbol); VALUE dest = Qnil; CvArr* src2_ptr = CVARR_WITH_CHECK(src2); try { dest = new_mat_kind_object(cvGetSize(src2_ptr), src2); cvSolve(CVARR_WITH_CHECK(src1), src2_ptr, CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
Instance Method Details
#[](idx0) ⇒ CvScalar #[](idx0, idx1) ⇒ CvScalar #[](idx0, idx1, idx2) ⇒ CvScalar #[](idx0, idx1, idx2, ...) ⇒ CvScalar Also known as: at
Returns a specific array element.
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'ext/opencv/cvmat.cpp', line 1008 VALUE rb_aref(VALUE self, VALUE args) { int index[CV_MAX_DIM]; for (int i = 0; i < RARRAY_LEN(args); ++i) index[i] = NUM2INT(rb_ary_entry(args, i)); CvScalar scalar = cvScalarAll(0); try { switch (RARRAY_LEN(args)) { case 1: scalar = cvGet1D(CVARR(self), index[0]); break; case 2: scalar = cvGet2D(CVARR(self), index[0], index[1]); break; default: scalar = cvGetND(CVARR(self), index); break; } } catch (cv::Exception& e) { raise_cverror(e); } return cCvScalar::new_object(scalar); } |
#[]=(idx0, value) ⇒ CvMat #[]=(idx0, idx1, value) ⇒ CvMat #[]=(idx0, idx1, idx2, value) ⇒ CvMat #[]=(idx0, idx1, idx2, ..., value) ⇒ CvMat
Changes the particular array element
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'ext/opencv/cvmat.cpp', line 1099 VALUE rb_aset(VALUE self, VALUE args) { CvScalar scalar = VALUE_TO_CVSCALAR(rb_ary_pop(args)); int index[CV_MAX_DIM]; for (int i = 0; i < RARRAY_LEN(args); ++i) index[i] = NUM2INT(rb_ary_entry(args, i)); try { switch (RARRAY_LEN(args)) { case 1: cvSet1D(CVARR(self), index[0], scalar); break; case 2: cvSet2D(CVARR(self), index[0], index[1], scalar); break; default: cvSetND(CVARR(self), index, scalar); break; } } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#abs_diff(val) ⇒ CvMat
Computes the per-element absolute difference between two arrays or between an array and a scalar.
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 |
# File 'ext/opencv/cvmat.cpp', line 2264 VALUE rb_abs_diff(VALUE self, VALUE val) { CvArr* self_ptr = CVARR(self); VALUE dest = new_mat_kind_object(cvGetSize(self_ptr), self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvAbsDiff(self_ptr, CVARR(val), CVARR(dest)); else cvAbsDiffS(self_ptr, CVARR(dest), VALUE_TO_CVSCALAR(val)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#adaptive_threshold(max_value, options) ⇒ CvMat
Applies an adaptive threshold to an array.
4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 |
# File 'ext/opencv/cvmat.cpp', line 4975 VALUE rb_adaptive_threshold(int argc, VALUE *argv, VALUE self) { VALUE dest, max_value, adaptive_method, threshold_type, block_size, constant; rb_scan_args(argc, argv, "5", &max_value, &adaptive_method, &threshold_type, &block_size, &constant); CvMat* self_ptr = CVMAT(self); // Create our destination pixels dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_MAT_DEPTH(self_ptr->type), 1); try { const cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); cv::adaptiveThreshold(selfMat, destMat, max_value, adaptive_method, threshold_type, block_size, constant); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#add(val, mask = nil) ⇒ CvMat Also known as: +
Computes the per-element sum of two arrays or an array and a scalar.
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 |
# File 'ext/opencv/cvmat.cpp', line 1765 VALUE rb_add(int argc, VALUE *argv, VALUE self) { VALUE val, mask, dest; rb_scan_args(argc, argv, "11", &val, &mask); dest = copy(self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvAdd(CVARR(self), CVARR(val), CVARR(dest), MASK(mask)); else cvAddS(CVARR(self), VALUE_TO_CVSCALAR(val), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#and(val, mask = nil) ⇒ CvMat Also known as: &
Calculates the per-element bit-wise conjunction of two arrays or an array and a scalar.
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 |
# File 'ext/opencv/cvmat.cpp', line 1974 VALUE rb_and(int argc, VALUE *argv, VALUE self) { VALUE val, mask, dest; rb_scan_args(argc, argv, "11", &val, &mask); dest = copy(self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvAnd(CVARR(self), CVARR(val), CVARR(dest), MASK(mask)); else cvAndS(CVARR(self), VALUE_TO_CVSCALAR(val), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#and_into(other, dest) ⇒ Object
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 |
# File 'ext/opencv/cvmat.cpp', line 1992 VALUE rb_and_into(VALUE self, VALUE other, VALUE dest) { try { cvAnd(CVARR(self), CVARR(other), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#apply_color_map(colormap) ⇒ Object
Applies a GNU Octave/MATLAB equivalent colormap on a given image.
Parameters:
colormap - The colormap to apply.
5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 |
# File 'ext/opencv/cvmat.cpp', line 5864 VALUE rb_apply_color_map(VALUE self, VALUE colormap) { VALUE dst; try { cv::Mat dst_mat; cv::Mat self_mat(CVMAT(self)); cv::applyColorMap(self_mat, dst_mat, NUM2INT(colormap)); CvMat tmp = dst_mat; dst = new_object(tmp.rows, tmp.cols, tmp.type); cvCopy(&tmp, CVMAT(dst)); } catch (cv::Exception& e) { raise_cverror(e); } return dst; } |
#avg(mask = nil) ⇒ CvScalar
Calculates an average (mean) of array elements.
2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 |
# File 'ext/opencv/cvmat.cpp', line 2423 VALUE rb_avg(int argc, VALUE *argv, VALUE self) { VALUE mask; rb_scan_args(argc, argv, "01", &mask); CvScalar avg; try { avg = cvAvg(CVARR(self), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return cCvScalar::new_object(avg); } |
#avg_sdv(mask = nil) ⇒ Array<CvScalar>
Calculates a mean and standard deviation of array elements.
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 |
# File 'ext/opencv/cvmat.cpp', line 2459 VALUE rb_avg_sdv(int argc, VALUE *argv, VALUE self) { VALUE mask, mean, std_dev; rb_scan_args(argc, argv, "01", &mask); mean = cCvScalar::new_object(); std_dev = cCvScalar::new_object(); try { cvAvgSdv(CVARR(self), CVSCALAR(mean), CVSCALAR(std_dev), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, mean, std_dev); } |
#avg_value(mask) ⇒ Object
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 |
# File 'ext/opencv/cvmat.cpp', line 2438 VALUE rb_avg_value(VALUE self, VALUE mask) { CvScalar avg; try { avg = cvAvg(CVARR(self), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_float_new(avg.val[0]); } |
#calc_hist(<i>[hist_options]) ⇒ Object
Return
hist_options should be Hash include these keys. :bins Number of bins to create per-channel. Defaults to -1, which will use the depth of the image as the bin count. :mask Optional Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as arrays . The non-zero mask elements mark the array elements counted in the histogram.
5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 |
# File 'ext/opencv/cvmat.cpp', line 5793 VALUE rb_calc_hist(int argc, VALUE *argv, VALUE self) { VALUE ; rb_scan_args(argc, argv, "01", &); const cv::Mat src(CVMAT(self)); = HIST_OPTION(); VALUE minVal = DO_HIST_MIN(); const float rangeMin = minVal != Qnil ? NUM2DBL(minVal) : 0; VALUE maxVal = DO_HIST_MAX(); const float rangeMax = maxVal != Qnil ? NUM2DBL(maxVal) : std::pow(2.0, (float)src.elemSize1() * 8.0); const float channelRanges[] = { rangeMin, rangeMax }; const float* ranges[] = { channelRanges, channelRanges, channelRanges, channelRanges }; int binCount = DO_HIST_BINS(); if (binCount < 0) { binCount = int(channelRanges[1]); } const int histSize[] = { binCount, binCount, binCount, binCount }; const int channels[] = { 0, 1, 2, 3 }; cv::Mat maskMat; VALUE maskVal = DO_HIST_MASK(); if (maskVal != Qnil) { if (!(rb_obj_is_kind_of(maskVal, cCvMat::rb_class())) || cvGetElemType(CVARR(maskVal)) != CV_8UC1) rb_raise(rb_eTypeError, "mask should be mask image."); maskMat = CVMAT(maskVal); } // Commented by WBH until we have time to re-implement MatND (removed by rebase, dunno if it needs to be changed) /* try { cv::MatND histMat; cv::calcHist( &src, 1, channels, maskMat, histMat, src.channels(), histSize, ranges, true, false ); const CvMatND histmatnd(histMat); return cCvMatND::new_object(&histmatnd); } catch (cv::Exception& e) { raise_cverror(e); } */ return Qnil; } |
#cam_shift(window, criteria) ⇒ Array
Implements CAMSHIFT object tracking algrorithm. First, it finds an object center using cvMeanShift and, after that, calculates the object size and orientation. The function returns number of iterations made within cvMeanShift.
5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 |
# File 'ext/opencv/cvmat.cpp', line 5992 VALUE rb_cam_shift(VALUE self, VALUE window, VALUE criteria) { VALUE comp = cCvConnectedComp::new_object(); VALUE box = cCvBox2D::new_object(); try { cvCamShift(CVARR(self), VALUE_TO_CVRECT(window), VALUE_TO_CVTERMCRITERIA(criteria), CVCONNECTEDCOMP(comp), CVBOX2D(box)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, comp, box); } |
#canny(thresh1, thresh2, aperture_size = 3) ⇒ CvMat
Finds edges in an image using the [Canny86] algorithm.
Canny86: J. Canny. A Computational Approach to Edge Detection, IEEE Trans. on Pattern Analysis and Machine Intelligence, 8(6), pp. 679-698 (1986).
3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 |
# File 'ext/opencv/cvmat.cpp', line 3808 VALUE rb_canny(int argc, VALUE *argv, VALUE self) { VALUE dest, thresh1, thresh2, aperture_size, l2_gradient; int args_given = rb_scan_args(argc, argv, "22", &thresh1, &thresh2, &aperture_size, &l2_gradient); switch(args_given) { case 2: aperture_size = 3; // intentional fallthrough, params applied cumulatively case 1: l2_gradient = false; } CvMat* self_ptr = CVMAT(self); // Create our destination pixels dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_MAT_DEPTH(self_ptr->type), 1); try { const cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); cv::Canny(selfMat, destMat, NUM2INT(thresh1), NUM2INT(thresh2), NUM2INT(aperture_size), l2_gradient); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#channel ⇒ Integer
Returns number of channels of the matrix
473 474 475 476 477 |
# File 'ext/opencv/cvmat.cpp', line 473 VALUE rb_channel(VALUE self) { return INT2FIX(CV_MAT_CN(CVMAT(self)->type)); } |
#circle(center, radius, options = nil) ⇒ CvMat
Returns an image that is drawn a circle
3198 3199 3200 3201 3202 |
# File 'ext/opencv/cvmat.cpp', line 3198 VALUE rb_circle(int argc, VALUE *argv, VALUE self) { return rb_circle_bang(argc, argv, rb_rcv_clone(self)); } |
#circle!(center, radius, options = nil) ⇒ CvMat
Draws a circle
3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 |
# File 'ext/opencv/cvmat.cpp', line 3221 VALUE rb_circle_bang(int argc, VALUE *argv, VALUE self) { VALUE center, radius, drawing_option; rb_scan_args(argc, argv, "21", ¢er, &radius, &drawing_option); drawing_option = DRAWING_OPTION(drawing_option); try { cvCircle(CVARR(self), VALUE_TO_CVPOINT(center), NUM2INT(radius), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#cmp(val, dest, operand) ⇒ Object
2094 2095 2096 2097 2098 |
# File 'ext/opencv/cvmat.cpp', line 2094 VALUE rb_cmp(VALUE self, VALUE val, VALUE dest, VALUE operand) { return rb_cmp_internal(self, val, dest, NUM2INT(operand)); } |
#convert_scale(params) ⇒ CvMat
Converts one array to another with optional linear transformation.
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 |
# File 'ext/opencv/cvmat.cpp', line 1704 VALUE rb_convert_scale(VALUE self, VALUE hash) { Check_Type(hash, T_HASH); CvMat* self_ptr = CVMAT(self); VALUE depth = LOOKUP_HASH(hash, "depth"); 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, CVMETHOD("DEPTH", depth, CV_MAT_DEPTH(self_ptr->type)), CV_MAT_CN(self_ptr->type)); cvConvertScale(self_ptr, CVARR(dest), IF_DBL(scale, 1.0), IF_DBL(shift, 0.0)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#convert_scale_abs(params) ⇒ CvMat
Scales, computes absolute values, and converts the result to 8-bit.
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
# File 'ext/opencv/cvmat.cpp', line 1736 VALUE rb_convert_scale_abs(VALUE self, VALUE hash) { Check_Type(hash, T_HASH); CvMat* self_ptr = CVMAT(self); 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)); cvConvertScaleAbs(self_ptr, CVARR(dest), IF_DBL(scale, 1.0), IF_DBL(shift, 0.0)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#copy(dst = nil, mask = nil) ⇒ CvMat
Copies one array to another.
The function copies selected elements from an input array to an output array: dst(I) = src(I) if mask(I) != 0
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'ext/opencv/cvmat.cpp', line 522 VALUE rb_copy(int argc, VALUE *argv, VALUE self) { VALUE _dst, _mask; rb_scan_args(argc, argv, "02", &_dst, &_mask); CvMat* mask = MASK(_mask); CvArr *src = CVARR(self); if (NIL_P(_dst)) { CvSize size = cvGetSize(src); _dst = new_mat_kind_object(size, self); } try { cvCopy(src, CVARR_WITH_CHECK(_dst), mask); } catch (cv::Exception& e) { raise_cverror(e); } return _dst; } |
#copy_make_border(border_type, size, offset[,value = CvScalar.new(0)]) ⇒ Object
Copies image and makes border around it. border_type:
- IPL_BORDER_CONSTANT, :constant border is filled with the fixed value, passed as last parameter of the function.
- IPL_BORDER_REPLICATE, :replicate the pixels from the top and bottom rows, the left-most and right-most columns are replicated to fill the border size: The destination image size offset: Coordinates of the top-left corner (or bottom-left in the case of images with bottom-left origin) of the destination image rectangle. value: Value of the border pixels if bordertype is IPL_BORDER_CONSTANT or :constant.
4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 |
# File 'ext/opencv/cvmat.cpp', line 4793 VALUE rb_copy_make_border(int argc, VALUE *argv, VALUE self) { VALUE border_type, size, offset, value, dest; rb_scan_args(argc, argv, "31", &border_type, &size, &offset, &value); dest = new_mat_kind_object(VALUE_TO_CVSIZE(size), self); int type = 0; if (SYMBOL_P(border_type)) { ID type_id = rb_to_id(border_type); if (type_id == rb_intern("constant")) type = IPL_BORDER_CONSTANT; else if (type_id == rb_intern("replicate")) type = IPL_BORDER_REPLICATE; else rb_raise(rb_eArgError, "Invalid border_type (should be :constant or :replicate)"); } else type = NUM2INT(border_type); try { cvCopyMakeBorder(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT(offset), type, NIL_P(value) ? cvScalar(0) : VALUE_TO_CVSCALAR(value)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#corner_eigenvv(block_size, aperture_size = 3) ⇒ CvMat
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 |
# File 'ext/opencv/cvmat.cpp', line 3870 VALUE rb_corner_eigenvv(int argc, VALUE *argv, VALUE self) { VALUE block_size, aperture_size, dest; if (rb_scan_args(argc, argv, "11", &block_size, &aperture_size) < 2) aperture_size = INT2FIX(3); CvMat* self_ptr = CVMAT(self); dest = new_object(cvSize(self_ptr->cols * 6, self_ptr->rows), CV_MAKETYPE(CV_32F, 1)); try { cvCornerEigenValsAndVecs(self_ptr, CVARR(dest), NUM2INT(block_size), NUM2INT(aperture_size)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#corner_harris(block_size, aperture_size = 3, k = 0.04) ⇒ CvMat
Harris edge detector.
3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 |
# File 'ext/opencv/cvmat.cpp', line 3923 VALUE rb_corner_harris(int argc, VALUE *argv, VALUE self) { VALUE block_size, aperture_size, k, dest; rb_scan_args(argc, argv, "12", &block_size, &aperture_size, &k); CvArr* self_ptr = CVARR(self); dest = new_object(cvGetSize(self_ptr), CV_MAKETYPE(CV_32F, 1)); try { cvCornerHarris(self_ptr, CVARR(dest), NUM2INT(block_size), IF_INT(aperture_size, 3), IF_DBL(k, 0.04)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#corner_min_eigen_val(block_size, aperture_size = 3) ⇒ CvMat
Calculates the minimal eigenvalue of gradient matrices for corner detection.
3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 |
# File 'ext/opencv/cvmat.cpp', line 3896 VALUE rb_corner_min_eigen_val(int argc, VALUE *argv, VALUE self) { VALUE block_size, aperture_size, dest; if (rb_scan_args(argc, argv, "11", &block_size, &aperture_size) < 2) aperture_size = INT2FIX(3); CvArr* self_ptr = CVARR(self); dest = new_object(cvGetSize(self_ptr), CV_MAKETYPE(CV_32F, 1)); try { cvCornerMinEigenVal(self_ptr, CVARR(dest), NUM2INT(block_size), NUM2INT(aperture_size)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#count_non_zero ⇒ Integer
Counts non-zero array elements.
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 |
# File 'ext/opencv/cvmat.cpp', line 2383 VALUE rb_count_non_zero(VALUE self) { int n = 0; try { n = cvCountNonZero(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return INT2NUM(n); } |
#create_mask ⇒ CvMat
Creates a mask (1-channel 8bit unsinged image whose elements are 0) from the matrix. The size of the mask is the same as source matrix.
420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'ext/opencv/cvmat.cpp', line 420 VALUE rb_create_mask(VALUE self) { VALUE mask = cCvMat::new_object(cvGetSize(CVARR(self)), CV_8UC1); try { cvZero(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return mask; } |
#cross_product(mat) ⇒ CvMat
Calculates the cross product of two 3D vectors.
2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 |
# File 'ext/opencv/cvmat.cpp', line 2628 VALUE rb_cross_product(VALUE self, VALUE mat) { CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvCrossProduct(self_ptr, CVARR_WITH_CHECK(mat), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#data ⇒ Object
This method will be removed.
483 484 485 486 487 488 |
# File 'ext/opencv/cvmat.cpp', line 483 VALUE rb_data(VALUE self) { IplImage *image = IPLIMAGE(self); return rb_str_new((char *)image->imageData, image->imageSize); } |
#set_data(data) ⇒ CvMat
Assigns user data to the array header
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'ext/opencv/cvmat.cpp', line 1133 VALUE rb_set_data(VALUE self, VALUE data) { CvMat *self_ptr = CVMAT(self); int depth = CV_MAT_DEPTH(self_ptr->type); if (TYPE(data) == T_STRING) { if (depth != CV_8U) rb_raise(rb_eArgError, "Invalid CvMat depth"); if (!CV_IS_MAT_CONT(self_ptr->type)) rb_raise(rb_eArgError, "CvMat must be continuous"); const int dataLength = RSTRING_LEN(data); if (dataLength != self_ptr->width * self_ptr->height * CV_MAT_CN(self_ptr->type)) rb_raise(rb_eArgError, "Invalid data string length"); memcpy(self_ptr->data.ptr, RSTRING_PTR(data), dataLength); } else { data = rb_funcall(data, rb_intern("flatten"), 0); const int DATA_LEN = RARRAY_LEN(data); void* array = NULL; switch (depth) { case CV_8U: array = rb_cvAlloc(sizeof(uchar) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((uchar*)array)[i] = (uchar)(NUM2INT(rb_ary_entry(data, i))); break; case CV_8S: array = rb_cvAlloc(sizeof(char) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((char*)array)[i] = (char)(NUM2INT(rb_ary_entry(data, i))); break; case CV_16U: array = rb_cvAlloc(sizeof(ushort) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((ushort*)array)[i] = (ushort)(NUM2INT(rb_ary_entry(data, i))); break; case CV_16S: array = rb_cvAlloc(sizeof(short) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((short*)array)[i] = (short)(NUM2INT(rb_ary_entry(data, i))); break; case CV_32S: array = rb_cvAlloc(sizeof(int) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((int*)array)[i] = NUM2INT(rb_ary_entry(data, i)); break; case CV_32F: array = rb_cvAlloc(sizeof(float) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((float*)array)[i] = (float)NUM2DBL(rb_ary_entry(data, i)); break; case CV_64F: array = rb_cvAlloc(sizeof(double) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((double*)array)[i] = NUM2DBL(rb_ary_entry(data, i)); break; default: rb_raise(rb_eArgError, "Invalid CvMat depth"); break; } try { cvSetData(self_ptr, array, self_ptr->step); } catch (cv::Exception& e) { raise_cverror(e); } } return self; } |
#dct(flags = CV_DXT_FORWARD) ⇒ CvMat
Performs forward or inverse Discrete Cosine Transform(DCT) of 1D or 2D floating-point array.
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 |
# File 'ext/opencv/cvmat.cpp', line 3044 VALUE rb_dct(int argc, VALUE *argv, VALUE self) { VALUE flag_value; rb_scan_args(argc, argv, "01", &flag_value); int flags = NIL_P(flag_value) ? CV_DXT_FORWARD : NUM2INT(flag_value); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvDCT(self_ptr, CVARR(dest), flags); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#depth ⇒ Symbol
Returns depth type of the matrix
461 462 463 464 465 466 |
# File 'ext/opencv/cvmat.cpp', line 461 VALUE rb_depth(VALUE self) { 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))); } |
#det ⇒ Number Also known as: determinant
Returns the determinant of a square floating-point matrix.
2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 |
# File 'ext/opencv/cvmat.cpp', line 2787 VALUE rb_det(VALUE self) { double det = 0.0; try { det = cvDet(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_float_new(det); } |
#dft(flags = CV_DXT_FORWARD, nonzero_rows = 0) ⇒ CvMat
Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.
3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 |
# File 'ext/opencv/cvmat.cpp', line 3010 VALUE rb_dft(int argc, VALUE *argv, VALUE self) { VALUE flag_value, nonzero_row_value; rb_scan_args(argc, argv, "02", &flag_value, &nonzero_row_value); int flags = NIL_P(flag_value) ? CV_DXT_FORWARD : NUM2INT(flag_value); int nonzero_rows = NIL_P(nonzero_row_value) ? 0 : NUM2INT(nonzero_row_value); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvDFT(self_ptr, CVARR(dest), flags, nonzero_rows); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#diag(val = 0) ⇒ CvMat Also known as: diagonal
Returns a specified diagonal of the matrix
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 |
# File 'ext/opencv/cvmat.cpp', line 912 VALUE rb_diag(int argc, VALUE *argv, VALUE self) { VALUE val; if (rb_scan_args(argc, argv, "01", &val) < 1) val = INT2FIX(0); CvMat* diag = NULL; try { diag = cvGetDiag(CVARR(self), RB_CVALLOC(CvMat), NUM2INT(val)); } catch (cv::Exception& e) { cvReleaseMat(&diag); raise_cverror(e); } return DEPEND_OBJECT(rb_klass, diag, self); } |
#dilate([element = nil][,iteration = 1]) ⇒ Object
Create dilates image by using arbitrary structuring element. element is structuring element used for erosion. element should be IplConvKernel. If it is nil, a 3x3 rectangular structuring element is used. iterations is number of times erosion is applied.
4488 4489 4490 4491 4492 |
# File 'ext/opencv/cvmat.cpp', line 4488 VALUE rb_dilate(int argc, VALUE *argv, VALUE self) { return rb_dilate_bang(argc, argv, rb_rcv_clone(self)); } |
#dilate!([element = nil][,iteration = 1]) ⇒ self
Dilate image by using arbitrary structuring element. see also #dilate.
4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 |
# File 'ext/opencv/cvmat.cpp', line 4501 VALUE rb_dilate_bang(int argc, VALUE *argv, VALUE self) { VALUE element, iteration; rb_scan_args(argc, argv, "02", &element, &iteration); IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element); try { cvDilate(CVARR(self), CVARR(self), kernel, IF_INT(iteration, 1)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#dilate_into(dest, element, iteration) ⇒ Object
4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 |
# File 'ext/opencv/cvmat.cpp', line 4516 VALUE rb_dilate_into(VALUE self, VALUE dest, VALUE element, VALUE iteration) { IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element); try { cvDilate(CVARR(self), CVARR(dest), kernel, NUM2INT(iteration)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#dim_size(index) ⇒ Integer
Returns array size along the specified dimension.
982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'ext/opencv/cvmat.cpp', line 982 VALUE rb_dim_size(VALUE self, VALUE index) { int dimsize = 0; try { dimsize = cvGetDimSize(CVARR(self), NUM2INT(index)); } catch (cv::Exception& e) { raise_cverror(e); } return INT2NUM(dimsize); } |
#dims ⇒ Array<Integer>
Returns array dimensions sizes
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'ext/opencv/cvmat.cpp', line 955 VALUE rb_dims(VALUE self) { int size[CV_MAX_DIM]; int dims = 0; try { dims = cvGetDims(CVARR(self), size); } catch (cv::Exception& e) { raise_cverror(e); } VALUE ary = rb_ary_new2(dims); for (int i = 0; i < dims; ++i) { rb_ary_store(ary, i, INT2NUM(size[i])); } return ary; } |
#distance_transform(<i>labels, distance_type, mask_size</i>)) ⇒ Object
5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 |
# File 'ext/opencv/cvmat.cpp', line 5003 VALUE rb_distance_transform(VALUE self, VALUE labels, VALUE distance_type, VALUE mask_size) { if (!(rb_obj_is_kind_of(self, cCvMat::rb_class())) || cvGetElemType(CVARR(self)) != CV_8UC1) rb_raise(rb_eTypeError, "self should be 8-bit single-channel CvMat."); if (labels != Qnil) { if (!(rb_obj_is_kind_of(labels, cCvMat::rb_class())) || cvGetElemType(CVARR(labels)) != CV_32S) rb_raise(rb_eTypeError, "labels should be 32-bit signed single-channel CvMat."); } CvMat* self_ptr = CVMAT(self); VALUE dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_32F, 1); try { const cv::Mat selfMat(CVMAT(self)); cv::Mat destMat(CVMAT(dest)); if (labels != Qnil) { cv::Mat labelsMat(CVMAT(labels)); cv::distanceTransform(selfMat, destMat, labelsMat, NUM2INT(distance_type), NUM2INT(mask_size)); } else { cv::distanceTransform(selfMat, destMat, NUM2INT(distance_type), NUM2INT(mask_size)); } } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#div(val, scale = 1.0) ⇒ CvMat Also known as: /
Performs per-element division of two arrays or a scalar by an array.
1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 |
# File 'ext/opencv/cvmat.cpp', line 1907 VALUE rb_div(int argc, VALUE *argv, VALUE self) { VALUE val, scale; if (rb_scan_args(argc, argv, "11", &val, &scale) < 2) scale = rb_float_new(1.0); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); if (rb_obj_is_kind_of(val, rb_klass)) cvDiv(self_ptr, CVARR(val), CVARR(dest), NUM2DBL(scale)); else { CvScalar scl = VALUE_TO_CVSCALAR(val); VALUE mat = new_mat_kind_object(cvGetSize(self_ptr), self); CvArr* mat_ptr = CVARR(mat); cvSet(mat_ptr, scl); cvDiv(self_ptr, mat_ptr, CVARR(dest), NUM2DBL(scale)); } } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#dot_product(mat) ⇒ Number
WBH started this but didn't end up needing it, so didn't complete debugging (used bounding_rect instead) Note that WBH of 11/2014 tried to revisit this method and was beset with 3 hours of frustration based around the fact that the ROI can only be set via a constructor, but constructing a new object means allocating and returning memory associated with that new object. GL with debugging that, future self.
VALUE rb_set_roi(int argc, VALUE *argv, VALUE self) { VALUE dest, newMat, delta, ksize, rect, scale; rb_scan_args(argc, argv, "1", &rect);
CvMat* self_ptr = CVMAT(self); dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_MAT_DEPTH(self_ptr->type), 1);
cv::Rect cppCvRect; cppCvRect.x = CVRECT(rect)->x; cppCvRect.y = CVRECT(rect)->y;
try { cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); destMat(selfMat(cppCvRect)); } catch (cv::Exception& e) { raise_cverror(e); } return newMat;
}
Calculates the dot product of two arrays in Euclidean metrics.
2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 |
# File 'ext/opencv/cvmat.cpp', line 2607 VALUE rb_dot_product(VALUE self, VALUE mat) { double result = 0.0; try { result = cvDotProduct(CVARR(self), CVARR_WITH_CHECK(mat)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_float_new(result); } |
#draw_chessboard_corners(pattern_size, corners, pattern_was_found) ⇒ nil
Returns an image which is rendered the detected chessboard corners.
pattern_size (CvSize) - Number of inner corners per a chessboard row and column.
corners (Array
5351 5352 5353 5354 5355 |
# File 'ext/opencv/cvmat.cpp', line 5351 VALUE rb_draw_chessboard_corners(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found) { return rb_draw_chessboard_corners_bang(copy(self), pattern_size, corners, pattern_was_found); } |
#draw_chessboard_corners!(pattern_size, corners, pattern_was_found) ⇒ self
Renders the detected chessboard corners.
pattern_size (CvSize) - Number of inner corners per a chessboard row and column.
corners (Array
5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 |
# File 'ext/opencv/cvmat.cpp', line 5367 VALUE rb_draw_chessboard_corners_bang(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found) { Check_Type(corners, T_ARRAY); int count = RARRAY_LEN(corners); CvPoint2D32f* corners_buff = ALLOCA_N(CvPoint2D32f, count); VALUE* corners_ptr = RARRAY_PTR(corners); for (int i = 0; i < count; i++) { corners_buff[i] = *(CVPOINT2D32F(corners_ptr[i])); } try { int found = (pattern_was_found == Qtrue); cvDrawChessboardCorners(CVARR(self), VALUE_TO_CVSIZE(pattern_size), corners_buff, count, found); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#draw_contours(contour, external_color, hole_color, max_level, options) ⇒ Object
Draws contour outlines or interiors in an image.
- contour (CvContour) - Pointer to the first contour
- external_color (CvScalar) - Color of the external contours
- hole_color (CvScalar) - Color of internal contours (holes)
- max_level (Integer) - Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours following it on the same level are drawn. If 2, all contours following and all contours one level below the contours are drawn, and so forth. If the value is negative, the function does not draw the contours following after contour but draws the child contours of contour up to the |max_level| - 1 level.
-
options (Hash) - Drawing options.
- :thickness (Integer) - Thickness of lines the contours are drawn with. If it is negative, the contour interiors are drawn (default: 1).
- :line_type (Integer or Symbol) - Type of the contour segments, see CvMat#line description (default: 8).
5310 5311 5312 5313 5314 |
# File 'ext/opencv/cvmat.cpp', line 5310 VALUE rb_draw_contours(int argc, VALUE *argv, VALUE self) { return rb_draw_contours_bang(argc, argv, copy(self)); } |
#draw_contours!(contour, external_color, hole_color, max_level, options) ⇒ Object
Draws contour outlines or interiors in an image.
see CvMat#draw_contours
5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 |
# File 'ext/opencv/cvmat.cpp', line 5324 VALUE rb_draw_contours_bang(int argc, VALUE *argv, VALUE self) { VALUE contour, external_color, hole_color, max_level, ; rb_scan_args(argc, argv, "41", &contour, &external_color, &hole_color, &max_level, &); = DRAWING_OPTION(); try { cvDrawContours(CVARR(self), CVSEQ_WITH_CHECK(contour), VALUE_TO_CVSCALAR(external_color), VALUE_TO_CVSCALAR(hole_color), NUM2INT(max_level), DO_THICKNESS(), DO_LINE_TYPE()); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#each_col {|col| ... } ⇒ CvMat Also known as: each_column
To return an enumerator if no block is given
Calls block once for each column in the matrix, passing that column as a parameter.
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
# File 'ext/opencv/cvmat.cpp', line 884 VALUE rb_each_col(VALUE self) { int cols = CVMAT(self)->cols; CvMat *col = NULL; for (int i = 0; i < cols; ++i) { try { col = cvGetCol(CVARR(self), RB_CVALLOC(CvMat), i); } catch (cv::Exception& e) { if (col != NULL) cvReleaseMat(&col); raise_cverror(e); } rb_yield(DEPEND_OBJECT(rb_klass, col, self)); } return self; } |
#each_row {|row| ... } ⇒ CvMat
To return an enumerator if no block is given
Calls block once for each row in the matrix, passing that row as a parameter.
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
# File 'ext/opencv/cvmat.cpp', line 857 VALUE rb_each_row(VALUE self) { int rows = CVMAT(self)->rows; CvMat* row = NULL; for (int i = 0; i < rows; ++i) { try { row = cvGetRow(CVARR(self), RB_CVALLOC(CvMat), i); } catch (cv::Exception& e) { if (row != NULL) cvReleaseMat(&row); raise_cverror(e); } rb_yield(DEPEND_OBJECT(rb_klass, row, self)); } return self; } |
#eigenvv ⇒ Array<CvMat>
Computes eigenvalues and eigenvectors of symmetric matrix. self should be symmetric square matrix. self is modified during the processing.
2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 |
# File 'ext/opencv/cvmat.cpp', line 2920 VALUE rb_eigenvv(int argc, VALUE *argv, VALUE self) { VALUE epsilon, lowindex, highindex; rb_scan_args(argc, argv, "03", &epsilon, &lowindex, &highindex); double eps = (NIL_P(epsilon)) ? 0.0 : NUM2DBL(epsilon); int lowidx = (NIL_P(lowindex)) ? -1 : NUM2INT(lowindex); int highidx = (NIL_P(highindex)) ? -1 : NUM2INT(highindex); VALUE eigen_vectors = Qnil, eigen_values = Qnil; CvArr* self_ptr = CVARR(self); try { CvSize size = cvGetSize(self_ptr); int type = cvGetElemType(self_ptr); eigen_vectors = new_object(size, type); eigen_values = new_object(size.height, 1, type); // NOTE: eps, lowidx, highidx are ignored in the current OpenCV implementation. cvEigenVV(self_ptr, CVARR(eigen_vectors), CVARR(eigen_values), eps, lowidx, highidx); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, eigen_vectors, eigen_values); } |
#ellipse(center, axes, angle, start_angle, end_angle, options = nil) ⇒ CvMat
Returns an image that is drawn a simple or thick elliptic arc or fills an ellipse sector.
3260 3261 3262 3263 3264 |
# File 'ext/opencv/cvmat.cpp', line 3260 VALUE rb_ellipse(int argc, VALUE *argv, VALUE self) { return rb_ellipse_bang(argc, argv, rb_rcv_clone(self)); } |
#ellipse!(center, axes, angle, start_angle, end_angle, options = nil) ⇒ CvMat
Draws a simple or thick elliptic arc or fills an ellipse sector.
3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 |
# File 'ext/opencv/cvmat.cpp', line 3286 VALUE rb_ellipse_bang(int argc, VALUE *argv, VALUE self) { VALUE center, axis, angle, start_angle, end_angle, drawing_option; rb_scan_args(argc, argv, "51", ¢er, &axis, &angle, &start_angle, &end_angle, &drawing_option); drawing_option = DRAWING_OPTION(drawing_option); try { cvEllipse(CVARR(self), VALUE_TO_CVPOINT(center), VALUE_TO_CVSIZE(axis), NUM2DBL(angle), NUM2DBL(start_angle), NUM2DBL(end_angle), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#ellipse_box(box, options = nil) ⇒ CvMat
Returns an image that is drawn a simple or thick elliptic arc or fills an ellipse sector.
3324 3325 3326 3327 3328 |
# File 'ext/opencv/cvmat.cpp', line 3324 VALUE rb_ellipse_box(int argc, VALUE *argv, VALUE self) { return rb_ellipse_box_bang(argc, argv, rb_rcv_clone(self)); } |
#ellipse_box!(box, options = nil) ⇒ CvMat
Draws a simple or thick elliptic arc or fills an ellipse sector.
3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 |
# File 'ext/opencv/cvmat.cpp', line 3347 VALUE rb_ellipse_box_bang(int argc, VALUE *argv, VALUE self) { VALUE box, drawing_option; rb_scan_args(argc, argv, "11", &box, &drawing_option); drawing_option = DRAWING_OPTION(drawing_option); try { cvEllipseBox(CVARR(self), VALUE_TO_CVBOX2D(box), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#encode_image(ext, params = nil) ⇒ Array<Integer> Also known as: encode
Encodes an image into a memory buffer.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'ext/opencv/cvmat.cpp', line 224 VALUE rb_encode_imageM(int argc, VALUE *argv, VALUE self) { VALUE _ext, _params; rb_scan_args(argc, argv, "11", &_ext, &_params); Check_Type(_ext, T_STRING); const char* ext = RSTRING_PTR(_ext); CvMat* buff = NULL; int* params = NULL; if (!NIL_P(_params)) { params = hash_to_format_specific_param(_params); } try { buff = cvEncodeImage(ext, CVARR(self), params); } catch (cv::Exception& e) { if (params != NULL) { free(params); params = NULL; } raise_cverror(e); } if (params != NULL) { free(params); params = NULL; } const int size = buff->rows * buff->cols; VALUE array = rb_ary_new2(size); for (int i = 0; i < size; i++) { rb_ary_store(array, i, CHR2FIX(CV_MAT_ELEM(*buff, char, 0, i))); } try { cvReleaseMat(&buff); } catch (cv::Exception& e) { raise_cverror(e); } return array; } |
#eq(val) ⇒ CvMat
Performs the per-element comparison "equal" of two arrays or an array and scalar value.
2130 2131 2132 2133 2134 2135 |
# File 'ext/opencv/cvmat.cpp', line 2130 VALUE rb_eq(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_EQ); } |
#equalize_hist ⇒ Object
Equalize histgram of grayscale of image.
equalizes histogram of the input image using the following algorithm:
- calculate histogram H for src.
- normalize histogram, so that the sum of histogram bins is 255.
- compute integral of the histogram: H’(i) = sum0≤j≤iH(j)
- transform the image using H’ as a look-up table: dst(x,y)=H’(src(x,y)) The algorithm normalizes brightness and increases contrast of the image.
support single-channel 8bit image (grayscale) only.
5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 |
# File 'ext/opencv/cvmat.cpp', line 5764 VALUE rb_equalize_hist(VALUE self) { VALUE dest = Qnil; try { CvArr* self_ptr = CVARR(self); dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvEqualizeHist(self_ptr, CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#erode([element = nil, iteration = 1]) ⇒ Object
Create erodes image by using arbitrary structuring element. element is structuring element used for erosion. element should be IplConvKernel. If it is nil, a 3x3 rectangular structuring element is used. iterations is number of times erosion is applied.
4451 4452 4453 4454 4455 |
# File 'ext/opencv/cvmat.cpp', line 4451 VALUE rb_erode(int argc, VALUE *argv, VALUE self) { return rb_erode_bang(argc, argv, rb_rcv_clone(self)); } |
#erode!([element = nil][,iteration = 1]) ⇒ self
Erodes image by using arbitrary structuring element. see also #erode.
4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 |
# File 'ext/opencv/cvmat.cpp', line 4464 VALUE rb_erode_bang(int argc, VALUE *argv, VALUE self) { VALUE element, iteration; rb_scan_args(argc, argv, "02", &element, &iteration); IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element); try { cvErode(CVARR(self), CVARR(self), kernel, IF_INT(iteration, 1)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#rb_extract_orb(params[,mask]) ⇒ Array
Extracts ORB Features from an image
params (hash) - Various algorithm parameters, allowing the following keys:
:scale_factor - Scale factor used to transform scale level n into scale level n-1. Defaults to 1.2
:n_levels - Number of pyramid levels to consider when keypoints. Defaults to 3
:edge_threshold - Defaults to 31
:first_level - The pyramid level of the image this function is being called on - level 0 is the largest level
of the pyramid, so any value > 0 will generate pyramid levels larger than the original image.
Defaults to 0
:keypoints - If given, should be an array of tuples of [ x, y, size ] describing keypoints to generate
descriptors for. Defaults to nil
:keypoints_only - If true, descriptors will not be generated. Returned value will only be array(hash) containing
keypoints (given keypoints will be ignored). Defaults to false.
:num_keypoints - If given, maximum number of desired keypoints to find. Defaults to 500
mask (CvMat) - The optional input 8-bit mask. The features are only found in the areas that contain more than 50% of non-zero mask pixels.
Returns array of keypoints (array of hashes) and descriptors (cvmat). Keypoints array contains entries with the following keys: 'point' => CvPoint, 'size' => float, 'angle' => float, 'response' => float, 'octave' => float
6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 |
# File 'ext/opencv/cvmat.cpp', line 6415 VALUE rb_extract_orb(int argc, VALUE *argv, VALUE self) { // Commented by WBH until we can research the replacement for cv::ORB::CommonParams (which no longer exists) /* VALUE mask, orb_option; rb_scan_args(argc, argv, "02", &mask, &orb_option); orb_option = ORB_OPTION(orb_option); const cv::Mat selfMat(CVMAT(self)); const CvSize size = cvGetSize(CVARR(self)); cv::Mat descriptorsMat; if (mask == Qnil) { mask = new_object(cvSize(size.width, size.height), CV_MAKETYPE(CV_8U, 1)); cvSet(CVARR(mask), cvScalarAll(255)); } const cv::Mat maskMat(CVMAT(mask)); std::vector<cv::KeyPoint> keypoints; VALUE inputKeypoints = DO_ORB_KEYPOINTS(orb_option); const bool descriptorsOnly = inputKeypoints != Qnil; if (descriptorsOnly) { const int inputKeypointsLength = RARRAY_LEN(inputKeypoints); for (int i = 0; i < inputKeypointsLength; ++i) { VALUE inputKeypoint = rb_ary_entry(inputKeypoints, i); keypoints.push_back(cv::KeyPoint( (float)NUM2DBL(rb_ary_entry(inputKeypoint, 0)), (float)NUM2DBL(rb_ary_entry(inputKeypoint, 1)), (float)NUM2DBL(rb_ary_entry(inputKeypoint, 2)) )); } } try { cv::ORB::CommonParams params(DO_ORB_SCALE_FACTOR(orb_option), DO_ORB_N_LEVELS(orb_option), DO_ORB_EDGE_THRESHOLD(orb_option), DO_ORB_FIRST_LEVEL(orb_option)); cv::ORB featuresFinder(DO_ORB_NUM_KEYPOINTS(orb_option), params); if (DO_ORB_KEYPOINTS_ONLY(orb_option)) { featuresFinder(selfMat, maskMat, keypoints); } else { featuresFinder(selfMat, maskMat, keypoints, descriptorsMat, descriptorsOnly); } } catch (cv::Exception& e) { raise_cverror(e); } VALUE keypointsList = rb_ary_new2(keypoints.size()); for (size_t i = 0; i < keypoints.size(); ++i) { const cv::KeyPoint& keypoint = keypoints[i]; VALUE keypointData = rb_hash_new(); rb_hash_aset(keypointData, rb_str_new2("point"), cCvPoint::new_object(cvPoint(keypoint.pt.x, keypoint.pt.y))); rb_hash_aset(keypointData, rb_str_new2("size"), rb_float_new(keypoint.size)); rb_hash_aset(keypointData, rb_str_new2("angle"), rb_float_new(keypoint.angle)); rb_hash_aset(keypointData, rb_str_new2("response"), rb_float_new(keypoint.response)); rb_hash_aset(keypointData, rb_str_new2("octave"), rb_float_new(keypoint.octave)); rb_ary_store(keypointsList, i, keypointData); } VALUE result = Qnil; if (DO_ORB_KEYPOINTS_ONLY(orb_option)) { result = keypointsList; } else { CvMat descriptorsCvMat = descriptorsMat; VALUE descriptors = new_mat_kind_object(cvGetSize(&descriptorsCvMat), self, CV_8U, 1); cvCopy(&descriptorsCvMat, CVMAT(descriptors)); if (descriptorsOnly) { result = descriptors; } else { result = rb_ary_new2(2); rb_ary_store(result, 0, keypointsList); rb_ary_store(result, 1, descriptors); } } return result; */ } |
#extract_surf(params, mask = nil) ⇒ Array<CvSeq<CvSURFPoint>, Array<float>>
Extracts Speeded Up Robust Features from an image
6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 |
# File 'ext/opencv/cvmat.cpp', line 6353 VALUE rb_extract_surf(int argc, VALUE *argv, VALUE self) { VALUE _params, _mask; rb_scan_args(argc, argv, "11", &_params, &_mask); // Prepare arguments CvSURFParams params = *CVSURFPARAMS_WITH_CHECK(_params); CvMat* mask = MASK(_mask); VALUE storage = cCvMemStorage::new_object(); CvSeq* keypoints = NULL; CvSeq* descriptors = NULL; // Compute SURF keypoints and descriptors try { cvExtractSURF(CVARR(self), mask, &keypoints, &descriptors, CVMEMSTORAGE(storage), params, 0); } catch (cv::Exception& e) { raise_cverror(e); } VALUE _keypoints = cCvSeq::new_sequence(cCvSeq::rb_class(), keypoints, cCvSURFPoint::rb_class(), storage); // Create descriptor array const int DIM_SIZE = (params.extended) ? 128 : 64; const int NUM_KEYPOINTS = keypoints->total; VALUE _descriptors = rb_ary_new2(NUM_KEYPOINTS); for (int m = 0; m < NUM_KEYPOINTS; ++m) { VALUE elem = rb_ary_new2(DIM_SIZE); float *descriptor = (float*)cvGetSeqElem(descriptors, m); for (int n = 0; n < DIM_SIZE; ++n) { rb_ary_store(elem, n, rb_float_new(descriptor[n])); } rb_ary_store(_descriptors, m, elem); } return rb_assoc_new(_keypoints, _descriptors); } |
#fill_convex_poly(points, options = nil) ⇒ CvMat
Returns an image that is filled a convex polygon.
3458 3459 3460 3461 3462 |
# File 'ext/opencv/cvmat.cpp', line 3458 VALUE rb_fill_convex_poly(int argc, VALUE *argv, VALUE self) { return rb_fill_convex_poly_bang(argc, argv, rb_rcv_clone(self)); } |
#fill_convex_poly!(points, options = nil) ⇒ CvMat
Fills a convex polygon.
3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 |
# File 'ext/opencv/cvmat.cpp', line 3480 VALUE rb_fill_convex_poly_bang(int argc, VALUE *argv, VALUE self) { VALUE points, drawing_option; int i, num_points; CvPoint *p; rb_scan_args(argc, argv, "11", &points, &drawing_option); Check_Type(points, T_ARRAY); drawing_option = DRAWING_OPTION(drawing_option); num_points = RARRAY_LEN(points); p = ALLOCA_N(CvPoint, num_points); for (i = 0; i < num_points; ++i) p[i] = VALUE_TO_CVPOINT(rb_ary_entry(points, i)); try { cvFillConvexPoly(CVARR(self), p, num_points, DO_COLOR(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#fill_poly(points, options = nil) ⇒ CvMat
Returns an image that is filled the area bounded by one or more polygons.
3382 3383 3384 3385 3386 |
# File 'ext/opencv/cvmat.cpp', line 3382 VALUE rb_fill_poly(int argc, VALUE *argv, VALUE self) { return rb_fill_poly_bang(argc, argv, self); } |
#fill_poly!(points, options = nil) ⇒ CvMat
Fills the area bounded by one or more polygons.
3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 |
# File 'ext/opencv/cvmat.cpp', line 3404 VALUE rb_fill_poly_bang(int argc, VALUE *argv, VALUE self) { VALUE polygons, drawing_option; VALUE points; int i, j; int num_polygons; int *num_points; CvPoint **p; rb_scan_args(argc, argv, "11", &polygons, &drawing_option); Check_Type(polygons, T_ARRAY); drawing_option = DRAWING_OPTION(drawing_option); num_polygons = RARRAY_LEN(polygons); num_points = ALLOCA_N(int, num_polygons); p = ALLOCA_N(CvPoint*, num_polygons); for (j = 0; j < num_polygons; ++j) { points = rb_ary_entry(polygons, j); Check_Type(points, T_ARRAY); num_points[j] = RARRAY_LEN(points); p[j] = ALLOCA_N(CvPoint, num_points[j]); for (i = 0; i < num_points[j]; ++i) { p[j][i] = VALUE_TO_CVPOINT(rb_ary_entry(points, i)); } } try { cvFillPoly(CVARR(self), p, num_points, num_polygons, DO_COLOR(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#filter2d(kernel[,anchor]) ⇒ Object
Convolves image with the kernel. Convolution kernel, single-channel floating point matrix (or same depth of self's). If you want to apply different kernels to different channels, split the image using CvMat#split into separate color planes and process them individually.
4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 |
# File 'ext/opencv/cvmat.cpp', line 4761 VALUE rb_filter2d(int argc, VALUE *argv, VALUE self) { VALUE _kernel, _anchor; rb_scan_args(argc, argv, "11", &_kernel, &_anchor); CvMat* kernel = CVMAT_WITH_CHECK(_kernel); CvArr* self_ptr = CVARR(self); VALUE _dest = Qnil; try { _dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvFilter2D(self_ptr, CVARR(_dest), kernel, NIL_P(_anchor) ? cvPoint(-1,-1) : VALUE_TO_CVPOINT(_anchor)); } catch (cv::Exception& e) { raise_cverror(e); } return _dest; } |
#find_chessboard_corners(pattern_size, flag = CV_CALIB_CB_ADAPTIVE_THRESH) ⇒ Array<Array<CvPoint2D32f>, Boolean>
Finds the positions of internal corners of the chessboard.
3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 |
# File 'ext/opencv/cvmat.cpp', line 3975 VALUE rb_find_chessboard_corners(int argc, VALUE *argv, VALUE self) { VALUE pattern_size_val, flag_val; rb_scan_args(argc, argv, "11", &pattern_size_val, &flag_val); int flag = NIL_P(flag_val) ? CV_CALIB_CB_ADAPTIVE_THRESH : NUM2INT(flag_val); CvSize pattern_size = VALUE_TO_CVSIZE(pattern_size_val); CvPoint2D32f* corners = ALLOCA_N(CvPoint2D32f, pattern_size.width * pattern_size.height); int num_found_corners = 0; int pattern_was_found = 0; try { pattern_was_found = cvFindChessboardCorners(CVARR(self), pattern_size, corners, &num_found_corners, flag); } catch (cv::Exception& e) { raise_cverror(e); } VALUE found_corners = rb_ary_new2(num_found_corners); for (int i = 0; i < num_found_corners; i++) { rb_ary_store(found_corners, i, cCvPoint2D32f::new_object(corners[i])); } VALUE found = (pattern_was_found > 0) ? Qtrue : Qfalse; return rb_assoc_new(found_corners, found); } |
#find_contours(find_contours_options) ⇒ CvContour, CvChain
Finds contours in binary image.
5246 5247 5248 5249 5250 |
# File 'ext/opencv/cvmat.cpp', line 5246 VALUE rb_find_contours(int argc, VALUE *argv, VALUE self) { return rb_find_contours_bang(argc, argv, copy(self)); } |
#find_contours!(find_contours_options) ⇒ CvContour, CvChain
Finds contours in binary image.
5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 |
# File 'ext/opencv/cvmat.cpp', line 5260 VALUE rb_find_contours_bang(int argc, VALUE *argv, VALUE self) { VALUE find_contours_option, klass, element_klass, storage; rb_scan_args(argc, argv, "01", &find_contours_option); CvSeq *contour = NULL; find_contours_option = FIND_CONTOURS_OPTION(find_contours_option); int mode = FC_MODE(find_contours_option); int method = FC_METHOD(find_contours_option); int header_size; if (method == CV_CHAIN_CODE) { klass = cCvChain::rb_class(); element_klass = T_FIXNUM; header_size = sizeof(CvChain); } else { klass = cCvContour::rb_class(); element_klass = cCvPoint::rb_class(); header_size = sizeof(CvContour); } storage = cCvMemStorage::new_object(); int count = 0; try { count = cvFindContours(CVARR(self), CVMEMSTORAGE(storage), &contour, header_size, mode, method, FC_OFFSET(find_contours_option)); } catch (cv::Exception& e) { raise_cverror(e); } if (count == 0) return Qnil; else return cCvSeq::new_sequence(klass, contour, element_klass, storage); } |
#find_corner_sub_pix(corners, win_size, zero_zone, criteria) ⇒ Array<CvPoint2D32f>
Refines the corner locations.
4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 |
# File 'ext/opencv/cvmat.cpp', line 4014 VALUE rb_find_corner_sub_pix(VALUE self, VALUE corners, VALUE win_size, VALUE zero_zone, VALUE criteria) { Check_Type(corners, T_ARRAY); int count = RARRAY_LEN(corners); CvPoint2D32f* corners_buff = ALLOCA_N(CvPoint2D32f, count); VALUE* corners_ptr = RARRAY_PTR(corners); for (int i = 0; i < count; i++) { corners_buff[i] = *(CVPOINT2D32F(corners_ptr[i])); } try { cvFindCornerSubPix(CVARR(self), corners_buff, count, VALUE_TO_CVSIZE(win_size), VALUE_TO_CVSIZE(zero_zone), VALUE_TO_CVTERMCRITERIA(criteria)); } catch (cv::Exception& e) { raise_cverror(e); } VALUE refined_corners = rb_ary_new2(count); for (int i = 0; i < count; i++) { rb_ary_store(refined_corners, i, cCvPoint2D32f::new_object(corners_buff[i])); } return refined_corners; } |
#fit_ellipse ⇒ CvBox2D
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
# File 'ext/opencv/cvmat.cpp', line 1316 VALUE rb_fit_ellipse(VALUE self) { VALUE box = cCvBox2D::new_object(); try { const cv::Mat selfMat(CVMAT(self)); *CVBOX2D(box) = cv::fitEllipse(selfMat); } catch (cv::Exception& e) { raise_cverror(e); } return box; } |
#fit_line ⇒ Object
self should be 2-channel or 3-channel mat (where channels are [x,y] or [x,y,z])
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 |
# File 'ext/opencv/cvmat.cpp', line 1297 VALUE rb_fit_line(VALUE self, VALUE dest, VALUE distType, VALUE param, VALUE reps, VALUE aeps) { try { const cv::Mat selfMat(CVMAT(self)); cv::Mat destMat(CVMAT(dest)); cv::fitLine(selfMat, destMat, NUM2INT(distType), NUM2DBL(param), NUM2DBL(reps), NUM2DBL(aeps)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#flip(flip_mode) ⇒ CvMat
Returns a fliped 2D array around vertical, horizontal, or both axes.
1498 1499 1500 1501 1502 |
# File 'ext/opencv/cvmat.cpp', line 1498 VALUE rb_flip(int argc, VALUE *argv, VALUE self) { return rb_flip_bang(argc, argv, copy(self)); } |
#flip!(flip_mode) ⇒ CvMat
Flips a 2D array around vertical, horizontal, or both axes.
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'ext/opencv/cvmat.cpp', line 1512 VALUE rb_flip_bang(int argc, VALUE *argv, VALUE self) { VALUE format; int mode = 1; if (rb_scan_args(argc, argv, "01", &format) > 0) { Check_Type(format, T_SYMBOL); ID flip_mode = rb_to_id(format); if (flip_mode == rb_intern("x")) { mode = 1; } else if (flip_mode == rb_intern("y")) { mode = 0; } else if (flip_mode == rb_intern("xy")) { mode = -1; } } try { cvFlip(CVARR(self), NULL, mode); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#flood_fill(seed_point, new_val, lo_diff = CvScalar.new(0), up_diff = CvScalar.new(0), flood_fill_option = nil) ⇒ Array<CvMat, CvConnectedComp>
Fills a connected component with the given color.
5140 5141 5142 5143 5144 |
# File 'ext/opencv/cvmat.cpp', line 5140 VALUE rb_flood_fill(int argc, VALUE *argv, VALUE self) { return rb_flood_fill_bang(argc, argv, copy(self)); } |
#flood_fill!(seed_point, new_val, lo_diff = CvScalar.new(0), up_diff = CvScalar.new(0), flood_fill_option = nil) ⇒ Object
Fills a connected component with the given color.
5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 |
# File 'ext/opencv/cvmat.cpp', line 5154 VALUE rb_flood_fill_bang(int argc, VALUE *argv, VALUE self) { VALUE seed_point, new_val, lo_diff, up_diff, flood_fill_option; rb_scan_args(argc, argv, "23", &seed_point, &new_val, &lo_diff, &up_diff, &flood_fill_option); flood_fill_option = FLOOD_FILL_OPTION(flood_fill_option); int flags = FF_CONNECTIVITY(flood_fill_option); if (FF_FIXED_RANGE(flood_fill_option)) { flags |= CV_FLOODFILL_FIXED_RANGE; } if (FF_MASK_ONLY(flood_fill_option)) { flags |= CV_FLOODFILL_MASK_ONLY; } cv::Rect rect; VALUE mask = FF_MASK(flood_fill_option); try { if (mask == Qnil) { CvSize size = cvGetSize(CVARR(self)); mask = new_object(cvSize(size.width + 2, size.height + 2), CV_MAKETYPE(CV_8U, 1)); cvSetZero(CVARR(mask)); } cv::Mat selfMat(CVMAT(self)); cv::Mat maskMat(CVMAT(mask)); cv::floodFill( selfMat, maskMat, cv::Point(VALUE_TO_CVPOINT(seed_point)), cv::Scalar(VALUE_TO_CVSCALAR(new_val)), &rect, cv::Scalar(NIL_P(lo_diff) ? cvScalar(0) : VALUE_TO_CVSCALAR(lo_diff)), cv::Scalar(NIL_P(up_diff) ? cvScalar(0) : VALUE_TO_CVSCALAR(up_diff)), flags); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(3, self, cCvRect::new_object(cvRect(rect.x, rect.y, rect.width, rect.height)), mask); } |
#flood_fill_mask(seed_point, mask, lo_diff, up_diff, connectivity, fixed_range) ⇒ Object
5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 |
# File 'ext/opencv/cvmat.cpp', line 5195 VALUE rb_flood_fill_mask(VALUE self, VALUE seed_point, VALUE mask, VALUE lo_diff, VALUE up_diff, VALUE connectivity, VALUE fixed_range) { int flags = NUM2INT(connectivity); if (RTEST(fixed_range)) { flags |= CV_FLOODFILL_FIXED_RANGE; } flags |= CV_FLOODFILL_MASK_ONLY; cv::Rect rect; try { cv::Mat selfMat(CVMAT(self)); cv::Mat maskMat(CVMAT(mask)); cv::floodFill( selfMat, maskMat, cv::Point(VALUE_TO_CVPOINT(seed_point)), cv::Scalar(cvScalar(0)), &rect, cv::Scalar(NIL_P(lo_diff) ? cvScalar(0) : VALUE_TO_CVSCALAR(lo_diff)), cv::Scalar(NIL_P(up_diff) ? cvScalar(0) : VALUE_TO_CVSCALAR(up_diff)), flags); } catch (cv::Exception& e) { raise_cverror(e); } return cCvRect::new_object(cvRect(rect.x, rect.y, rect.width, rect.height)); } |
#ge(val) ⇒ CvMat
Performs the per-element comparison "greater than or equal" of two arrays or an array and scalar value.
2162 2163 2164 2165 2166 2167 |
# File 'ext/opencv/cvmat.cpp', line 2162 VALUE rb_ge(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_GE); } |
#get_cols(<i>n</i>)) ⇒ Return column #get_cols(<i>n1, n2, ...</i>)) ⇒ Return Array of columns
Return column(or columns) of matrix. argument should be Fixnum or CvSlice compatible object.
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'ext/opencv/cvmat.cpp', line 821 VALUE rb_get_cols(VALUE self, VALUE args) { 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; 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); } } catch (cv::Exception& e) { if (col != NULL) cvReleaseMat(&col); 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); } |
#get_rows(<i>n</i>)) ⇒ Return row #get_rows(<i>n1, n2, ...</i>)) ⇒ Return Array of row
Return row(or rows) of matrix. argument should be Fixnum or CvSlice compatible object.
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'ext/opencv/cvmat.cpp', line 783 VALUE rb_get_rows(VALUE self, VALUE args) { 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* row = NULL; 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); } } catch (cv::Exception& e) { if (row != NULL) cvReleaseMat(&row); 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); } |
#good_features_to_track(quality_level, min_distance, good_features_to_track_option = {}) ⇒ Array<CvPoint2D32f>
Determines strong corners on an image.
4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 |
# File 'ext/opencv/cvmat.cpp', line 4062 VALUE rb_good_features_to_track(int argc, VALUE *argv, VALUE self) { VALUE quality_level, min_distance, good_features_to_track_option; rb_scan_args(argc, argv, "21", &quality_level, &min_distance, &good_features_to_track_option); good_features_to_track_option = GOOD_FEATURES_TO_TRACK_OPTION(good_features_to_track_option); int np = GF_MAX(good_features_to_track_option); if (np <= 0) rb_raise(rb_eArgError, "option :max should be positive value."); CvMat *self_ptr = CVMAT(self); CvPoint2D32f *p32 = (CvPoint2D32f*)rb_cvAlloc(sizeof(CvPoint2D32f) * np); int type = CV_MAKETYPE(CV_32F, 1); CvMat* eigen = rb_cvCreateMat(self_ptr->rows, self_ptr->cols, type); CvMat* tmp = rb_cvCreateMat(self_ptr->rows, self_ptr->cols, type); try { cvGoodFeaturesToTrack(self_ptr, &eigen, &tmp, p32, &np, NUM2DBL(quality_level), NUM2DBL(min_distance), GF_MASK(good_features_to_track_option), GF_BLOCK_SIZE(good_features_to_track_option), GF_USE_HARRIS(good_features_to_track_option), GF_K(good_features_to_track_option)); } catch (cv::Exception& e) { if (eigen != NULL) cvReleaseMat(&eigen); if (tmp != NULL) cvReleaseMat(&tmp); if (p32 != NULL) cvFree(&p32); raise_cverror(e); } VALUE corners = rb_ary_new2(np); for (int i = 0; i < np; ++i) rb_ary_store(corners, i, cCvPoint2D32f::new_object(p32[i])); cvFree(&p32); cvReleaseMat(&eigen); cvReleaseMat(&tmp); return corners; } |
#grab_cut ⇒ Object
Does grab cut segmentation.
5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 |
# File 'ext/opencv/cvmat.cpp', line 5483 VALUE rb_grab_cut(VALUE self, VALUE mask, VALUE rect, VALUE bgdModel, VALUE fgdModel, VALUE iterCount, VALUE mode) { if (!(rb_obj_is_kind_of(self, cCvMat::rb_class())) || cvGetElemType(CVARR(self)) != CV_8UC3) rb_raise(rb_eTypeError, "image (self) should be 8-bit 3-channel image."); if (!(rb_obj_is_kind_of(mask, cCvMat::rb_class())) || cvGetElemType(CVARR(mask)) != CV_8UC1) rb_raise(rb_eTypeError, "argument 1 (mask) should be mask image."); const int INVALID_TYPE = -1; int valid_mode = CVMETHOD("GRAB_CUT_MODE", mode, INVALID_TYPE); try { const cv::Mat selfMat(CVMAT(self)); cv::Mat maskMat(CVMAT(mask)); cv::Mat bgMat(CVMAT(bgdModel)); cv::Mat fgMat(CVMAT(fgdModel)); cv::grabCut(selfMat, maskMat, VALUE_TO_CVRECT(rect), bgMat, fgMat, NUM2INT(iterCount), valid_mode); } catch (cv::Exception& e) { raise_cverror(e); } return mask; } |
#grab_cut2 ⇒ Array, ...
Does grab cut segmentation.
5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 |
# File 'ext/opencv/cvmat.cpp', line 5514 VALUE rb_grab_cut2(VALUE self, VALUE mask, VALUE rect, VALUE bgdModel, VALUE fgdModel, VALUE iterCount, VALUE mode, VALUE bgdLabels, VALUE fgdLabels, VALUE bgdCenters, VALUE fgdCenters) { if (!(rb_obj_is_kind_of(self, cCvMat::rb_class())) || cvGetElemType(CVARR(self)) != CV_8UC3) rb_raise(rb_eTypeError, "image (self) should be 8-bit 3-channel image."); if (!(rb_obj_is_kind_of(mask, cCvMat::rb_class())) || cvGetElemType(CVARR(mask)) != CV_8UC1) rb_raise(rb_eTypeError, "argument 1 (mask) should be mask image."); const int INVALID_TYPE = -1; int valid_mode = CVMETHOD("GRAB_CUT_MODE", mode, INVALID_TYPE); try { const cv::Mat selfMat(CVMAT(self)); cv::Mat maskMat(CVMAT(mask)); cv::Mat bgMat(CVMAT(bgdModel)); cv::Mat fgMat(CVMAT(fgdModel)); int labelsMode = cv::GC_LABELS_INIT_KMEANS; if (bgdLabels == Qnil) { bgdLabels = new_object(cvSize(1, 1), CV_MAKETYPE(CV_32F, 2)); cvSetZero(CVARR(bgdLabels)); } else { labelsMode = cv::GC_LABELS_USE_INITIAL; } cv::Mat bgdLabelsMat(CVMAT(bgdLabels)); if (fgdLabels == Qnil) { fgdLabels = new_object(cvSize(1, 1), CV_MAKETYPE(CV_32F, 2)); cvSetZero(CVARR(fgdLabels)); } else { labelsMode = cv::GC_LABELS_USE_INITIAL; } cv::Mat fgdLabelsMat(CVMAT(fgdLabels)); int centersMode = cv::GC_CENTERS_MODE_INIT_RANDOM; if (bgdCenters == Qnil) { // K=5 (# of clusters) for 3-dimensions (RGB) bgdCenters = new_object(cvSize(3, 5), CV_MAKETYPE(CV_32F, 2)); cvSetZero(CVARR(bgdCenters)); } else { centersMode = cv::GC_CENTERS_MODE_USE_INITIAL; } cv::Mat bgdCentersMat(CVMAT(bgdCenters)); if (fgdCenters == Qnil) { // K=5 (# of clusters) for 3-dimensions (RGB) fgdCenters = new_object(cvSize(3, 5), CV_MAKETYPE(CV_32F, 2)); cvSetZero(CVARR(fgdCenters)); } else { centersMode = cv::GC_CENTERS_MODE_USE_INITIAL; } cv::Mat fgdCentersMat(CVMAT(fgdCenters)); cv::grabCut2(selfMat, maskMat, VALUE_TO_CVRECT(rect), bgMat, fgMat, bgdLabelsMat, fgdLabelsMat, bgdCentersMat, fgdCentersMat, NUM2INT(iterCount), valid_mode, labelsMode, centersMode); CvMat bgdLabelsTmp = bgdLabelsMat; bgdLabels = new_object(bgdLabelsTmp.rows, bgdLabelsTmp.cols, bgdLabelsTmp.type); cvCopy(&bgdLabelsTmp, CVMAT(bgdLabels)); CvMat fgdLabelsTmp = fgdLabelsMat; fgdLabels = new_object(fgdLabelsTmp.rows, fgdLabelsTmp.cols, fgdLabelsTmp.type); cvCopy(&fgdLabelsTmp, CVMAT(fgdLabels)); CvMat bgdCentersTmp = bgdCentersMat; bgdCenters = new_object(bgdCentersTmp.rows, bgdCentersTmp.cols, bgdCentersTmp.type); cvCopy(&bgdCentersTmp, CVMAT(bgdCenters)); CvMat fgdCentersTmp = fgdCentersMat; fgdCenters = new_object(fgdCentersTmp.rows, fgdCentersTmp.cols, fgdCentersTmp.type); cvCopy(&fgdCentersTmp, CVMAT(fgdCenters)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(5, mask, bgdLabels, fgdLabels, bgdCenters, fgdCenters); } |
#gt(val) ⇒ CvMat
Performs the per-element comparison "greater than" of two arrays or an array and scalar value.
2146 2147 2148 2149 2150 2151 |
# File 'ext/opencv/cvmat.cpp', line 2146 VALUE rb_gt(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_GT); } |
#rows ⇒ Integer Also known as: rows
Returns number of rows of the matrix.
449 450 451 452 453 |
# File 'ext/opencv/cvmat.cpp', line 449 VALUE rb_height(VALUE self) { return INT2NUM(CVMAT(self)->height); } |
#hough_circles(method, dp, min_dist, param1, param2, min_radius = 0, max_radius = 0) ⇒ CvSeq<CvCircle32f>
Finds circles in a grayscale image using the Hough transform.
5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 |
# File 'ext/opencv/cvmat.cpp', line 5698 VALUE rb_hough_circles(int argc, VALUE *argv, VALUE self) { const int INVALID_TYPE = -1; VALUE method, dp, min_dist, param1, param2, min_radius, max_radius, storage; rb_scan_args(argc, argv, "52", &method, &dp, &min_dist, ¶m1, ¶m2, &min_radius, &max_radius); storage = cCvMemStorage::new_object(); int method_flag = CVMETHOD("HOUGH_TRANSFORM_METHOD", method, INVALID_TYPE); if (method_flag == INVALID_TYPE) rb_raise(rb_eArgError, "Invalid method: %d", method_flag); CvSeq *seq = NULL; try { seq = cvHoughCircles(CVARR(self), CVMEMSTORAGE(storage), method_flag, NUM2DBL(dp), NUM2DBL(min_dist), NUM2DBL(param1), NUM2DBL(param2), IF_INT(min_radius, 0), IF_INT(max_radius, 0)); } catch (cv::Exception& e) { raise_cverror(e); } return cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvCircle32f::rb_class(), storage); } |
#hough_lines(method, rho, theta, threshold, param1, param2) ⇒ CvSeq<CvLine, CvTwoPoints>
Finds lines in binary image using a Hough transform.
5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 |
# File 'ext/opencv/cvmat.cpp', line 5644 VALUE rb_hough_lines(int argc, VALUE *argv, VALUE self) { const int INVALID_TYPE = -1; VALUE method, rho, theta, threshold, p1, p2; rb_scan_args(argc, argv, "42", &method, &rho, &theta, &threshold, &p1, &p2); int method_flag = CVMETHOD("HOUGH_TRANSFORM_METHOD", method, INVALID_TYPE); if (method_flag == INVALID_TYPE) rb_raise(rb_eArgError, "Invalid method: %d", method_flag); VALUE storage = cCvMemStorage::new_object(); CvSeq *seq = NULL; try { seq = cvHoughLines2(CVARR(copy(self)), CVMEMSTORAGE(storage), method_flag, NUM2DBL(rho), NUM2DBL(theta), NUM2INT(threshold), IF_DBL(p1, 0), IF_DBL(p2, 0)); } catch (cv::Exception& e) { raise_cverror(e); } switch (method_flag) { case CV_HOUGH_STANDARD: case CV_HOUGH_MULTI_SCALE: return cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvLine::rb_class(), storage); break; case CV_HOUGH_PROBABILISTIC: return cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvTwoPoints::rb_class(), storage); break; default: break; } return Qnil; } |
#identity(value) ⇒ CvMat
Returns a scaled identity matrix. arr(i, j) = value if i = j, 0 otherwise
1368 1369 1370 1371 1372 |
# File 'ext/opencv/cvmat.cpp', line 1368 VALUE rb_set_identity(int argc, VALUE *argv, VALUE self) { return rb_set_identity_bang(argc, argv, copy(self)); } |
#identity!(value) ⇒ CvMat
Initializes a scaled identity matrix. arr(i, j) = value if i = j, 0 otherwise
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 |
# File 'ext/opencv/cvmat.cpp', line 1382 VALUE rb_set_identity_bang(int argc, VALUE *argv, VALUE self) { VALUE val; CvScalar value; if (rb_scan_args(argc, argv, "01", &val) < 1) value = cvRealScalar(1); else value = VALUE_TO_CVSCALAR(val); try { cvSetIdentity(CVARR(self), value); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#in_range(min, max) ⇒ CvMat
Checks if array elements lie between the elements of two other arrays.
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 |
# File 'ext/opencv/cvmat.cpp', line 2227 VALUE rb_in_range(VALUE self, VALUE min, VALUE max) { CvArr* self_ptr = CVARR(self); CvSize size = cvGetSize(self_ptr); VALUE dest = new_object(size, CV_8UC1); try { if (rb_obj_is_kind_of(min, rb_klass) && rb_obj_is_kind_of(max, rb_klass)) cvInRange(self_ptr, CVARR(min), CVARR(max), CVARR(dest)); else if (rb_obj_is_kind_of(min, rb_klass)) { VALUE tmp = new_object(size, cvGetElemType(self_ptr)); cvSet(CVARR(tmp), VALUE_TO_CVSCALAR(max)); cvInRange(self_ptr, CVARR(min), CVARR(tmp), CVARR(dest)); } else if (rb_obj_is_kind_of(max, rb_klass)) { VALUE tmp = new_object(size, cvGetElemType(self_ptr)); cvSet(CVARR(tmp), VALUE_TO_CVSCALAR(min)); cvInRange(self_ptr, CVARR(tmp), CVARR(max), CVARR(dest)); } else cvInRangeS(self_ptr, VALUE_TO_CVSCALAR(min), VALUE_TO_CVSCALAR(max), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#inpaint(inpaint_method, mask, radius) ⇒ Object
Inpaints the selected region in the image The radius of circlular neighborhood of each point inpainted that is considered by the algorithm.
5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 |
# File 'ext/opencv/cvmat.cpp', line 5729 VALUE rb_inpaint(VALUE self, VALUE inpaint_method, VALUE mask, VALUE radius) { const int INVALID_TYPE = -1; VALUE dest = Qnil; int method = CVMETHOD("INPAINT_METHOD", inpaint_method, INVALID_TYPE); if (method == INVALID_TYPE) rb_raise(rb_eArgError, "Invalid method"); try { CvArr* self_ptr = CVARR(self); dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvInpaint(self_ptr, MASK(mask), CVARR(dest), NUM2DBL(radius), method); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#inside?(point) ⇒ Boolean #inside?(rect) ⇒ Boolean
Tests whether a coordinate or rectangle is inside of the matrix
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'ext/opencv/cvmat.cpp', line 376 VALUE rb_inside_q(VALUE self, VALUE object) { if (cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)) { CvMat *mat = CVMAT(self); int x = NUM2INT(rb_funcall(object, rb_intern("x"), 0)); int y = NUM2INT(rb_funcall(object, rb_intern("y"), 0)); if (cCvRect::rb_compatible_q(cCvRect::rb_class(), object)) { int width = NUM2INT(rb_funcall(object, rb_intern("width"), 0)); int height = NUM2INT(rb_funcall(object, rb_intern("height"), 0)); return (x >= 0) && (y >= 0) && (x < mat->width) && ((x + width) < mat->width) && (y < mat->height) && ((y + height) < mat->height) ? Qtrue : Qfalse; } else { return (x >= 0) && (y >= 0) && (x < mat->width) && (y < mat->height) ? Qtrue : Qfalse; } } rb_raise(rb_eArgError, "argument 1 should have method \"x\", \"y\""); return Qnil; } |
#integral(need_sqsum = false, need_tilted_sum = false) ⇒ Array?
Calculates integral images. If need_sqsum = true, calculate the integral image for squared pixel values. If need_tilted_sum = true, calculate the integral for the image rotated by 45 degrees.
sum(X,Y)=sumx<X,y<Yimage(x,y)
sqsum(X,Y)=sumx<X,y<Yimage(x,y)2
tilted_sum(X,Y)=sumy<Y,abs(x-X)<yimage(x,y)
Using these integral images, one may calculate sum, mean, standard deviation over arbitrary up-right or rotated rectangular region of the image in a constant time.
4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 |
# File 'ext/opencv/cvmat.cpp', line 4837 VALUE rb_integral(int argc, VALUE *argv, VALUE self) { VALUE need_sqsum = Qfalse, need_tiled_sum = Qfalse; rb_scan_args(argc, argv, "02", &need_sqsum, &need_tiled_sum); VALUE sum = Qnil; VALUE sqsum = Qnil; VALUE tiled_sum = Qnil; CvArr* self_ptr = CVARR(self); try { CvSize self_size = cvGetSize(self_ptr); CvSize size = cvSize(self_size.width + 1, self_size.height + 1); int type_cv64fcn = CV_MAKETYPE(CV_64F, CV_MAT_CN(cvGetElemType(self_ptr))); sum = cCvMat::new_object(size, type_cv64fcn); sqsum = (need_sqsum == Qtrue ? cCvMat::new_object(size, type_cv64fcn) : Qnil); tiled_sum = (need_tiled_sum == Qtrue ? cCvMat::new_object(size, type_cv64fcn) : Qnil); cvIntegral(self_ptr, CVARR(sum), (need_sqsum == Qtrue) ? CVARR(sqsum) : NULL, (need_tiled_sum == Qtrue) ? CVARR(tiled_sum) : NULL); } catch (cv::Exception& e) { raise_cverror(e); } if ((need_sqsum != Qtrue) && (need_tiled_sum != Qtrue)) return sum; else { VALUE dest = rb_ary_new3(1, sum); if (need_sqsum == Qtrue) rb_ary_push(dest, sqsum); if (need_tiled_sum == Qtrue) rb_ary_push(dest, tiled_sum); return dest; } } |
#invert(inversion_method = :lu) ⇒ Number
Finds inverse or pseudo-inverse of matrix.
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 |
# File 'ext/opencv/cvmat.cpp', line 2811 VALUE rb_invert(int argc, VALUE *argv, VALUE self) { VALUE symbol; rb_scan_args(argc, argv, "01", &symbol); int method = CVMETHOD("INVERSION_METHOD", symbol, CV_LU); VALUE dest = Qnil; CvArr* self_ptr = CVARR(self); try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvInvert(self_ptr, CVARR(dest), method); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#kmeans(k, termcrit) ⇒ Object
5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 |
# File 'ext/opencv/cvmat.cpp', line 5464 VALUE rb_kmeans(VALUE self, VALUE k, VALUE termcrit) { VALUE labels = new_object(CVMAT(self)->height, 1, CV_32SC1); try { cvKMeans2(CVARR(self), NUM2INT(k), CVARR(labels), *CVTERMCRITERIA(termcrit)); } catch (cv::Exception& e) { raise_cverror(e); } return labels; } |
#laplace(aperture_size = 3) ⇒ Object
Calculates the Laplacian of an image.
3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 |
# File 'ext/opencv/cvmat.cpp', line 3728 VALUE rb_laplace(int argc, VALUE *argv, VALUE self) { VALUE aperture_size, dest; if (rb_scan_args(argc, argv, "01", &aperture_size) < 1) aperture_size = INT2FIX(3); CvMat* self_ptr = CVMAT(self); switch(CV_MAT_DEPTH(self_ptr->type)) { case CV_8U: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_8U, 1); break; case CV_32F: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_32F, 1); break; default: rb_raise(rb_eArgError, "source depth should be CV_8U or CV_32F."); } try { cvLaplace(self_ptr, CVARR(dest), NUM2INT(aperture_size)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#laplace2(<i>ksize = 1, scale = 1, delta = 0</i>)) ⇒ Object
Calculates first, second, third or mixed image derivatives using extended Sobel operator. self should be single-channel 8bit unsigned or 32bit floating-point.
link:../images/CvMat_sobel.png
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 |
# File 'ext/opencv/cvmat.cpp', line 3764 VALUE rb_laplace2(int argc, VALUE *argv, VALUE self) { VALUE dest, delta, ksize, scale; int ddepth; rb_scan_args(argc, argv, "03", &ksize, &scale, &delta); CvMat* self_ptr = CVMAT(self); if(CV_MAT_DEPTH(self_ptr->type) == CV_8U) { ddepth = CV_16S; // An 8U datatype would overflow due to negative derivative values } else { ddepth = CV_MAT_DEPTH(self_ptr->type); } dest = new_mat_kind_object(cvGetSize(self_ptr), self, ddepth, 1); if(NIL_P(ksize)) ksize = INT2FIX(1); if(NIL_P(scale)) scale = 1.0; if(NIL_P(delta)) delta = 0.0; try { const cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); cv::Laplacian(selfMat, destMat, ddepth, ksize, scale, delta); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#le(val) ⇒ CvMat
Performs the per-element comparison "less than or equal" of two arrays or an array and scalar value.
2194 2195 2196 2197 2198 2199 |
# File 'ext/opencv/cvmat.cpp', line 2194 VALUE rb_le(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_LE); } |
#line(p1, p2, options = nil) ⇒ CvMat
Returns an image that is drawn a line segment connecting two points.
3080 3081 3082 3083 3084 |
# File 'ext/opencv/cvmat.cpp', line 3080 VALUE rb_line(int argc, VALUE *argv, VALUE self) { return rb_line_bang(argc, argv, rb_rcv_clone(self)); } |
#line!(p1, p2, options = nil) ⇒ CvMat
Draws a line segment connecting two points.
3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 |
# File 'ext/opencv/cvmat.cpp', line 3103 VALUE rb_line_bang(int argc, VALUE *argv, VALUE self) { VALUE p1, p2, drawing_option; rb_scan_args(argc, argv, "21", &p1, &p2, &drawing_option); drawing_option = DRAWING_OPTION(drawing_option); try { cvLine(CVARR(self), VALUE_TO_CVPOINT(p1), VALUE_TO_CVPOINT(p2), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#log ⇒ Object
Calculates the natural logarithm of every array element
2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 |
# File 'ext/opencv/cvmat.cpp', line 2337 VALUE rb_log(VALUE self) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self); try { const cv::Mat selfMat(CVMAT(self)); cv::Mat destMat(CVMAT(dest)); cv::log(selfMat, destMat); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#log_polar(size, center, magnitude, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS) ⇒ CvMat
Remaps an image to log-polar space.
4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 |
# File 'ext/opencv/cvmat.cpp', line 4426 VALUE rb_log_polar(int argc, VALUE *argv, VALUE self) { VALUE dst_size, center, m, flags; rb_scan_args(argc, argv, "31", &dst_size, ¢er, &m, &flags); int _flags = NIL_P(flags) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags); VALUE dest = new_mat_kind_object(VALUE_TO_CVSIZE(dst_size), self); try { cvLogPolar(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT2D32F(center), NUM2DBL(m), _flags); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#lt(val) ⇒ CvMat
Performs the per-element comparison "less than" of two arrays or an array and scalar value.
2178 2179 2180 2181 2182 2183 |
# File 'ext/opencv/cvmat.cpp', line 2178 VALUE rb_lt(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_LT); } |
#lut(lut) ⇒ CvMat
Performs a look-up table transform of an array.
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 |
# File 'ext/opencv/cvmat.cpp', line 1680 VALUE rb_lut(VALUE self, VALUE lut) { VALUE dest = copy(self); try { cvLUT(CVARR(self), CVARR(dest), CVARR_WITH_CHECK(lut)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#magnitude(y) ⇒ Object
Calculates the magnitude of 2D vectors
2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 |
# File 'ext/opencv/cvmat.cpp', line 2359 VALUE rb_magnitude(VALUE self, VALUE y) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self); try { const cv::Mat selfMat(CVMAT(self)); const cv::Mat yMat(CVMAT(y)); cv::Mat destMat(CVMAT(dest)); cv::magnitude(selfMat, yMat, destMat); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#mat_mul(val, shiftvec = nil) ⇒ CvMat Also known as: *
Calculates the product of two arrays. dst = self * val + shiftvec
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 |
# File 'ext/opencv/cvmat.cpp', line 1879 VALUE rb_mat_mul(int argc, VALUE *argv, VALUE self) { VALUE val, shiftvec, dest; rb_scan_args(argc, argv, "11", &val, &shiftvec); CvArr* self_ptr = CVARR(self); dest = new_mat_kind_object(cvGetSize(self_ptr), self); try { if (NIL_P(shiftvec)) cvMatMul(self_ptr, CVARR_WITH_CHECK(val), CVARR(dest)); else cvMatMulAdd(self_ptr, CVARR_WITH_CHECK(val), CVARR_WITH_CHECK(shiftvec), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#match_shapes(object, method) ⇒ Float
Compares two shapes(self and object). object should be CvMat or CvContour.
A - object1, B - object2:
- method=CV_CONTOURS_MATCH_I1 I1(A,B)=sumi=1..7abs(1/mAi - 1/mBi)
- method=CV_CONTOURS_MATCH_I2 I2(A,B)=sumi=1..7abs(mAi - mBi)
- method=CV_CONTOURS_MATCH_I3 I3(A,B)=sumi=1..7abs(mAi - mBi)/abs(mAi)
5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 |
# File 'ext/opencv/cvmat.cpp', line 5944 VALUE rb_match_shapes(int argc, VALUE *argv, VALUE self) { VALUE object, method, param; rb_scan_args(argc, argv, "21", &object, &method, ¶m); int method_flag = CVMETHOD("COMPARISON_METHOD", method); if (!(rb_obj_is_kind_of(object, cCvMat::rb_class()) || rb_obj_is_kind_of(object, cCvContour::rb_class()))) rb_raise(rb_eTypeError, "argument 1 (shape) should be %s or %s", rb_class2name(cCvMat::rb_class()), rb_class2name(cCvContour::rb_class())); double result = 0; try { result = cvMatchShapes(CVARR(self), CVARR(object), method_flag); } catch (cv::Exception& e) { raise_cverror(e); } return rb_float_new(result); } |
#match_template(template, method = CV_TM_SQDIFF) ⇒ Object
Compares template against overlapped image regions.
After the match_template finishes comparison, the best matches can be found as global minimums (CV_TM_SQDIFF) or maximums(CV_TM_CCORR or CV_TM_CCOEFF) using CvMat#min_max_loc. In case of color image and template summation in both numerator and each sum in denominator is done over all the channels (and separate mean values are used for each channel).
5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 |
# File 'ext/opencv/cvmat.cpp', line 5903 VALUE rb_match_template(int argc, VALUE *argv, VALUE self) { VALUE templ, method; int method_flag; if (rb_scan_args(argc, argv, "11", &templ, &method) == 1) method_flag = CV_TM_SQDIFF; else method_flag = CVMETHOD("MATCH_TEMPLATE_METHOD", method); CvArr* self_ptr = CVARR(self); CvArr* templ_ptr = CVARR_WITH_CHECK(templ); VALUE result = Qnil; try { CvSize src_size = cvGetSize(self_ptr); CvSize template_size = cvGetSize(templ_ptr); result = cCvMat::new_object(src_size.height - template_size.height + 1, src_size.width - template_size.width + 1, CV_32FC1); cvMatchTemplate(self_ptr, templ_ptr, CVARR(result), method_flag); } catch (cv::Exception& e) { raise_cverror(e); } return result; } |
#max(anothermat) ⇒ Object
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 |
# File 'ext/opencv/cvmat.cpp', line 2549 VALUE rb_max(int argc, VALUE *argv, VALUE self) { VALUE second_mat, dest; rb_scan_args(argc, argv, "1", &second_mat); dest = copy(self); try { cvMax(CVARR(self), CVARR(second_mat), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#mean_shift(window, criteria) ⇒ Object
Implements CAMSHIFT object tracking algrorithm. First, it finds an object center using mean_shift and, after that, calculates the object size and orientation.
5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 |
# File 'ext/opencv/cvmat.cpp', line 5971 VALUE rb_mean_shift(VALUE self, VALUE window, VALUE criteria) { VALUE comp = cCvConnectedComp::new_object(); try { cvMeanShift(CVARR(self), VALUE_TO_CVRECT(window), VALUE_TO_CVTERMCRITERIA(criteria), CVCONNECTEDCOMP(comp)); } catch (cv::Exception& e) { raise_cverror(e); } return comp; } |
#min(anothermat) ⇒ Object
2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 |
# File 'ext/opencv/cvmat.cpp', line 2529 VALUE rb_min(int argc, VALUE *argv, VALUE self) { VALUE second_mat, dest; rb_scan_args(argc, argv, "1", &second_mat); dest = copy(self); try { cvMin(CVARR(self), CVARR(second_mat), CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#min_max_loc(mask = nil) ⇒ Array<Number, CvPoint>
Finds the global minimum and maximum in an array.
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 |
# File 'ext/opencv/cvmat.cpp', line 2507 VALUE rb_min_max_loc(int argc, VALUE *argv, VALUE self) { VALUE mask, min_loc, max_loc; double min_val = 0.0, max_val = 0.0; rb_scan_args(argc, argv, "01", &mask); min_loc = cCvPoint::new_object(); max_loc = cCvPoint::new_object(); try { cvMinMaxLoc(CVARR(self), &min_val, &max_val, CVPOINT(min_loc), CVPOINT(max_loc), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(4, rb_float_new(min_val), rb_float_new(max_val), min_loc, max_loc); } |
#moments ⇒ Object
Calculates moments.
5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 |
# File 'ext/opencv/cvmat.cpp', line 5601 VALUE rb_moments(int argc, VALUE *argv, VALUE self) { VALUE is_binary; rb_scan_args(argc, argv, "01", &is_binary); CvArr *self_ptr = CVARR(self); VALUE moments = Qnil; try { moments = cCvMoments::new_object(self_ptr, TRUE_OR_FALSE(is_binary, 0)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(1, moments); } |
#morphology(operation, element = nil, iteration = 1) ⇒ CvMat
Performs advanced morphological transformations using erosion and dilation as basic operations.
4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 |
# File 'ext/opencv/cvmat.cpp', line 4544 VALUE 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); IplConvKernel* kernel = NIL_P(element) ? NULL : IPLCONVKERNEL_WITH_CHECK(element); try { if (operation == CV_MOP_GRADIENT) { CvMat* temp = rb_cvCreateMat(size.height, size.width, cvGetElemType(self_ptr)); cvMorphologyEx(self_ptr, CVARR(dest), temp, kernel, CV_MOP_GRADIENT, IF_INT(iteration, 1)); cvReleaseMat(&temp); } else { cvMorphologyEx(self_ptr, CVARR(dest), 0, kernel, operation, IF_INT(iteration, 1)); } } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#mul(val, scale = 1.0) ⇒ CvMat
Calculates the per-element scaled product of two arrays.
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 |
# File 'ext/opencv/cvmat.cpp', line 1821 VALUE rb_mul(int argc, VALUE *argv, VALUE self) { VALUE val, scale, dest; if (rb_scan_args(argc, argv, "11", &val, &scale) < 2) scale = rb_float_new(1.0); dest = new_mat_kind_object(cvGetSize(CVARR(self)), self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvMul(CVARR(self), CVARR(val), CVARR(dest), NUM2DBL(scale)); else { CvScalar scl = VALUE_TO_CVSCALAR(val); VALUE mat = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self))); cvSet(CVARR(mat), scl); cvMul(CVARR(self), CVARR(mat), CVARR(dest), NUM2DBL(scale)); } } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#mul_transposed(options) ⇒ CvMat
Calculates the product of a matrix and its transposition.
This function calculates the product of self and its transposition:
if :order = 0
dst = scale * (self - delta) * (self - delta)T
otherwise
dst = scale * (self - delta)T * (self - delta)
2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 |
# File 'ext/opencv/cvmat.cpp', line 2710 VALUE rb_mul_transposed(int argc, VALUE *argv, VALUE self) { VALUE = Qnil; VALUE _delta = Qnil, _scale = Qnil, _order = Qnil; if (rb_scan_args(argc, argv, "01", &) > 0) { Check_Type(, T_HASH); _delta = LOOKUP_HASH(, "delta"); _scale = LOOKUP_HASH(, "scale"); _order = LOOKUP_HASH(, "order"); } CvArr* delta = NIL_P(_delta) ? NULL : CVARR_WITH_CHECK(_delta); double scale = NIL_P(_scale) ? 1.0 : NUM2DBL(_scale); int order = NIL_P(_order) ? 0 : NUM2INT(_order); CvArr* self_ptr = CVARR(self); VALUE dest = new_mat_kind_object(cvGetSize(self_ptr), self); try { cvMulTransposed(self_ptr, CVARR(dest), order, delta, scale); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#ne(val) ⇒ CvMat
Performs the per-element comparison "not equal" of two arrays or an array and scalar value.
2210 2211 2212 2213 2214 2215 |
# File 'ext/opencv/cvmat.cpp', line 2210 VALUE rb_ne(VALUE self, VALUE val) { VALUE dest = new_mat_kind_object(cvGetSize(CVARR(self)), self, CV_8U, 1); return rb_cmp_internal(self, val, dest, CV_CMP_NE); } |
#normalize(alpha = 1.0, beta = 0.0, norm_type = NORM_L2, dtype = -1, mask = nil) ⇒ CvMat
Normalizes the norm or value range of an array.
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 |
# File 'ext/opencv/cvmat.cpp', line 2296 VALUE rb_normalize(int argc, VALUE *argv, VALUE self) { VALUE alpha_val, beta_val, norm_type_val, dtype_val, mask_val; rb_scan_args(argc, argv, "05", &alpha_val, &beta_val, &norm_type_val, &dtype_val, &mask_val); double alpha = NIL_P(alpha_val) ? 1.0 : NUM2DBL(alpha_val); double beta = NIL_P(beta_val) ? 0.0 : NUM2DBL(beta_val); int norm_type = NIL_P(norm_type_val) ? cv::NORM_L2 : NUM2INT(norm_type_val); int dtype = NIL_P(dtype_val) ? -1 : NUM2INT(dtype_val); VALUE dst; try { cv::Mat self_mat(CVMAT(self)); cv::Mat dst_mat; if (NIL_P(mask_val)) { cv::normalize(self_mat, dst_mat, alpha, beta, norm_type, dtype); } else { cv::Mat mask(MASK(mask_val)); cv::normalize(self_mat, dst_mat, alpha, beta, norm_type, dtype, mask); } dst = new_mat_kind_object(cvGetSize(CVARR(self)), self, dst_mat.depth(), dst_mat.channels()); CvMat tmp = dst_mat; cvCopy(&tmp, CVMAT(dst)); } catch (cv::Exception& e) { raise_cverror(e); } return dst; } |
#not ⇒ CvMat
Returns an array which elements are bit-wise invertion of source array.
2069 2070 2071 2072 2073 |
# File 'ext/opencv/cvmat.cpp', line 2069 VALUE rb_not(VALUE self) { return rb_not_bang(copy(self)); } |
#not! ⇒ CvMat
Inverts every bit of an array.
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 |
# File 'ext/opencv/cvmat.cpp', line 2082 VALUE rb_not_bang(VALUE self) { try { cvNot(CVARR(self), CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#optical_flow_bm(prev[,velx = nil][,vely = nil][,option]) ⇒ Array
Calculates optical flow for two images (previous -> self) using block matching method. Return horizontal component of the optical flow and vertical component of the optical flow. prev is previous image. velx is previous velocity field of x-axis, and vely is previous velocity field of y-axis.
options
- :block_size -> should be CvSize (default is CvSize(4,4)) Size of basic blocks that are compared.
- :shift_size -> should be CvSize (default is CvSize(1,1)) Block coordinate increments.
- :max_range -> should be CvSize (default is CVSize(4,4)) Size of the scanned neighborhood in pixels around block. note: option's default value is CvMat::OPTICAL_FLOW_BM_OPTION.
Velocity is computed for every block, but not for every pixel, so velocity image pixels correspond to input image blocks. input/output velocity field's size should be (self.width / block_size.width)x(self.height / block_size.height). e.g. image.size is 320x240 and block_size is 4x4, velocity field's size is 80x60.
6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 |
# File 'ext/opencv/cvmat.cpp', line 6200 VALUE rb_optical_flow_bm(int argc, VALUE *argv, VALUE self) { VALUE prev, velx, vely, ; rb_scan_args(argc, argv, "13", &prev, &velx, &vely, &); = OPTICAL_FLOW_BM_OPTION(); CvArr* self_ptr = CVARR(self); CvSize block_size = BM_BLOCK_SIZE(); CvSize shift_size = BM_SHIFT_SIZE(); CvSize max_range = BM_MAX_RANGE(); int use_previous = 0; try { CvSize image_size = cvGetSize(self_ptr); CvSize velocity_size = cvSize((image_size.width - block_size.width + shift_size.width) / shift_size.width, (image_size.height - block_size.height + shift_size.height) / shift_size.height); CvMat *velx_ptr, *vely_ptr; if (NIL_P(velx) && NIL_P(vely)) { int type = CV_MAKETYPE(CV_32F, 1); velx = cCvMat::new_object(velocity_size, type); vely = cCvMat::new_object(velocity_size, type); velx_ptr = CVMAT(velx); vely_ptr = CVMAT(vely); } else { use_previous = 1; velx_ptr = CVMAT_WITH_CHECK(velx); vely_ptr = CVMAT_WITH_CHECK(vely); } cvCalcOpticalFlowBM(CVMAT_WITH_CHECK(prev), self_ptr, block_size, shift_size, max_range, use_previous, velx_ptr, vely_ptr); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, velx, vely); } |
#optical_flow_hs(prev[,velx = nil][,vely = nil][,options]) ⇒ Array
Calculates optical flow for two images (previous -> self) using Horn & Schunck algorithm. Return horizontal component of the optical flow and vertical component of the optical flow. prev is previous image velx is previous velocity field of x-axis, and vely is previous velocity field of y-axis.
options
- :lambda -> should be Float (default is 0.0005) Lagrangian multiplier.
- :criteria -> should be CvTermCriteria object (default is CvTermCriteria(1, 0.001)) Criteria of termination of velocity computing. note: option's default value is CvMat::OPTICAL_FLOW_HS_OPTION.
sample code velx, vely = nil, nil while true current = capture.query velx, vely = current.optical_flow_hs(prev, velx, vely) if prev prev = current end
6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 |
# File 'ext/opencv/cvmat.cpp', line 6115 VALUE rb_optical_flow_hs(int argc, VALUE *argv, VALUE self) { VALUE prev, velx, vely, ; int use_previous = 0; rb_scan_args(argc, argv, "13", &prev, &velx, &vely, &); = OPTICAL_FLOW_HS_OPTION(); CvMat *velx_ptr, *vely_ptr; CvArr* self_ptr = CVARR(self); try { if (NIL_P(velx) && NIL_P(vely)) { CvSize size = cvGetSize(self_ptr); int type = CV_MAKETYPE(CV_32F, 1); velx = cCvMat::new_object(size, type); vely = cCvMat::new_object(size, type); velx_ptr = CVMAT(velx); vely_ptr = CVMAT(vely); } else { use_previous = 1; velx_ptr = CVMAT_WITH_CHECK(velx); vely_ptr = CVMAT_WITH_CHECK(vely); } cvCalcOpticalFlowHS(CVMAT_WITH_CHECK(prev), self_ptr, use_previous, velx_ptr, vely_ptr, HS_LAMBDA(), HS_CRITERIA()); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, velx, vely); } |
#optical_flow_lk(prev, win_size) ⇒ Array
Calculates optical flow for two images (previous -> self) using Lucas & Kanade algorithm Return horizontal component of the optical flow and vertical component of the optical flow.
win_size is size of the averaging window used for grouping pixels.
6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 |
# File 'ext/opencv/cvmat.cpp', line 6156 VALUE rb_optical_flow_lk(VALUE self, VALUE prev, VALUE win_size) { VALUE velx = Qnil; VALUE vely = Qnil; try { CvArr* self_ptr = CVARR(self); CvSize size = cvGetSize(self_ptr); int type = CV_MAKETYPE(CV_32F, 1); velx = cCvMat::new_object(size, type); vely = cCvMat::new_object(size, type); cvCalcOpticalFlowLK(CVMAT_WITH_CHECK(prev), self_ptr, VALUE_TO_CVSIZE(win_size), CVARR(velx), CVARR(vely)); } catch (cv::Exception& e) { raise_cverror(e); } return rb_ary_new3(2, velx, vely); } |
#or(val, mask = nil) ⇒ CvMat Also known as: |
Calculates the per-element bit-wise disjunction of two arrays or an array and a scalar.
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 |
# File 'ext/opencv/cvmat.cpp', line 2015 VALUE rb_or(int argc, VALUE *argv, VALUE self) { VALUE val, mask, dest; rb_scan_args(argc, argv, "11", &val, &mask); dest = copy(self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvOr(CVARR(self), CVARR(val), CVARR(dest), MASK(mask)); else cvOrS(CVARR(self), VALUE_TO_CVSCALAR(val), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#perspective_transform(mat) ⇒ CvMat
Performs the perspective matrix transformation of vectors.
2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 |
# File 'ext/opencv/cvmat.cpp', line 2678 VALUE rb_perspective_transform(VALUE self, VALUE mat) { CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvPerspectiveTransform(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(mat)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#pixel_value(index) ⇒ Object
1041 1042 1043 1044 1045 1046 |
# File 'ext/opencv/cvmat.cpp', line 1041 VALUE rb_pixel_value(VALUE self, VALUE index) { CvScalar scalar = cvGet1D(CVARR(self), NUM2INT(index)); return rb_float_new(scalar.val[0]); } |
#poly_line(points, options = nil) ⇒ CvMat
Returns an image that is drawn several polygonal curves.
3527 3528 3529 3530 3531 |
# File 'ext/opencv/cvmat.cpp', line 3527 VALUE rb_poly_line(int argc, VALUE *argv, VALUE self) { return rb_poly_line_bang(argc, argv, rb_rcv_clone(self)); } |
#poly_line!(points, options = nil) ⇒ CvMat
Draws several polygonal curves.
3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 |
# File 'ext/opencv/cvmat.cpp', line 3553 VALUE rb_poly_line_bang(int argc, VALUE *argv, VALUE self) { VALUE polygons, drawing_option; VALUE points; int i, j; int num_polygons; int *num_points; CvPoint **p; rb_scan_args(argc, argv, "11", &polygons, &drawing_option); Check_Type(polygons, T_ARRAY); drawing_option = DRAWING_OPTION(drawing_option); num_polygons = RARRAY_LEN(polygons); num_points = ALLOCA_N(int, num_polygons); p = ALLOCA_N(CvPoint*, num_polygons); for (j = 0; j < num_polygons; ++j) { points = rb_ary_entry(polygons, j); Check_Type(points, T_ARRAY); num_points[j] = RARRAY_LEN(points); p[j] = ALLOCA_N(CvPoint, num_points[j]); for (i = 0; i < num_points[j]; ++i) { p[j][i] = VALUE_TO_CVPOINT(rb_ary_entry(points, i)); } } try { cvPolyLine(CVARR(self), p, num_points, num_polygons, DO_IS_CLOSED(drawing_option), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#pre_corner_detect(aperture_size = 3) ⇒ CvMat
Calculates a feature map for corner detection.
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 |
# File 'ext/opencv/cvmat.cpp', line 3843 VALUE rb_pre_corner_detect(int argc, VALUE *argv, VALUE self) { VALUE aperture_size, dest = Qnil; if (rb_scan_args(argc, argv, "01", &aperture_size) < 1) aperture_size = INT2FIX(3); CvArr *self_ptr = CVARR(self); try { dest = new_object(cvGetSize(self_ptr), CV_MAKETYPE(CV_32F, 1)); cvPreCornerDetect(self_ptr, CVARR(dest), NUM2INT(aperture_size)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#put_text(text, org, font, color = CvColor::Black) ⇒ CvMat
Returns an image which is drawn a text string.
3607 3608 3609 3610 3611 |
# File 'ext/opencv/cvmat.cpp', line 3607 VALUE rb_put_text(int argc, VALUE* argv, VALUE self) { return rb_put_text_bang(argc, argv, rb_rcv_clone(self)); } |
#put_text!(text, org, font, color = CvColor::Black) ⇒ CvMat
Draws a text string.
3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 |
# File 'ext/opencv/cvmat.cpp', line 3624 VALUE rb_put_text_bang(int argc, VALUE* argv, VALUE self) { VALUE _text, _point, _font, _color; rb_scan_args(argc, argv, "31", &_text, &_point, &_font, &_color); CvScalar color = NIL_P(_color) ? CV_RGB(0, 0, 0) : VALUE_TO_CVSCALAR(_color); try { cvPutText(CVARR(self), StringValueCStr(_text), VALUE_TO_CVPOINT(_point), CVFONT_WITH_CHECK(_font), color); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#pyr_down([filter = :gaussian_5x5]) ⇒ Object
Return downsamples image.
This operation performs downsampling step of Gaussian pyramid decomposition. First it convolves source image with the specified filter and then downsamples the image by rejecting even rows and columns.
note: filter - only :gaussian_5x5 is currently supported.
5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 |
# File 'ext/opencv/cvmat.cpp', line 5047 VALUE rb_pyr_down(int argc, VALUE *argv, VALUE self) { int filter = CV_GAUSSIAN_5x5; if (argc > 0) { VALUE filter_type = argv[0]; switch (TYPE(filter_type)) { case T_SYMBOL: // currently suport CV_GAUSSIAN_5x5 only. break; default: raise_typeerror(filter_type, rb_cSymbol); } } CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { CvSize original_size = cvGetSize(self_ptr); CvSize size = { original_size.width >> 1, original_size.height >> 1 }; dest = new_mat_kind_object(size, self); cvPyrDown(self_ptr, CVARR(dest), filter); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#pyr_mean_shift_filtering(sp, sr[,max_level = 1][termcrit = CvTermCriteria.new(5,1)]) ⇒ Object
Does meanshift image segmentation.
sp - The spatial window radius.
sr - The color window radius.
max_level - Maximum level of the pyramid for the segmentation.
termcrit - Termination criteria: when to stop meanshift iterations.
This method is implements the filtering stage of meanshift segmentation, that is, the output of the function is the filtered "posterized" image with color gradients and fine-grain texture flattened. At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is considered:
{(x,y): X-sp
where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively (though, the algorithm does not depend on the color space used, so any 3-component color space can be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector (R',G',B') are found and they act as the neighborhood center on the next iteration:
(X,Y)~(X',Y'), (R,G,B)~(R',G',B').
After the iterations over, the color components of the initial pixel (that is, the pixel from where the iterations started) are set to the final value (average color at the last iteration):
I(X,Y) <- (R*,G*,B*).
Then max_level > 0, the gaussian pyramid of max_level+1 levels is built, and the above procedure is run on the smallest layer. After that, the results are propagated to the larger layer and the iterations are run again only on those pixels where the layer colors differ much (>sr) from the lower-resolution layer, that is, the boundaries of the color regions are clarified.
Note, that the results will be actually different from the ones obtained by running the meanshift procedure on the whole original image (i.e. when max_level==0).
5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 |
# File 'ext/opencv/cvmat.cpp', line 5422 VALUE rb_pyr_mean_shift_filtering(int argc, VALUE *argv, VALUE self) { VALUE spatial_window_radius, color_window_radius, max_level, termcrit; rb_scan_args(argc, argv, "22", &spatial_window_radius, &color_window_radius, &max_level, &termcrit); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvPyrMeanShiftFiltering(self_ptr, CVARR(dest), NUM2DBL(spatial_window_radius), NUM2DBL(color_window_radius), IF_INT(max_level, 1), NIL_P(termcrit) ? cvTermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 5, 1) : VALUE_TO_CVTERMCRITERIA(termcrit)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#pyr_up([filter = :gaussian_5x5]) ⇒ Object
Return upsamples image.
This operation performs up-sampling step of Gaussian pyramid decomposition. First it upsamples the source image by injecting even zero rows and columns and then convolves result with the specified filter multiplied by 4 for interpolation. So the destination image is four times larger than the source image.
note: filter - only :gaussian_5x5 is currently supported.
5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 |
# File 'ext/opencv/cvmat.cpp', line 5088 VALUE rb_pyr_up(int argc, VALUE *argv, VALUE self) { VALUE filter_type; rb_scan_args(argc, argv, "01", &filter_type); int filter = CV_GAUSSIAN_5x5; if (argc > 0) { switch (TYPE(filter_type)) { case T_SYMBOL: // currently suport CV_GAUSSIAN_5x5 only. break; default: raise_typeerror(filter_type, rb_cSymbol); } } CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { CvSize original_size = cvGetSize(self_ptr); CvSize size = { original_size.width << 1, original_size.height << 1 }; dest = new_mat_kind_object(size, self); cvPyrUp(self_ptr, CVARR(dest), filter); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#quadrangle_sub_pix(map_matrix, size = self.size) ⇒ CvMat
CvMat#quadrangle_sub_pix is similar to CvMat#warp_affine, but the outliers are extrapolated using replication border mode.
Applies an affine transformation to an image.
4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 |
# File 'ext/opencv/cvmat.cpp', line 4144 VALUE rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self) { VALUE map_matrix, size; VALUE dest = Qnil; CvSize _size; CvArr* self_ptr = CVARR(self); try { if (rb_scan_args(argc, argv, "11", &map_matrix, &size) < 2) _size = cvGetSize(self_ptr); else _size = VALUE_TO_CVSIZE(size); dest = new_mat_kind_object(_size, self); cvGetQuadrangleSubPix(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#rand_shuffle(seed = -1, iter_factor = 1) ⇒ CvMat
Returns shuffled matrix by swapping randomly chosen pairs of the matrix elements on each iteration (where each element may contain several components in case of multi-channel arrays)
1636 1637 1638 1639 1640 |
# File 'ext/opencv/cvmat.cpp', line 1636 VALUE rb_rand_shuffle(int argc, VALUE *argv, VALUE self) { return rb_rand_shuffle_bang(argc, argv, copy(self)); } |
#rand_shuffle!(seed = -1, iter_factor = 1) ⇒ CvMat
Shuffles the matrix by swapping randomly chosen pairs of the matrix elements on each iteration (where each element may contain several components in case of multi-channel arrays)
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 |
# File 'ext/opencv/cvmat.cpp', line 1651 VALUE rb_rand_shuffle_bang(int argc, VALUE *argv, VALUE self) { VALUE seed, iter; rb_scan_args(argc, argv, "02", &seed, &iter); try { if (NIL_P(seed)) cvRandShuffle(CVARR(self), NULL, IF_INT(iter, 1)); else { CvRNG rng = cvRNG(rb_num2ll(seed)); cvRandShuffle(CVARR(self), &rng, IF_INT(iter, 1)); } } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#range(start, end) ⇒ CvMat
Returns initialized matrix as following:
arr(i,j)=(end-start)*(i*cols(arr)+j)/(cols(arr)*rows(arr))
1410 1411 1412 1413 1414 |
# File 'ext/opencv/cvmat.cpp', line 1410 VALUE rb_range(VALUE self, VALUE start, VALUE end) { return rb_range_bang(copy(self), start, end); } |
#range!(start, end) ⇒ CvMat
Initializes the matrix as following:
arr(i,j)=(end-start)*(i*cols(arr)+j)/(cols(arr)*rows(arr))
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 |
# File 'ext/opencv/cvmat.cpp', line 1424 VALUE rb_range_bang(VALUE self, VALUE start, VALUE end) { try { cvRange(CVARR(self), NUM2DBL(start), NUM2DBL(end)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#clone ⇒ CvMat
Makes a clone of an object.
496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'ext/opencv/cvmat.cpp', line 496 VALUE rb_rcv_clone(VALUE self) { VALUE clone = rb_obj_clone(self); try { DATA_PTR(clone) = cvClone(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return clone; } |
#rect_sub_pix(center, size = self.size) ⇒ CvMat
Retrieves a pixel rectangle from an image with sub-pixel accuracy.
4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 |
# File 'ext/opencv/cvmat.cpp', line 4112 VALUE rb_rect_sub_pix(int argc, VALUE *argv, VALUE self) { VALUE center, size; VALUE dest = Qnil; CvSize _size; CvArr* self_ptr = CVARR(self); try { if (rb_scan_args(argc, argv, "11", ¢er, &size) < 2) _size = cvGetSize(self_ptr); else _size = VALUE_TO_CVSIZE(size); dest = new_mat_kind_object(_size, self); cvGetRectSubPix(self_ptr, CVARR(dest), VALUE_TO_CVPOINT2D32F(center)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#rectangle(p1, p2, options = nil) ⇒ CvMat
Returns an image that is drawn a simple, thick, or filled up-right rectangle.
3139 3140 3141 3142 3143 |
# File 'ext/opencv/cvmat.cpp', line 3139 VALUE rb_rectangle(int argc, VALUE *argv, VALUE self) { return rb_rectangle_bang(argc, argv, rb_rcv_clone(self)); } |
#rectangle!(p1, p2, options = nil) ⇒ CvMat
Draws a simple, thick, or filled up-right rectangle.
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 |
# File 'ext/opencv/cvmat.cpp', line 3162 VALUE rb_rectangle_bang(int argc, VALUE *argv, VALUE self) { VALUE p1, p2, drawing_option; rb_scan_args(argc, argv, "21", &p1, &p2, &drawing_option); drawing_option = DRAWING_OPTION(drawing_option); try { cvRectangle(CVARR(self), VALUE_TO_CVPOINT(p1), VALUE_TO_CVPOINT(p2), DO_COLOR(drawing_option), DO_THICKNESS(drawing_option), DO_LINE_TYPE(drawing_option), DO_SHIFT(drawing_option)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#remap(mapx, mapy, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies a generic geometrical transformation to an image.
4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 |
# File 'ext/opencv/cvmat.cpp', line 4392 VALUE rb_remap(int argc, VALUE *argv, VALUE self) { VALUE mapx, mapy, flags_val, option, fillval; if (rb_scan_args(argc, argv, "23", &mapx, &mapy, &flags_val, &option, &fillval) < 5) fillval = INT2FIX(0); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val); try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvRemap(self_ptr, CVARR(dest), CVARR_WITH_CHECK(mapx), CVARR_WITH_CHECK(mapy), flags, VALUE_TO_CVSCALAR(fillval)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#repeat(dst) ⇒ CvMat
Fills the destination array with repeated copies of the source array.
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 |
# File 'ext/opencv/cvmat.cpp', line 1475 VALUE rb_repeat(VALUE self, VALUE object) { try { cvRepeat(CVARR(self), CVARR_WITH_CHECK(object)); } catch (cv::Exception& e) { raise_cverror(e); } return object; } |
#reshape(cn, rows = 0) ⇒ CvMat
Changes shape of matrix/image without copying data.
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 |
# File 'ext/opencv/cvmat.cpp', line 1448 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"))); CvMat *mat = NULL; try { mat = cvReshape(CVARR(self), RB_CVALLOC(CvMat), NIL_P(channel) ? 0 : NUM2INT(channel), NIL_P(rows) ? 0 : NUM2INT(rows)); } catch (cv::Exception& e) { if (mat != NULL) cvReleaseMat(&mat); raise_cverror(e); } return DEPEND_OBJECT(rb_klass, mat, self); } |
#resize(size, interpolation = :linear) ⇒ CvMat
Resizes an image.
4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 |
# File 'ext/opencv/cvmat.cpp', line 4181 VALUE rb_resize(int argc, VALUE *argv, VALUE self) { VALUE size, interpolation; rb_scan_args(argc, argv, "11", &size, &interpolation); VALUE dest = new_mat_kind_object(VALUE_TO_CVSIZE(size), self); int method = NIL_P(interpolation) ? CV_INTER_LINEAR : NUM2INT(interpolation); try { cvResize(CVARR(self), CVARR(dest), method); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#save_image(filename) ⇒ CvMat Also known as: save
Saves an image to a specified file. The image format is chosen based on the filename extension.
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
# File 'ext/opencv/cvmat.cpp', line 1261 VALUE rb_save_image(int argc, VALUE *argv, VALUE self) { VALUE _filename, _params; rb_scan_args(argc, argv, "11", &_filename, &_params); Check_Type(_filename, T_STRING); int *params = NULL; if (!NIL_P(_params)) { params = hash_to_format_specific_param(_params); } try { cvSaveImage(StringValueCStr(_filename), CVARR(self), params); } catch (cv::Exception& e) { if (params != NULL) { free(params); params = NULL; } raise_cverror(e); } if (params != NULL) { free(params); params = NULL; } return self; } |
#sobel(<i>xorder, yorder[,aperture_size = 3]) ⇒ Object
Calculates first, second, third or mixed image derivatives using extended Sobel operator. self should be single-channel 8bit unsigned or 32bit floating-point.
link:../images/CvMat_sobel.png
3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 |
# File 'ext/opencv/cvmat.cpp', line 3689 VALUE rb_scharr(int argc, VALUE *argv, VALUE self) { VALUE xorder, yorder, aperture_size, dest, scale; rb_scan_args(argc, argv, "3", &xorder, &yorder, &scale); // aperture_size = INT2FIX(3); CvMat* self_ptr = CVMAT(self); switch(CV_MAT_DEPTH(self_ptr->type)) { case CV_8U: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_16S, 1); break; case CV_32F: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_32F, 1); break; default: rb_raise(rb_eArgError, "source depth should be CV_8U or CV_32F."); break; } try { const cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); cv::Scharr(selfMat, destMat, CV_MAT_DEPTH(self_ptr->type), NUM2INT(xorder), NUM2INT(yorder), scale); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#sdv(mask = nil) ⇒ CvScalar
Calculates a standard deviation of array elements.
2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 |
# File 'ext/opencv/cvmat.cpp', line 2482 VALUE rb_sdv(int argc, VALUE *argv, VALUE self) { VALUE mask, std_dev; rb_scan_args(argc, argv, "01", &mask); std_dev = cCvScalar::new_object(); try { cvAvgSdv(CVARR(self), NULL, CVSCALAR(std_dev), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return std_dev; } |
#set(value, mask = nil) ⇒ CvMat Also known as: fill
Returns a matrix which is set every element to a given value. The function copies the scalar value to every selected element of the destination array:
mat[I] = value if mask(I) != 0
1223 1224 1225 1226 1227 |
# File 'ext/opencv/cvmat.cpp', line 1223 VALUE rb_set(int argc, VALUE *argv, VALUE self) { return rb_set_bang(argc, argv, copy(self)); } |
#set!(value, mask = nil) ⇒ CvMat Also known as: fill!
Sets every element of the matrix to a given value. The function copies the scalar value to every selected element of the destination array:
mat[I] = value if mask(I) != 0
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'ext/opencv/cvmat.cpp', line 1239 VALUE rb_set_bang(int argc, VALUE *argv, VALUE self) { VALUE value, mask; rb_scan_args(argc, argv, "11", &value, &mask); try { cvSet(CVARR(self), VALUE_TO_CVSCALAR(value), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#set_data(data) ⇒ CvMat
Assigns user data to the array header
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'ext/opencv/cvmat.cpp', line 1133 VALUE rb_set_data(VALUE self, VALUE data) { CvMat *self_ptr = CVMAT(self); int depth = CV_MAT_DEPTH(self_ptr->type); if (TYPE(data) == T_STRING) { if (depth != CV_8U) rb_raise(rb_eArgError, "Invalid CvMat depth"); if (!CV_IS_MAT_CONT(self_ptr->type)) rb_raise(rb_eArgError, "CvMat must be continuous"); const int dataLength = RSTRING_LEN(data); if (dataLength != self_ptr->width * self_ptr->height * CV_MAT_CN(self_ptr->type)) rb_raise(rb_eArgError, "Invalid data string length"); memcpy(self_ptr->data.ptr, RSTRING_PTR(data), dataLength); } else { data = rb_funcall(data, rb_intern("flatten"), 0); const int DATA_LEN = RARRAY_LEN(data); void* array = NULL; switch (depth) { case CV_8U: array = rb_cvAlloc(sizeof(uchar) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((uchar*)array)[i] = (uchar)(NUM2INT(rb_ary_entry(data, i))); break; case CV_8S: array = rb_cvAlloc(sizeof(char) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((char*)array)[i] = (char)(NUM2INT(rb_ary_entry(data, i))); break; case CV_16U: array = rb_cvAlloc(sizeof(ushort) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((ushort*)array)[i] = (ushort)(NUM2INT(rb_ary_entry(data, i))); break; case CV_16S: array = rb_cvAlloc(sizeof(short) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((short*)array)[i] = (short)(NUM2INT(rb_ary_entry(data, i))); break; case CV_32S: array = rb_cvAlloc(sizeof(int) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((int*)array)[i] = NUM2INT(rb_ary_entry(data, i)); break; case CV_32F: array = rb_cvAlloc(sizeof(float) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((float*)array)[i] = (float)NUM2DBL(rb_ary_entry(data, i)); break; case CV_64F: array = rb_cvAlloc(sizeof(double) * DATA_LEN); for (int i = 0; i < DATA_LEN; ++i) ((double*)array)[i] = NUM2DBL(rb_ary_entry(data, i)); break; default: rb_raise(rb_eArgError, "Invalid CvMat depth"); break; } try { cvSetData(self_ptr, array, self_ptr->step); } catch (cv::Exception& e) { raise_cverror(e); } } return self; } |
#set_zero ⇒ CvMat Also known as: clear, zero
Returns cleared array.
1336 1337 1338 1339 1340 |
# File 'ext/opencv/cvmat.cpp', line 1336 VALUE rb_set_zero(VALUE self) { return rb_set_zero_bang(copy(self)); } |
#set_zero! ⇒ CvMat Also known as: clear!, zero!
Clears the array.
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 |
# File 'ext/opencv/cvmat.cpp', line 1348 VALUE rb_set_zero_bang(VALUE self) { try { cvSetZero(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return self; } |
#size ⇒ CvSize
Returns size of the matrix
935 936 937 938 939 940 941 942 943 944 945 946 |
# File 'ext/opencv/cvmat.cpp', line 935 VALUE rb_size(VALUE self) { CvSize size; try { size = cvGetSize(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return cCvSize::new_object(size); } |
#smooth(smoothtype, size1 = 3, size2 = 0, sigma1 = 0, sigma2 = 0) ⇒ CvMat
Smooths the image in one of several ways.
4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 |
# File 'ext/opencv/cvmat.cpp', line 4709 VALUE rb_smooth(int argc, VALUE *argv, VALUE self) { VALUE smoothtype, p1, p2, p3, p4; rb_scan_args(argc, argv, "14", &smoothtype, &p1, &p2, &p3, &p4); int _smoothtype = CVMETHOD("SMOOTHING_TYPE", smoothtype, -1); VALUE (*smooth_func)(int c, VALUE* v, VALUE s); argc--; switch (_smoothtype) { case CV_BLUR_NO_SCALE: smooth_func = rb_smooth_blur_no_scale; argc = (argc > 2) ? 2 : argc; break; case CV_BLUR: smooth_func = rb_smooth_blur; argc = (argc > 2) ? 2 : argc; break; case CV_GAUSSIAN: smooth_func = rb_smooth_gaussian; break; case CV_MEDIAN: smooth_func = rb_smooth_median; argc = (argc > 1) ? 1 : argc; break; case CV_BILATERAL: smooth_func = rb_smooth_bilateral; argc = (argc > 4) ? 4 : argc; break; default: smooth_func = rb_smooth_gaussian; break; } VALUE result = Qnil; try { result = (*smooth_func)(argc, argv + 1, self); } catch (cv::Exception& e) { raise_cverror(e); } return result; } |
#snake_image(points, alpha, beta, gamma, window, criteria[, calc_gradient = true]) ⇒ Object
Updates snake in order to minimize its total energy that is a sum of internal energy that depends on contour shape (the smoother contour is, the smaller internal energy is) and external energy that depends on the energy field and reaches minimum at the local energy extremums that correspond to the image edges in case of image gradient.
The parameter criteria.epsilon is used to define the minimal number of points that must be moved during any iteration to keep the iteration process running.
If at some iteration the number of moved points is less than criteria.epsilon or the function performed criteria.max_iter iterations, the function terminates.
points Contour points (snake). alpha Weight of continuity energy, single float or array of length floats, one per each contour point. beta Weight of curvature energy, similar to alpha. gamma Weight of image energy, similar to alpha. window Size of neighborhood of every point used to search the minimum, both win.width and win.height must be odd. criteria Termination criteria. calc_gradient Gradient flag. If not 0, the function calculates gradient magnitude for every image pixel and consideres it as the energy field, otherwise the input image itself is considered.
6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 |
# File 'ext/opencv/cvmat.cpp', line 6038 VALUE rb_snake_image(int argc, VALUE *argv, VALUE self) { VALUE points, alpha, beta, gamma, window, criteria, calc_gradient; rb_scan_args(argc, argv, "61", &points, &alpha, &beta, &gamma, &window, &criteria, &calc_gradient); CvPoint *pointset = 0; int length = CVPOINTS_FROM_POINT_SET(points, &pointset); int coeff = (TYPE(alpha) == T_ARRAY && TYPE(beta) == T_ARRAY && TYPE(gamma) == T_ARRAY) ? CV_ARRAY : CV_VALUE; float *a = 0, *b = 0, *c = 0; IplImage stub; int i; if (coeff == CV_VALUE) { float buff_a, buff_b, buff_c; buff_a = (float)NUM2DBL(alpha); buff_b = (float)NUM2DBL(beta); buff_c = (float)NUM2DBL(gamma); a = &buff_a; b = &buff_b; c = &buff_c; } else { // CV_ARRAY if ((RARRAY_LEN(alpha) != length) || (RARRAY_LEN(beta) != length) || (RARRAY_LEN(gamma) != length)) rb_raise(rb_eArgError, "alpha, beta, gamma should be same size of points"); a = ALLOCA_N(float, length); b = ALLOCA_N(float, length); c = ALLOCA_N(float, length); for (i = 0; i < length; ++i) { a[i] = (float)NUM2DBL(RARRAY_PTR(alpha)[i]); b[i] = (float)NUM2DBL(RARRAY_PTR(beta)[i]); c[i] = (float)NUM2DBL(RARRAY_PTR(gamma)[i]); } } CvSize win = VALUE_TO_CVSIZE(window); CvTermCriteria tc = VALUE_TO_CVTERMCRITERIA(criteria); try { cvSnakeImage(cvGetImage(CVARR(self), &stub), pointset, length, a, b, c, coeff, win, tc, IF_BOOL(calc_gradient, 1, 0, 1)); } catch (cv::Exception& e) { if (pointset != NULL) cvFree(&pointset); raise_cverror(e); } VALUE result = rb_ary_new2(length); for (i = 0; i < length; ++i) rb_ary_push(result, cCvPoint::new_object(pointset[i])); cvFree(&pointset); return result; } |
#sobel(xorder, yorder, aperture_size = 3) ⇒ CvMat
Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 |
# File 'ext/opencv/cvmat.cpp', line 3650 VALUE rb_sobel(int argc, VALUE *argv, VALUE self) { VALUE xorder, yorder, dest, ksize; rb_scan_args(argc, argv, "3", &xorder, &yorder, &ksize); // aperture_size = INT2FIX(3); CvMat* self_ptr = CVMAT(self); switch(CV_MAT_DEPTH(self_ptr->type)) { case CV_8U: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_8U, 1); break; case CV_32F: dest = new_mat_kind_object(cvGetSize(self_ptr), self, CV_32F, 1); break; default: rb_raise(rb_eArgError, "source depth should be CV_8U or CV_32F."); break; } try { const cv::Mat selfMat(CVMAT(self)); // WBH convert openCv1-style cvMat to openCv2-style cv::Mat cv::Mat destMat(CVMAT(dest)); cv::Sobel(selfMat, destMat, CV_MAT_DEPTH(self_ptr->type), NUM2INT(xorder), NUM2INT(yorder), NUM2INT(ksize)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#split ⇒ Array<CvMat>
Divides a multi-channel array into several single-channel arrays.
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 |
# File 'ext/opencv/cvmat.cpp', line 1550 VALUE rb_split(VALUE self) { CvArr* self_ptr = CVARR(self); int type = cvGetElemType(self_ptr); int depth = CV_MAT_DEPTH(type), channel = CV_MAT_CN(type); VALUE dest = rb_ary_new2(channel); try { CvArr *dest_ptr[] = { NULL, NULL, NULL, NULL }; CvSize size = cvGetSize(self_ptr); for (int i = 0; i < channel; ++i) { VALUE tmp = new_mat_kind_object(size, self, depth, 1); rb_ary_store(dest, i, tmp); dest_ptr[i] = CVARR(tmp); } cvSplit(self_ptr, dest_ptr[0], dest_ptr[1], dest_ptr[2], dest_ptr[3]); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#sqrt ⇒ Object
Calculates a square root of array elements.
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 |
# File 'ext/opencv/cvmat.cpp', line 1850 VALUE rb_sqrt(VALUE self) { CvArr* self_ptr = CVARR(self); VALUE dest = new_mat_kind_object(cvGetSize(self_ptr), self); try { const cv::Mat srcMat(CVMAT(self)); cv::Mat dstMat(CVMAT(dest)); cv::sqrt(srcMat, dstMat); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#square? ⇒ Boolean
Returns whether the matrix is a square.
674 675 676 677 678 679 |
# File 'ext/opencv/cvmat.cpp', line 674 VALUE rb_square_q(VALUE self) { CvMat *mat = CVMAT(self); return mat->width == mat->height ? Qtrue : Qfalse; } |
#sub(val, mask = nil) ⇒ CvMat Also known as: -
Calculates the per-element difference between two arrays or array and a scalar.
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 |
# File 'ext/opencv/cvmat.cpp', line 1794 VALUE rb_sub(int argc, VALUE *argv, VALUE self) { VALUE val, mask, dest; rb_scan_args(argc, argv, "11", &val, &mask); dest = copy(self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvSub(CVARR(self), CVARR(val), CVARR(dest), MASK(mask)); else cvSubS(CVARR(self), VALUE_TO_CVSCALAR(val), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#sub_rect(rect) ⇒ CvMat #sub_rect(topleft, size) ⇒ CvMat #sub_rect(x, y, width, height) ⇒ CvMat Also known as: subrect
Returns matrix corresponding to the rectangular sub-array of input image or matrix
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'ext/opencv/cvmat.cpp', line 722 VALUE rb_sub_rect(VALUE self, VALUE args) { CvRect area; CvPoint topleft; CvSize size; switch(RARRAY_LEN(args)) { case 1: area = VALUE_TO_CVRECT(RARRAY_PTR(args)[0]); break; case 2: topleft = VALUE_TO_CVPOINT(RARRAY_PTR(args)[0]); size = VALUE_TO_CVSIZE(RARRAY_PTR(args)[1]); area.x = topleft.x; area.y = topleft.y; area.width = size.width; area.height = size.height; break; case 4: area.x = NUM2INT(RARRAY_PTR(args)[0]); area.y = NUM2INT(RARRAY_PTR(args)[1]); area.width = NUM2INT(RARRAY_PTR(args)[2]); area.height = NUM2INT(RARRAY_PTR(args)[3]); break; default: rb_raise(rb_eArgError, "wrong number of arguments (%ld of 1 or 2 or 4)", RARRAY_LEN(args)); } CvMat* mat = NULL; try { mat = cvGetSubRect(CVARR(self), RB_CVALLOC(CvMat), area); } catch (cv::Exception& e) { raise_cverror(e); } return DEPEND_OBJECT(rb_klass, mat, self); } |
#subspace_project(w, mean) ⇒ Object
6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 |
# File 'ext/opencv/cvmat.cpp', line 6508 VALUE rb_subspace_project(VALUE self, VALUE w, VALUE mean) { VALUE projection; try { cv::Mat w_mat(CVMAT_WITH_CHECK(w)); cv::Mat mean_mat(CVMAT_WITH_CHECK(mean)); cv::Mat self_mat(CVMAT(self)); cv::Mat pmat = cv::subspaceProject(w_mat, mean_mat, self_mat); projection = new_object(pmat.rows, pmat.cols, pmat.type()); CvMat tmp = pmat; cvCopy(&tmp, CVMAT(projection)); } catch (cv::Exception& e) { raise_cverror(e); } return projection; } |
#subspace_reconstruct(w, mean) ⇒ Object
6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 |
# File 'ext/opencv/cvmat.cpp', line 6532 VALUE rb_subspace_reconstruct(VALUE self, VALUE w, VALUE mean) { VALUE result; try { cv::Mat w_mat(CVMAT_WITH_CHECK(w)); cv::Mat mean_mat(CVMAT_WITH_CHECK(mean)); cv::Mat self_mat(CVMAT(self)); cv::Mat rmat = cv::subspaceReconstruct(w_mat, mean_mat, self_mat); result = new_object(rmat.rows, rmat.cols, rmat.type()); CvMat tmp = rmat; cvCopy(&tmp, CVMAT(result)); } catch (cv::Exception& e) { raise_cverror(e); } return result; } |
#sum ⇒ CvScalar
Calculates the sum of array elements.
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 |
# File 'ext/opencv/cvmat.cpp', line 2403 VALUE rb_sum(VALUE self) { CvScalar sum; try { sum = cvSum(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return cCvScalar::new_object(sum); } |
#svd(flag = 0) ⇒ Array<CvMat>
Performs SVD of a matrix
2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 |
# File 'ext/opencv/cvmat.cpp', line 2873 VALUE rb_svd(int argc, VALUE *argv, VALUE self) { VALUE _flag = Qnil; int flag = 0; if (rb_scan_args(argc, argv, "01", &_flag) > 0) { flag = NUM2INT(_flag); } CvMat* self_ptr = CVMAT(self); VALUE w = new_mat_kind_object(cvSize(self_ptr->cols, self_ptr->rows), self); int rows = 0; int cols = 0; if (flag & CV_SVD_U_T) { rows = MIN(self_ptr->rows, self_ptr->cols); cols = self_ptr->rows; } else { rows = self_ptr->rows; cols = MIN(self_ptr->rows, self_ptr->cols); } VALUE u = new_mat_kind_object(cvSize(cols, rows), self); if (flag & CV_SVD_V_T) { rows = MIN(self_ptr->rows, self_ptr->cols); cols = self_ptr->cols; } else { rows = self_ptr->cols; cols = MIN(self_ptr->rows, self_ptr->cols); } VALUE v = new_mat_kind_object(cvSize(cols, rows), self); cvSVD(self_ptr, CVARR(w), CVARR(u), CVARR(v), flag); return rb_ary_new3(3, w, u, v); } |
#threshold(threshold, max_value, threshold_type) ⇒ CvMat #threshold(threshold, max_value, threshold_type, use_otsu) ⇒ Array<CvMat, Number>
Applies a fixed-level threshold to each array element.
4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 |
# File 'ext/opencv/cvmat.cpp', line 4933 VALUE rb_threshold(int argc, VALUE *argv, VALUE self) { VALUE threshold, max_value, threshold_type, use_otsu; rb_scan_args(argc, argv, "31", &threshold, &max_value, &threshold_type, &use_otsu); const int INVALID_TYPE = -1; int type = CVMETHOD("THRESHOLD_TYPE", threshold_type, INVALID_TYPE); if (type == INVALID_TYPE) rb_raise(rb_eArgError, "Invalid threshold type."); return rb_threshold_internal(type, threshold, max_value, use_otsu, self); } |
#to_16s ⇒ CvMat
Converts the matrix to 16bit signed.
610 611 612 613 614 |
# File 'ext/opencv/cvmat.cpp', line 610 VALUE rb_to_16s(VALUE self) { return rb_to_X_internal(self, CV_16S); } |
#to_16u ⇒ CvMat
Converts the matrix to 16bit unsigned.
598 599 600 601 |
# File 'ext/opencv/cvmat.cpp', line 598 VALUE rb_to_16u(VALUE self) { return rb_to_X_internal(self, CV_16U); } |
#to_32f ⇒ CvMat
Converts the matrix to 32bit float.
636 637 638 639 640 |
# File 'ext/opencv/cvmat.cpp', line 636 VALUE rb_to_32f(VALUE self) { return rb_to_X_internal(self, CV_32F); } |
#to_32s ⇒ CvMat
Converts the matrix to 32bit signed.
623 624 625 626 627 |
# File 'ext/opencv/cvmat.cpp', line 623 VALUE rb_to_32s(VALUE self) { return rb_to_X_internal(self, CV_32S); } |
#to_64f ⇒ CvMat
Converts the matrix to 64bit float.
649 650 651 652 653 |
# File 'ext/opencv/cvmat.cpp', line 649 VALUE rb_to_64f(VALUE self) { return rb_to_X_internal(self, CV_64F); } |
#to_8s ⇒ CvMat
Converts the matrix to 8bit signed.
585 586 587 588 589 |
# File 'ext/opencv/cvmat.cpp', line 585 VALUE rb_to_8s(VALUE self) { return rb_to_X_internal(self, CV_8S); } |
#to_8u ⇒ CvMat
Converts the matrix to 8bit unsigned.
572 573 574 575 576 |
# File 'ext/opencv/cvmat.cpp', line 572 VALUE rb_to_8u(VALUE self) { return rb_to_X_internal(self, CV_8U); } |
#to_CvMat ⇒ CvMat
Converts an object to CvMat
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'ext/opencv/cvmat.cpp', line 689 VALUE rb_to_CvMat(VALUE self) { // CvMat#to_CvMat aborts when self's class is CvMat. if (CLASS_OF(self) == rb_klass) return self; CvMat *mat = NULL; try { mat = cvGetMat(CVARR(self), RB_CVALLOC(CvMat)); } catch (cv::Exception& e) { raise_cverror(e); } return DEPEND_OBJECT(rb_klass, mat, self); } |
#to_IplConvKernel(anchor) ⇒ IplConvKernel
Creates a structuring element from the matrix for morphological operations.
404 405 406 407 408 409 410 411 412 |
# File 'ext/opencv/cvmat.cpp', line 404 VALUE rb_to_IplConvKernel(VALUE self, VALUE anchor) { CvMat *src = CVMAT(self); CvPoint p = VALUE_TO_CVPOINT(anchor); IplConvKernel *kernel = rb_cvCreateStructuringElementEx(src->cols, src->rows, p.x, p.y, CV_SHAPE_CUSTOM, src->data.i); return DEPEND_OBJECT(cIplConvKernel::rb_class(), kernel, self); } |
#to_s ⇒ String
Returns String representation of the matrix.
353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'ext/opencv/cvmat.cpp', line 353 VALUE rb_to_s(VALUE self) { const int i = 6; VALUE str[i]; str[0] = rb_str_new2("<%s:%dx%d,depth=%s,channel=%d>"); str[1] = rb_str_new2(rb_class2name(CLASS_OF(self))); str[2] = rb_width(self); str[3] = rb_height(self); str[4] = rb_depth(self); str[5] = rb_channel(self); return rb_f_sprintf(i, str); } |
#trace ⇒ CvScalar
Returns the trace of a matrix.
2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 |
# File 'ext/opencv/cvmat.cpp', line 2746 VALUE rb_trace(VALUE self) { CvScalar scalar; try { scalar = cvTrace(CVARR(self)); } catch (cv::Exception& e) { raise_cverror(e); } return cCvScalar::new_object(scalar); } |
#transform(transmat, shiftvec = nil) ⇒ CvMat
Performs the matrix transformation of every array element.
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 |
# File 'ext/opencv/cvmat.cpp', line 2652 VALUE rb_transform(int argc, VALUE *argv, VALUE self) { VALUE transmat, shiftvec; rb_scan_args(argc, argv, "11", &transmat, &shiftvec); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvTransform(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(transmat), NIL_P(shiftvec) ? NULL : CVMAT_WITH_CHECK(shiftvec)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#transpose ⇒ CvMat Also known as: t
Transposes a matrix.
2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 |
# File 'ext/opencv/cvmat.cpp', line 2766 VALUE rb_transpose(VALUE self) { CvMat* self_ptr = CVMAT(self); VALUE dest = new_mat_kind_object(cvSize(self_ptr->rows, self_ptr->cols), self); try { cvTranspose(self_ptr, CVARR(dest)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#vector? ⇒ Boolean
Returns whether the matrix is a vector.
661 662 663 664 665 666 |
# File 'ext/opencv/cvmat.cpp', line 661 VALUE rb_vector_q(VALUE self) { CvMat *mat = CVMAT(self); return (mat->width == 1|| mat->height == 1) ? Qtrue : Qfalse; } |
#vector_magnitude! ⇒ Object
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'ext/opencv/cvmat.cpp', line 1066 VALUE rb_vector_magnitude(VALUE self) { CvMat* self_ptr = CVMAT(self); int type = self_ptr->type, depth = CV_MAT_DEPTH(type), channel = CV_MAT_CN(type); CvArr* mat_ptr = CVARR(self); CvScalar this_scalar; CvSize arrSize = cvGetSize(CVARR(self)); for(int i=0;i<(arrSize.height*arrSize.width)-1;i++) { this_scalar = cvGet1D(mat_ptr, i); int sum_of_squares = this_scalar.val[0]*this_scalar.val[0] + this_scalar.val[1]*this_scalar.val[1] + this_scalar.val[2]*this_scalar.val[2]; cvSet1D(CVARR(self), i, cvScalar(sqrt(sum_of_squares), 0, 0, 0)); } return self; } |
#warp_affine(map_matrix, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies an affine transformation to an image.
4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 |
# File 'ext/opencv/cvmat.cpp', line 4209 VALUE rb_warp_affine(int argc, VALUE *argv, VALUE self) { VALUE map_matrix, flags_val, fill_value; VALUE dest = Qnil; if (rb_scan_args(argc, argv, "12", &map_matrix, &flags_val, &fill_value) < 3) fill_value = INT2FIX(0); CvArr* self_ptr = CVARR(self); int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val); try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvWarpAffine(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix), flags, VALUE_TO_CVSCALAR(fill_value)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#warp_perspective(map_matrix, flags = CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS, fillval = 0) ⇒ CvMat
Applies a perspective transformation to an image.
4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 |
# File 'ext/opencv/cvmat.cpp', line 4358 VALUE rb_warp_perspective(int argc, VALUE *argv, VALUE self) { VALUE map_matrix, flags_val, option, fillval; if (rb_scan_args(argc, argv, "13", &map_matrix, &flags_val, &option, &fillval) < 4) fillval = INT2FIX(0); CvArr* self_ptr = CVARR(self); VALUE dest = Qnil; int flags = NIL_P(flags_val) ? (CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS) : NUM2INT(flags_val); try { dest = new_mat_kind_object(cvGetSize(self_ptr), self); cvWarpPerspective(self_ptr, CVARR(dest), CVMAT_WITH_CHECK(map_matrix), flags, VALUE_TO_CVSCALAR(fillval)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#watershed(markers) ⇒ CvMat
Performs a marker-based image segmentation using the watershed algorithm.
5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 |
# File 'ext/opencv/cvmat.cpp', line 5452 VALUE rb_watershed(VALUE self, VALUE markers) { try { cvWatershed(CVARR(self), CVARR_WITH_CHECK(markers)); } catch (cv::Exception& e) { raise_cverror(e); } return markers; } |
#width ⇒ Integer Also known as: columns, cols
Returns number of columns of the matrix.
438 439 440 441 442 |
# File 'ext/opencv/cvmat.cpp', line 438 VALUE rb_width(VALUE self) { return INT2NUM(CVMAT(self)->width); } |
#xor(val, mask = nil) ⇒ CvMat Also known as: ^
Calculates the per-element bit-wise "exclusive or" operation on two arrays or an array and a scalar.
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'ext/opencv/cvmat.cpp', line 2044 VALUE rb_xor(int argc, VALUE *argv, VALUE self) { VALUE val, mask, dest; rb_scan_args(argc, argv, "11", &val, &mask); dest = copy(self); try { if (rb_obj_is_kind_of(val, rb_klass)) cvXor(CVARR(self), CVARR(val), CVARR(dest), MASK(mask)); else cvXorS(CVARR(self), VALUE_TO_CVSCALAR(val), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } |
#zero?(x, y) ⇒ Boolean
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
# File 'ext/opencv/cvmat.cpp', line 1048 VALUE rb_zero_q(VALUE self, VALUE x, VALUE y) { CvScalar scalar; try { scalar = cvGet2D(CVARR(self), NUM2INT(y), NUM2INT(x)); } catch (cv::Exception& e) { raise_cverror(e); } return (scalar.val[0] == 0 && scalar.val[1] == 0 && scalar.val[2] == 0 && scalar.val[3] == 0) ? Qtrue : Qfalse; } |