/// <summary> /// Applies the Stroke Width Transform operator followed by filtering of connected components of similar Stroke Widths to /// return letter candidates. It also chain them by proximity and size, saving the result in chainBBs. /// </summary> /// <param name="input">input the input image with 3 channels.</param> /// <param name="darkOnLight">a boolean value signifying whether the text is darker or lighter than the background, /// it is observed to reverse the gradient obtained from Scharr operator, and significantly affect the result.</param> /// <param name="draw">an optional Mat of type CV_8UC3 which visualises the detected letters using bounding boxes.</param> /// <param name="chainBBs">an optional parameter which chains the letter candidates according to heuristics in the /// paper and returns all possible regions where text is likely to occur.</param> /// <returns>a vector of resulting bounding boxes where probability of finding text is high</returns> public static Rect[] DetectTextSWT( InputArray input, bool darkOnLight, OutputArray?draw = null, OutputArray?chainBBs = null) { if (input == null) { throw new ArgumentNullException(nameof(input)); } input.ThrowIfDisposed(); draw?.ThrowIfNotReady(); chainBBs?.ThrowIfNotReady(); using var result = new VectorOfRect(); NativeMethods.HandleException( NativeMethods.text_detectTextSWT( input.CvPtr, result.CvPtr, darkOnLight ? 1 : 0, draw?.CvPtr ?? IntPtr.Zero, chainBBs?.CvPtr ?? IntPtr.Zero)); GC.KeepAlive(input); draw?.Fix(); chainBBs?.Fix(); return(result.ToArray()); }
/// <summary> /// Finds the neighbors and predicts responses for input vectors. /// </summary> /// <param name="samples">Input samples stored by rows. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <param name="k">Number of used nearest neighbors. Should be greater than 1.</param> /// <param name="results">Vector with results of prediction (regression or classification) for each /// input sample. It is a single-precision floating-point vector with `[number_of_samples]` elements.</param> /// <param name="neighborResponses">neighborResponses Optional output values for corresponding neighbors. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <param name="dist">Optional output distances from the input vectors to the corresponding neighbors. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <returns></returns> public float FindNearest(InputArray samples, int k, OutputArray results, OutputArray neighborResponses = null, OutputArray dist = null) { if (disposed) { throw new ObjectDisposedException(GetType().Name); } if (samples == null) { throw new ArgumentNullException(nameof(samples)); } if (results == null) { throw new ArgumentNullException(nameof(results)); } samples.ThrowIfDisposed(); results.ThrowIfNotReady(); float ret = NativeMethods.ml_KNearest_findNearest( ptr, samples.CvPtr, k, results.CvPtr, Cv2.ToPtr(neighborResponses), Cv2.ToPtr(dist)); GC.KeepAlive(samples); results.Fix(); neighborResponses?.Fix(); dist?.Fix(); return(ret); }
/// <summary> /// Finds the neighbors and predicts responses for input vectors. /// </summary> /// <param name="samples">Input samples stored by rows. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <param name="k">Number of used nearest neighbors. Should be greater than 1.</param> /// <param name="results">Vector with results of prediction (regression or classification) for each /// input sample. It is a single-precision floating-point vector with `[number_of_samples]` elements.</param> /// <param name="neighborResponses">neighborResponses Optional output values for corresponding neighbors. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <param name="dist">Optional output distances from the input vectors to the corresponding neighbors. /// It is a single-precision floating-point matrix of `[number_of_samples] * k` size.</param> /// <returns></returns> public float FindNearest(InputArray samples, int k, OutputArray results, OutputArray?neighborResponses = null, OutputArray?dist = null) { ThrowIfDisposed(); if (samples == null) { throw new ArgumentNullException(nameof(samples)); } if (results == null) { throw new ArgumentNullException(nameof(results)); } samples.ThrowIfDisposed(); results.ThrowIfNotReady(); NativeMethods.HandleException( NativeMethods.ml_KNearest_findNearest( ptr, samples.CvPtr, k, results.CvPtr, Cv2.ToPtr(neighborResponses), Cv2.ToPtr(dist), out var ret)); GC.KeepAlive(this); GC.KeepAlive(samples); GC.KeepAlive(results); GC.KeepAlive(neighborResponses); GC.KeepAlive(dist); results.Fix(); neighborResponses?.Fix(); dist?.Fix(); return(ret); }
/// <summary> /// computes a background image /// </summary> /// <param name="backgroundImage"></param> public virtual void GetBackgroundImage(OutputArray backgroundImage) { if (backgroundImage == null) throw new ArgumentNullException("backgroundImage"); backgroundImage.ThrowIfNotReady(); NativeMethods.video_BackgroundSubtractor_getBackgroundImage(ptr, backgroundImage.CvPtr); backgroundImage.Fix(); }
/// <summary> /// /// </summary> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="colormap"></param> public static void ApplyColorMap(InputArray src, OutputArray dst, ColorMapMode colormap) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.contrib_applyColorMap(src.CvPtr, dst.CvPtr, (int)colormap); dst.Fix(); }
/// <summary> /// Perform image denoising using Non-local Means Denoising algorithm /// with several computational optimizations. Noise expected to be a gaussian white noise /// </summary> /// <param name="src">Input 8-bit 1-channel, 2-channel or 3-channel image.</param> /// <param name="dst">Output image with the same size and type as src .</param> /// <param name="h"> /// Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, /// smaller h value preserves details but also preserves some noise</param> /// <param name="templateWindowSize"> /// Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels</param> /// <param name="searchWindowSize"> /// Size in pixels of the window that is used to compute weighted average for given pixel. /// Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels</param> public static void FastNlMeansDenoising(InputArray src, OutputArray dst, float h = 3, int templateWindowSize = 7, int searchWindowSize = 21) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.photo_fastNlMeansDenoising(src.CvPtr, dst.CvPtr, h, templateWindowSize, searchWindowSize); dst.Fix(); }
/// <summary> /// Forms a border around the image /// </summary> /// <param name="src">The source image</param> /// <param name="dst">The destination image; will have the same type as src and /// the size Size(src.cols+left+right, src.rows+top+bottom)</param> /// <param name="top">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param> /// <param name="bottom">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param> /// <param name="left">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param> /// <param name="right">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param> /// <param name="borderType">The border type</param> /// <param name="value">The border value if borderType == Constant</param> public static void CopyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, BorderType borderType, Scalar? value = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); Scalar value0 = value.GetValueOrDefault(new Scalar()); NativeMethods.imgproc_copyMakeBorder(src.CvPtr, dst.CvPtr, top, bottom, left, right, (int)borderType, value0); dst.Fix(); }
/// <summary> /// converts rotation vector to rotation matrix or vice versa using Rodrigues transformation /// </summary> /// <param name="src">Input rotation vector (3x1 or 1x3) or rotation matrix (3x3).</param> /// <param name="dst">Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively.</param> /// <param name="jacobian">Optional output Jacobian matrix, 3x9 or 9x3, which is a matrix of partial derivatives of the output array components with respect to the input array components.</param> public static void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.calib3d_Rodrigues(src.CvPtr, dst.CvPtr, ToPtr(jacobian)); dst.Fix(); if (jacobian != null) jacobian.Fix(); }
/// <summary> /// Pose estimation for single markers /// </summary> /// <param name="corners">corners vector of already detected markers corners. /// For each marker, its four corners are provided, (e.g std::vector<std::vector<cv::Point2f>> ). /// For N detected markers, the dimensions of this array should be Nx4. The order of the corners should be clockwise.</param> /// <param name="markerLength">the length of the markers' side. The returning translation vectors will /// be in the same unit.Normally, unit is meters.</param> /// <param name="cameraMatrix">input 3x3 floating-point camera matrix /// \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$</param> /// <param name="distortionCoefficients">vector of distortion coefficients /// \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements</param> /// <param name="rvec">array of output rotation vectors (@sa Rodrigues) (e.g. std::vector<cv::Vec3d>). /// Each element in rvecs corresponds to the specific marker in imgPoints.</param> /// <param name="tvec">array of output translation vectors (e.g. std::vector<cv::Vec3d>). /// Each element in tvecs corresponds to the specific marker in imgPoints.</param> /// <param name="objPoints">array of object points of all the marker corners</param> public static void EstimatePoseSingleMarkers( Point2f[][] corners, float markerLength, InputArray cameraMatrix, InputArray distortionCoefficients, OutputArray rvec, OutputArray tvec, OutputArray?objPoints = null) { if (corners == null) { throw new ArgumentNullException(nameof(corners)); } if (cameraMatrix == null) { throw new ArgumentNullException(nameof(cameraMatrix)); } if (distortionCoefficients == null) { throw new ArgumentNullException(nameof(distortionCoefficients)); } if (rvec == null) { throw new ArgumentNullException(nameof(rvec)); } if (tvec == null) { throw new ArgumentNullException(nameof(tvec)); } cameraMatrix.ThrowIfDisposed(); distortionCoefficients.ThrowIfDisposed(); rvec.ThrowIfNotReady(); tvec.ThrowIfNotReady(); objPoints?.ThrowIfNotReady(); using var cornersAddress = new ArrayAddress2 <Point2f>(corners); NativeMethods.HandleException( NativeMethods.aruco_estimatePoseSingleMarkers( cornersAddress.GetPointer(), cornersAddress.GetDim1Length(), cornersAddress.GetDim2Lengths(), markerLength, cameraMatrix.CvPtr, distortionCoefficients.CvPtr, rvec.CvPtr, tvec.CvPtr, objPoints?.CvPtr ?? IntPtr.Zero)); GC.KeepAlive(cameraMatrix); GC.KeepAlive(distortionCoefficients); rvec.Fix(); tvec.Fix(); objPoints?.Fix(); }
/// <summary> /// the update operator that takes the next video frame and returns the current foreground mask as 8-bit binary image. /// </summary> /// <param name="image"></param> /// <param name="fgmask"></param> /// <param name="learningRate"></param> public virtual void Apply(InputArray image, OutputArray fgmask, double learningRate = -1) { if (image == null) throw new ArgumentNullException("image"); if (fgmask == null) throw new ArgumentNullException("fgmask"); image.ThrowIfDisposed(); fgmask.ThrowIfNotReady(); NativeMethods.video_BackgroundSubtractor_apply(ptr, image.CvPtr, fgmask.CvPtr, learningRate); fgmask.Fix(); GC.KeepAlive(image); }
/// <summary> /// restores the damaged image areas using one of the available intpainting algorithms /// </summary> /// <param name="src"></param> /// <param name="inpaintMask"></param> /// <param name="dst"></param> /// <param name="inpaintRadius"></param> /// <param name="flags"></param> public static void Inpaint(InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, InpaintMethod flags) { if (src == null) throw new ArgumentNullException("src"); if (inpaintMask == null) throw new ArgumentNullException("inpaintMask"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); inpaintMask.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.photo_inpaint(src.CvPtr, inpaintMask.CvPtr, dst.CvPtr, inpaintRadius, (int)flags); dst.Fix(); }
/// <summary> /// Applies white balancing to the input image. /// </summary> /// <param name="src">Input image</param> /// <param name="dst">White balancing result</param> public override void BalanceWhite(InputArray src, OutputArray dst) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.xphoto_LearningBasedWB_balanceWhite(this.ptr, src.CvPtr, dst.CvPtr); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Implements the feature extraction part of the algorithm. /// </summary> /// <param name="src">Input three-channel image (BGR color space is assumed).</param> /// <param name="dst">An array of four (r,g) chromaticity tuples corresponding to the features listed above.</param> public void ExtractSimpleFeatures(InputArray src, OutputArray dst) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.xphoto_LearningBasedWB_extractSimpleFeatures(this.ptr, src.CvPtr, dst.CvPtr); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Implements an efficient fixed-point approximation for applying channel gains, /// which is the last step of multiple white balance algorithms. /// </summary> /// <param name="src">Input three-channel image in the BGR color space (either CV_8UC3 or CV_16UC3)</param> /// <param name="dst">Output image of the same size and type as src.</param> /// <param name="gainB">gain for the B channel</param> /// <param name="gainG">gain for the G channel</param> /// <param name="gainR">gain for the R channel</param> public static void ApplyChannelGains(InputArray src, OutputArray dst, float gainB, float gainG, float gainR) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.xphoto_applyChannelGains(src.CvPtr, dst.CvPtr, gainB, gainG, gainR); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// static method for computing quality /// </summary> /// <param name="ref"></param> /// <param name="cmp"></param> /// <param name="qualityMap">output quality map, or null</param> /// <returns>cv::Scalar with per-channel quality values. Values range from 0 (worst) to 1 (best)</returns> public static Scalar Compute(InputArray @ref, InputArray cmp, OutputArray? qualityMap) { if (@ref == null) throw new ArgumentNullException(nameof(@ref)); if (cmp == null) throw new ArgumentNullException(nameof(cmp)); @ref.ThrowIfDisposed(); cmp.ThrowIfDisposed(); qualityMap?.ThrowIfNotReady(); var ret = NativeMethods.quality_QualityGMSD_staticCompute(@ref.CvPtr, cmp.CvPtr, qualityMap?.CvPtr ?? IntPtr.Zero); GC.KeepAlive(@ref); GC.KeepAlive(cmp); qualityMap?.Fix(); return ret; }
/// <summary> /// Computes squared magnitudes of complex matrix elements. /// </summary> /// <param name="xy">Source complex matrix in the interleaved format ( CV_32FC2 ).</param> /// <param name="magnitude">Destination matrix of float magnitude squares ( CV_32FC1 ).</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void magnitudeSqr(InputArray xy, OutputArray magnitude, Stream stream = null) { if (xy == null) { throw new ArgumentNullException(nameof(xy)); } if (magnitude == null) { throw new ArgumentNullException(nameof(magnitude)); } xy.ThrowIfDisposed(); magnitude.ThrowIfNotReady(); NativeMethods.cuda_arithm_magnitudeSqr_0(xy.CvPtr, magnitude.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(xy); GC.KeepAlive(magnitude); magnitude.Fix(); }
/// <summary> /// normalizes the grayscale image brightness and contrast by normalizing its histogram /// </summary> /// <param name="src">The source 8-bit single channel image</param> /// <param name="dst">The destination image; will have the same size and the same type as src</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void equalizeHist(InputArray src, OutputArray dst, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_imgproc_equalizeHist(src.CvPtr, dst.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Applies a fixed-level threshold to each array element. /// </summary> /// <param name="src">Source array (single-channel).</param> /// <param name="dst">Destination array with the same size and type as src .</param> /// <param name="thresh">Threshold value.</param> /// <param name="maxval">Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.</param> /// <param name="type">Threshold type. For details, see threshold . The THRESH_OTSU and THRESH_TRIANGLE /// threshold types are not supported.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void threshold(InputArray src, OutputArray dst, double thresh, double maxval, ThresholdTypes type, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_arithm_threshold(src.CvPtr, dst.CvPtr, thresh, maxval, (int)type, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Calculates a histogram with evenly distributed bins. /// </summary> /// <param name="src">Source image. CV_8U, CV_16U, or CV_16S depth and 1 or 4 channels are supported. For /// a four-channel image, all channels are processed separately.</param> /// <param name="hist">Destination histogram with one row, histSize columns, and the CV_32S type.</param> /// <param name="histSize">Size of the histogram.</param> /// <param name="lowerLevel">Lower boundary of lowest-level bin.</param> /// <param name="upperLevel">Upper boundary of highest-level bin.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void histEven(InputArray src, OutputArray hist, int histSize, int lowerLevel, int upperLevel, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (hist == null) { throw new ArgumentNullException(nameof(hist)); } src.ThrowIfDisposed(); hist.ThrowIfNotReady(); NativeMethods.cuda_imgproc_histEven_0(src.CvPtr, hist.CvPtr, histSize, lowerLevel, upperLevel, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(hist); hist.Fix(); }
/// <summary> /// Raises every matrix element to a power. /// </summary> /// <param name="src">Source matrix.</param> /// <param name="power">Exponent of power.</param> /// <param name="dst">Destination matrix with the same size and type as src .</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void pow(InputArray src, double power, OutputArray dst, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_arithm_pow(src.CvPtr, power, dst.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Draw a canonical marker image /// </summary> /// <param name="dictionary">dictionary of markers indicating the type of markers</param> /// <param name="id">identifier of the marker that will be returned. It has to be a valid id in the specified dictionary.</param> /// <param name="sidePixels">size of the image in pixels</param> /// <param name="mat">output image with the marker</param> /// <param name="borderBits">width of the marker border.</param> public static void DrawMarker(Dictionary dictionary, int id, int sidePixels, OutputArray mat, int borderBits = 1) { if (dictionary == null) { throw new ArgumentNullException(nameof(dictionary)); } if (mat == null) { throw new ArgumentNullException(nameof(mat)); } dictionary.ThrowIfDisposed(); mat.ThrowIfNotReady(); NativeMethods.aruco_drawMarker(dictionary.ObjectPtr.CvPtr, id, sidePixels, mat.CvPtr, borderBits); mat.Fix(); GC.KeepAlive(dictionary); }
/// <summary> /// Computes the estimated covariance matrix of an image using the sliding window forumlation. /// </summary> /// <remarks> /// The window size parameters control the accuracy of the estimation. /// The sliding window moves over the entire image from the top-left corner /// to the bottom right corner.Each location of the window represents a sample. /// If the window is the size of the image, then this gives the exact covariance matrix. /// For all other cases, the sizes of the window will impact the number of samples /// and the number of elements in the estimated covariance matrix. /// </remarks> /// <param name="src">The source image. Input image must be of a complex type.</param> /// <param name="dst">The destination estimated covariance matrix. Output matrix will be size (windowRows*windowCols, windowRows*windowCols).</param> /// <param name="windowRows">The number of rows in the window.</param> /// <param name="windowCols">The number of cols in the window.</param> public static void CovarianceEstimation(InputArray src, OutputArray dst, int windowRows, int windowCols) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.ximgproc_covarianceEstimation(src.CvPtr, dst.CvPtr, windowRows, windowCols); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Returns filter coefficients for computing spatial image derivatives. /// </summary> /// <param name="kx">Output matrix of row filter coefficients. It has the type ktype.</param> /// <param name="ky">Output matrix of column filter coefficients. It has the type ktype.</param> /// <param name="dx">Derivative order in respect of x.</param> /// <param name="dy">Derivative order in respect of y.</param> /// <param name="ksize">Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7.</param> /// <param name="normalize">Flag indicating whether to normalize (scale down) the filter coefficients or not. /// Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. /// If you are going to filter floating-point images, you are likely to use the normalized kernels. /// But if you compute derivatives of an 8-bit image, store the results in a 16-bit image, /// and wish to preserve all the fractional bits, you may want to set normalize = false.</param> /// <param name="ktype">Type of filter coefficients. It can be CV_32f or CV_64F.</param> public static void GetDerivKernels( OutputArray kx, OutputArray ky, int dx, int dy, int ksize, bool normalize = false, MatType? ktype = null) { if (kx == null) throw new ArgumentNullException(nameof(kx)); if (ky == null) throw new ArgumentNullException(nameof(ky)); kx.ThrowIfNotReady(); ky.ThrowIfNotReady(); var ktype0 = ktype.GetValueOrDefault(MatType.CV_32F); NativeMethods.imgproc_getDerivKernels( kx.CvPtr, ky.CvPtr, dx, dy, ksize, normalize ? 1 : 0, ktype0); kx.Fix(); ky.Fix(); }
/// <summary> /// Routines for correcting image color gamma. /// </summary> /// <param name="src">Source image (3- or 4-channel 8 bit).</param> /// <param name="dst">Destination image.</param> /// <param name="forward">true for forward gamma correction or false for inverse gamma correction.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void gammaCorrection( InputArray src, OutputArray dst, bool forward = true, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_imgproc_gammaCorrection(src.CvPtr, dst.CvPtr, forward, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Performs a per-element bitwise inversion. /// </summary> /// <param name="src">Source matrix.</param> /// <param name="dst">Destination matrix with the same size and type as src .</param> /// <param name="mask">Optional operation mask, 8-bit single channel array, that specifies elements of the /// destination array to be changed.The mask can be used only with single channel images.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void bitwise_not(InputArray src, OutputArray dst, InputArray mask = null, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_arithm_bitwise_not(src.CvPtr, dst.CvPtr, mask?.CvPtr ?? IntPtr.Zero, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); GC.KeepAlive(mask); dst.Fix(); }
/// <summary> /// Converts an image from Bayer pattern to RGB or grayscale. /// </summary> /// <param name="src">Source image (8-bit or 16-bit single channel).</param> /// <param name="dst">Destination image.</param> /// <param name="code">Color space conversion code (see the description below). /// The function can do the following transformations: /// - Demosaicing using bilinear interpolation /// > - COLOR_BayerBG2GRAY , COLOR_BayerGB2GRAY , COLOR_BayerRG2GRAY , COLOR_BayerGR2GRAY /// > - COLOR_BayerBG2BGR , COLOR_BayerGB2BGR , COLOR_BayerRG2BGR , COLOR_BayerGR2BGR /// - Demosaicing using Malvar-He-Cutler algorithm(@cite MHT2011) /// > - COLOR_BayerBG2GRAY_MHT , COLOR_BayerGB2GRAY_MHT , COLOR_BayerRG2GRAY_MHT , /// > COLOR_BayerGR2GRAY_MHT /// > - COLOR_BayerBG2BGR_MHT , COLOR_BayerGB2BGR_MHT , COLOR_BayerRG2BGR_MHT , /// > COLOR_BayerGR2BGR_MHT</param> /// <param name="dcn">Number of channels in the destination image. If the parameter is 0, the number of the /// channels is derived automatically from src and the code.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void demosaicing( InputArray src, OutputArray dst, ColorConversionCodes code, int dcn = -1, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_imgproc_demosaicing(src.CvPtr, dst.CvPtr, (int)code, dcn, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Performs anisotropic diffusian on an image. /// The function applies Perona-Malik anisotropic diffusion to an image. /// </summary> /// <param name="src">Grayscale Source image.</param> /// <param name="dst">Destination image of the same size and the same number of channels as src.</param> /// <param name="alpha">The amount of time to step forward by on each iteration (normally, it's between 0 and 1).</param> /// <param name="k">sensitivity to the edges</param> /// <param name="niters">The number of iterations</param> public static void AnisotropicDiffusion(InputArray src, OutputArray dst, float alpha, float k, int niters) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.ximgproc_anisotropicDiffusion(src.CvPtr, dst.CvPtr, alpha, k, niters); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Finds lines in the input image. /// This is the output of the default parameters of the algorithm on the above shown image. /// </summary> /// <param name="image">A grayscale (CV_8UC1) input image. If only a roi needs to be /// selected, use: `fld_ptr-\>detect(image(roi), lines, ...); /// lines += Scalar(roi.x, roi.y, roi.x, roi.y);`</param> /// <param name="lines">A vector of Vec4f elements specifying the beginning /// and ending point of a line. Where Vec4f is (x1, y1, x2, y2), /// point 1 is the start, point 2 - end.Returned lines are directed so that the /// brighter side is on their left.</param> public virtual void Detect(InputArray image, OutputArray lines) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (lines == null) { throw new ArgumentNullException(nameof(lines)); } image.ThrowIfDisposed(); lines.ThrowIfNotReady(); NativeMethods.ximgproc_FastLineDetector_detect_OutputArray(ptr, image.CvPtr, lines.CvPtr); GC.KeepAlive(image); lines.Fix(); }
/// <summary> /// Predicts responses for input samples and returns a float type. /// </summary> /// <param name="samples">The input data for the prediction algorithm. Matrix [m x n], /// where each row contains variables (features) of one object being classified. /// Should have data type CV_32F.</param> /// <param name="results">Predicted labels as a column matrix of type CV_32S.</param> /// <param name="flags">Not used.</param> /// <returns></returns> public float Predict(InputArray samples, OutputArray results = null, int flags = 0) { ThrowIfDisposed(); if (samples == null) { throw new ArgumentNullException(nameof(samples)); } samples.ThrowIfDisposed(); results?.ThrowIfNotReady(); float ret = NativeMethods.ml_LogisticRegression_predict(ptr, samples.CvPtr, Cv2.ToPtr(results), flags); GC.KeepAlive(this); GC.KeepAlive(samples); GC.KeepAlive(results); results?.Fix(); return(ret); }
/// <summary> /// Resizes an image. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image with the same type as src . The size is dsize (when it is non-zero) /// or the size is computed from src.size() , fx , and fy.</param> /// <param name="dsize">Destination image size. If it is zero, it is computed as: /// \f[\texttt{dsize = Size(round(fx* src.cols), round(fy* src.rows))}\f] /// Either dsize or both fx and fy must be non-zero.</param> /// <param name="fx">Scale factor along the horizontal axis. If it is zero, it is computed as: /// \f[\texttt{(double) dsize.width/src.cols}\f]</param> /// <param name="fy">Scale factor along the vertical axis. If it is zero, it is computed as: /// \f[\texttt{(double) dsize.height/src.rows}\f]</param> /// <param name="interpolation">interpolation Interpolation method. INTER_NEAREST , INTER_LINEAR and INTER_CUBIC are /// supported for now.</param> /// <param name="stream">Stream for the asynchronous version.</param> public static void Resize(InputArray src, OutputArray dst, Size dsize, double fx = 0, double fy = 0, InterpolationFlags interpolation = InterpolationFlags.Linear, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_warping_resize(src.CvPtr, dst.CvPtr, dsize, fx, fy, (int)interpolation, stream?.CvPtr ?? Stream.Null.CvPtr); GC.KeepAlive(src); GC.KeepAlive(dst); dst.Fix(); }
/// <summary> /// Performs image denoising using the Block-Matching and 3D-filtering algorithm /// (http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf) with several computational /// optimizations.Noise expected to be a gaussian white noise. /// </summary> /// <param name="src">Input 8-bit or 16-bit 1-channel image.</param> /// <param name="dstStep1">Output image of the first step of BM3D with the same size and type as src.</param> /// <param name="dstStep2">Output image of the second step of BM3D with the same size and type as src.</param> /// <param name="h">Parameter regulating filter strength. Big h value perfectly removes noise but also /// removes image details, smaller h value preserves details but also preserves some noise.</param> /// <param name="templateWindowSize">Size in pixels of the template patch that is used for block-matching. Should be power of 2.</param> /// <param name="searchWindowSize">Size in pixels of the window that is used to perform block-matching. /// Affect performance linearly: greater searchWindowsSize - greater denoising time. Must be larger than templateWindowSize.</param> /// <param name="blockMatchingStep1">Block matching threshold for the first step of BM3D (hard thresholding), /// i.e.maximum distance for which two blocks are considered similar.Value expressed in euclidean distance.</param> /// <param name="blockMatchingStep2">Block matching threshold for the second step of BM3D (Wiener filtering), /// i.e.maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param> /// <param name="groupSize">Maximum size of the 3D group for collaborative filtering.</param> /// <param name="slidingStep">Sliding step to process every next reference block.</param> /// <param name="beta">Kaiser window parameter that affects the sidelobe attenuation of the transform of the /// window.Kaiser window is used in order to reduce border effects.To prevent usage of the window, set beta to zero.</param> /// <param name="normType">Norm used to calculate distance between blocks. L2 is slower than L1 but yields more accurate results.</param> /// <param name="step">Step of BM3D to be executed. Allowed are only BM3D_STEP1 and BM3D_STEPALL. /// BM3D_STEP2 is not allowed as it requires basic estimate to be present.</param> /// <param name="transformType">Type of the orthogonal transform used in collaborative filtering step. /// Currently only Haar transform is supported.</param> public static void Bm3dDenoising( InputArray src, InputOutputArray dstStep1, OutputArray dstStep2, float h = 1, int templateWindowSize = 4, int searchWindowSize = 16, int blockMatchingStep1 = 2500, int blockMatchingStep2 = 400, int groupSize = 8, int slidingStep = 1, float beta = 2.0f, NormTypes normType = NormTypes.L2, Bm3dSteps step = Bm3dSteps.STEPALL, TransformTypes transformType = TransformTypes.HAAR) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dstStep1 == null) { throw new ArgumentNullException(nameof(dstStep1)); } if (dstStep2 == null) { throw new ArgumentNullException(nameof(dstStep2)); } src.ThrowIfDisposed(); dstStep1.ThrowIfNotReady(); dstStep2.ThrowIfNotReady(); NativeMethods.HandleException( NativeMethods.xphoto_bm3dDenoising1( src.CvPtr, dstStep1.CvPtr, dstStep2.CvPtr, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, (int)normType, (int)step, (int)transformType)); GC.KeepAlive(src); dstStep1.Fix(); dstStep2.Fix(); }
/// <summary> /// Recovers inverse camera response. /// </summary> /// <param name="src">vector of input images</param> /// <param name="dst">256x1 matrix with inverse camera response function</param> /// <param name="times">vector of exposure time values for each image</param> public virtual void Process(IEnumerable<Mat> src, OutputArray dst, IEnumerable<float> times) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); if (times == null) throw new ArgumentNullException("times"); dst.ThrowIfNotReady(); IntPtr[] srcArray = EnumerableEx.SelectPtrs(src); float[] timesArray = EnumerableEx.ToArray(times); if (srcArray.Length != timesArray.Length) throw new OpenCvSharpException("src.Count() != times.Count"); NativeMethods.photo_CalibrateCRF_process(ptr, srcArray, srcArray.Length, dst.CvPtr, timesArray); dst.Fix(); GC.KeepAlive(src); }
/// <summary> /// Finds edges in an image using the @cite Canny86 algorithm. /// </summary> /// <param name="image">Single-channel 8-bit input image.</param> /// <param name="edges">Output edge map. It has the same size and type as image.</param> /// <param name="stream">Stream for the asynchronous version.</param> public virtual void detect(InputArray image, OutputArray edges, Stream stream = null) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (edges == null) { throw new ArgumentNullException(nameof(edges)); } image.ThrowIfDisposed(); edges.ThrowIfNotReady(); NativeMethods.cuda_imgproc_CannyEdgeDetector_detect(ptr, image.CvPtr, edges.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); edges.Fix(); GC.KeepAlive(this); GC.KeepAlive(image); GC.KeepAlive(edges); }
/// <summary> /// The function detects edges in src and draw them to dst. /// The algorithm underlies this function is much more robust to texture presence, than common approaches, e.g.Sobel /// </summary> /// <param name="src">source image (RGB, float, in [0;1]) to detect edges</param> /// <param name="dst">destination image (grayscale, float, in [0;1]) where edges are drawn</param> public virtual void DetectEdges(InputArray src, OutputArray dst) { ThrowIfDisposed(); if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.ximgproc_StructuredEdgeDetection_detectEdges(ptr, src.CvPtr, dst.CvPtr); GC.KeepAlive(this); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Determines strong corners on an image. /// </summary> /// <param name="image">Input 8-bit or floating-point 32-bit, single-channel image.</param> /// <param name="corners">Output vector of detected corners (1-row matrix with CV_32FC2 type with corners /// positions).</param> /// <param name="mask">Optional region of interest. If the image is not empty (it needs to have the type /// CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.</param> /// <param name="stream">Stream for the asynchronous version.</param> public virtual void detect(InputArray image, OutputArray corners, InputArray mask = null, Stream stream = null) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (corners == null) { throw new ArgumentNullException(nameof(corners)); } image.ThrowIfDisposed(); corners.ThrowIfNotReady(); NativeMethods.cuda_imgproc_CornersDetector_detect(ptr, image.CvPtr, corners.CvPtr, mask?.CvPtr ?? IntPtr.Zero, stream?.CvPtr ?? Stream.Null.CvPtr); corners.Fix(); GC.KeepAlive(this); GC.KeepAlive(image); GC.KeepAlive(corners); }
/// <summary> /// Computes the motion gradient orientation image from the motion history image /// </summary> /// <param name="mhi">Motion history single-channel floating-point image.</param> /// <param name="mask">Output mask image that has the type CV_8UC1 and the same size as mhi. /// Its non-zero elements mark pixels where the motion gradient data is correct.</param> /// <param name="orientation">Output motion gradient orientation image that has the same type and the same size as mhi. /// Each pixel of the image is a motion orientation, from 0 to 360 degrees.</param> /// <param name="delta1">Minimal (or maximal) allowed difference between mhi values within a pixel neighborhood.</param> /// <param name="delta2">Maximal (or minimal) allowed difference between mhi values within a pixel neighborhood. /// That is, the function finds the minimum ( m(x,y) ) and maximum ( M(x,y) ) mhi values over 3x3 neighborhood of each pixel /// and marks the motion orientation at (x, y) as valid only if: /// min(delta1, delta2) <= M(x,y)-m(x,y) <= max(delta1, delta2).</param> /// <param name="apertureSize"></param> public static void CalcMotionGradient( InputArray mhi, OutputArray mask, OutputArray orientation, double delta1, double delta2, int apertureSize = 3) { if (mhi == null) throw new ArgumentNullException("mhi"); if (mask == null) throw new ArgumentNullException("mask"); if (orientation == null) throw new ArgumentNullException("orientation"); mhi.ThrowIfDisposed(); mask.ThrowIfNotReady(); orientation.ThrowIfNotReady(); NativeMethods.video_calcMotionGradient( mhi.CvPtr, mask.CvPtr, orientation.CvPtr, delta1, delta2, apertureSize); mask.Fix(); orientation.Fix(); }
/// <summary> /// Finds circles in a grayscale image using the Hough transform. /// </summary> /// <param name="src">8-bit, single-channel grayscale input image.</param> /// <param name="circles">Output vector of found circles. Each vector is encoded as a 3-element /// floating-point vector \f$(x, y, radius)\f$ .</param> /// <param name="stream">Stream for the asynchronous version.</param> public virtual void detect(InputArray src, OutputArray circles, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (circles == null) { throw new ArgumentNullException(nameof(circles)); } src.ThrowIfDisposed(); circles.ThrowIfNotReady(); NativeMethods.cuda_imgproc_HoughCirclesDetector_detect(ptr, src.CvPtr, circles.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); circles.Fix(); GC.KeepAlive(this); GC.KeepAlive(src); GC.KeepAlive(circles); }
/// <summary> /// Computes the cornerness criteria at each image pixel. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image containing cornerness values. It will have the same size as src and /// CV_32FC1 type.</param> /// <param name="stream">Stream for the asynchronous version.</param> public virtual void compute(InputArray src, OutputArray dst, Stream stream = null) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.cuda_imgproc_HoughCirclesDetector_compute(ptr, src.CvPtr, dst.CvPtr, stream?.CvPtr ?? Stream.Null.CvPtr); dst.Fix(); GC.KeepAlive(this); GC.KeepAlive(src); GC.KeepAlive(dst); }
/// <summary> /// Applies a binary blob thinning operation, to achieve a skeletization of the input image. /// The function transforms a binary blob image into a skeletized form using the technique of Zhang-Suen. /// </summary> /// <param name="src">Source 8-bit single-channel image, containing binary blobs, with blobs having 255 pixel values.</param> /// <param name="dst">Destination image of the same size and the same type as src. The function can work in-place.</param> /// <param name="thinningType">Value that defines which thinning algorithm should be used. </param> public static void Thinning( InputArray src, OutputArray dst, ThinningTypes thinningType = ThinningTypes.ZHANGSUEN) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.ximgproc_thinning(src.CvPtr, dst.CvPtr, (int)thinningType); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Applies Niblack thresholding to input image. /// </summary> /// <remarks><![CDATA[ /// The function transforms a grayscale image to a binary image according to the formulae: /// - **THRESH_BINARY** /// \f[dst(x, y) = \fork{\texttt{maxValue } /// }{if \(src(x, y) > T(x, y)\)}{0}{otherwise}\f] /// - ** THRESH_BINARY_INV** /// \f[dst(x, y) = \fork{0}{if \(src(x, y) > T(x, y)\)}{\texttt{maxValue}}{otherwise}\f] /// where \f$T(x, y)\f$ is a threshold calculated individually for each pixel. /// The threshold value \f$T(x, y)\f$ is the mean minus \f$ delta \f$ times standard deviation /// of \f$\texttt{blockSize} \times\texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$. /// The function can't process the image in-place. /// ]]></remarks> /// <param name="src">Source 8-bit single-channel image.</param> /// <param name="dst">Destination image of the same size and the same type as src.</param> /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied, /// used with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.</param> /// <param name="type">Thresholding type, see cv::ThresholdTypes.</param> /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param> /// <param name="delta">Constant multiplied with the standard deviation and subtracted from the mean. /// Normally, it is taken to be a real number between 0 and 1.</param> public static void NiblackThreshold( InputArray src, OutputArray dst, double maxValue, ThresholdTypes type, int blockSize, double delta) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.ximgproc_niBlackThreshold(src.CvPtr, dst.CvPtr, maxValue, (int)type, blockSize, delta); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Constructs a pyramid which can be used as input for calcOpticalFlowPyrLK /// </summary> /// <param name="img">8-bit input image.</param> /// <param name="pyramid">output pyramid.</param> /// <param name="winSize">window size of optical flow algorithm. /// Must be not less than winSize argument of calcOpticalFlowPyrLK(). /// It is needed to calculate required padding for pyramid levels.</param> /// <param name="maxLevel">0-based maximal pyramid level number.</param> /// <param name="withDerivatives">set to precompute gradients for the every pyramid level. /// If pyramid is constructed without the gradients then calcOpticalFlowPyrLK() will /// calculate them internally.</param> /// <param name="pyrBorder">the border mode for pyramid layers.</param> /// <param name="derivBorder">the border mode for gradients.</param> /// <param name="tryReuseInputImage">put ROI of input image into the pyramid if possible. /// You can pass false to force data copying.</param> /// <returns>number of levels in constructed pyramid. Can be less than maxLevel.</returns> public static int BuildOpticalFlowPyramid( InputArray img, OutputArray pyramid, Size winSize, int maxLevel, bool withDerivatives = true, BorderTypes pyrBorder = BorderTypes.Reflect101, BorderTypes derivBorder = BorderTypes.Constant, bool tryReuseInputImage = true) { if (img == null) throw new ArgumentNullException("img"); if (pyramid == null) throw new ArgumentNullException("pyramid"); img.ThrowIfDisposed(); pyramid.ThrowIfNotReady(); int result = NativeMethods.video_buildOpticalFlowPyramid1( img.CvPtr, pyramid.CvPtr, winSize, maxLevel, withDerivatives ? 1 : 0, (int)pyrBorder, (int)derivBorder, tryReuseInputImage ? 1 : 0); pyramid.Fix(); return result; }
/// <summary> /// extracts a single channel from src (coi is 0-based index) /// </summary> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="coi"></param> public static void ExtractChannel(InputArray src, OutputArray dst, int coi) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_extractChannel(src.CvPtr, dst.CvPtr, coi); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows /// </summary> /// <param name="src">The source 2D matrix</param> /// <param name="dst">The destination vector. /// Its size and type is defined by dim and dtype parameters</param> /// <param name="dim">The dimension index along which the matrix is reduced. /// 0 means that the matrix is reduced to a single row and 1 means that the matrix is reduced to a single column</param> /// <param name="rtype"></param> /// <param name="dtype">When it is negative, the destination vector will have /// the same type as the source matrix, otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())</param> public static void Reduce(InputArray src, OutputArray dst, ReduceDimension dim, ReduceTypes rtype, int dtype) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_reduce(src.CvPtr, dst.CvPtr, (int)dim, (int)rtype, dtype); dst.Fix(); GC.KeepAlive(src); }
/// <summary> /// naive nearest neighbor finder /// </summary> /// <param name="src1"></param> /// <param name="src2"></param> /// <param name="dist"></param> /// <param name="dtype"></param> /// <param name="nidx"></param> /// <param name="normType"></param> /// <param name="k"></param> /// <param name="mask"></param> /// <param name="update"></param> /// <param name="crosscheck"></param> public static void BatchDistance(InputArray src1, InputArray src2, OutputArray dist, int dtype, OutputArray nidx, NormTypes normType = NormTypes.L2, int k = 0, InputArray mask = null, int update = 0, bool crosscheck = false) { if (src1 == null) throw new ArgumentNullException("src1"); if (src2 == null) throw new ArgumentNullException("src2"); if (dist == null) throw new ArgumentNullException("dist"); if (nidx == null) throw new ArgumentNullException("nidx"); src1.ThrowIfDisposed(); src2.ThrowIfDisposed(); dist.ThrowIfNotReady(); nidx.ThrowIfNotReady(); NativeMethods.core_batchDistance(src1.CvPtr, src2.CvPtr, dist.CvPtr, dtype, nidx.CvPtr, (int)normType, k, ToPtr(mask), update, crosscheck ? 1 : 0); GC.KeepAlive(src1); GC.KeepAlive(src2); dist.Fix(); nidx.Fix(); }
/// <summary> /// Performs inverse 1D or 2D Discrete Cosine Transformation /// </summary> /// <param name="src">The source floating-point array</param> /// <param name="dst">The destination array; will have the same size and same type as src</param> /// <param name="flags">Transformation flags, a combination of DctFlag2 values</param> public static void Idct(InputArray src, OutputArray dst, DctFlags flags = DctFlags.None) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_idct(src.CvPtr, dst.CvPtr, (int)flags); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="mean"></param> /// <param name="eigenvectors"></param> /// <param name="result"></param> public static void PCABackProject(InputArray data, InputArray mean, InputArray eigenvectors, OutputArray result) { if (data == null) throw new ArgumentNullException("data"); if (mean == null) throw new ArgumentNullException("mean"); if (eigenvectors == null) throw new ArgumentNullException("eigenvectors"); if (result == null) throw new ArgumentNullException("result"); data.ThrowIfDisposed(); mean.ThrowIfDisposed(); eigenvectors.ThrowIfDisposed(); result.ThrowIfNotReady(); NativeMethods.core_PCABackProject(data.CvPtr, mean.CvPtr, eigenvectors.CvPtr, result.CvPtr); GC.KeepAlive(data); GC.KeepAlive(mean); GC.KeepAlive(eigenvectors); result.Fix(); }
/// <summary> /// computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma) /// </summary> /// <param name="src1"></param> /// <param name="alpha"></param> /// <param name="src2"></param> /// <param name="beta"></param> /// <param name="gamma"></param> /// <param name="dst"></param> /// <param name="dtype"></param> public static void AddWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype = -1) { if (src1 == null) throw new ArgumentNullException("src1"); if (src2 == null) throw new ArgumentNullException("src2"); if (dst == null) throw new ArgumentNullException("dst"); src1.ThrowIfDisposed(); src2.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_addWeighted(src1.CvPtr, alpha, src2.CvPtr, beta, gamma, dst.CvPtr, dtype); GC.KeepAlive(src1); GC.KeepAlive(src2); dst.Fix(); }
/// <summary> /// adds scaled array to another one (dst = alpha*src1 + src2) /// </summary> /// <param name="src1"></param> /// <param name="alpha"></param> /// <param name="src2"></param> /// <param name="dst"></param> public static void ScaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst) { if (src1 == null) throw new ArgumentNullException("src1"); if (src2 == null) throw new ArgumentNullException("src2"); if (dst == null) throw new ArgumentNullException("dst"); src1.ThrowIfDisposed(); src2.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_scaleAdd(src1.CvPtr, alpha, src2.CvPtr, dst.CvPtr); GC.KeepAlive(src1); GC.KeepAlive(src2); dst.Fix(); }
/// <summary> /// 2つの配列同士,あるいは配列とスカラの 要素毎の商を求めます. /// </summary> /// <param name="scale">スケールファクタ</param> /// <param name="src2">1番目の入力配列</param> /// <param name="dst">src2 と同じサイズ,同じ型である出力配列</param> /// <param name="dtype"></param> #else /// <summary> /// Performs per-element division of two arrays or a scalar by an array. /// </summary> /// <param name="scale">Scale factor</param> /// <param name="src2">The first source array</param> /// <param name="dst">The destination array; will have the same size and same type as src2</param> /// <param name="dtype"></param> #endif public static void Divide(double scale, InputArray src2, OutputArray dst, int dtype = -1) { if (src2 == null) throw new ArgumentNullException("src2"); if (dst == null) throw new ArgumentNullException("dst"); src2.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_divide(scale, src2.CvPtr, dst.CvPtr, dtype); GC.KeepAlive(src2); dst.Fix(); }
/// <summary> /// 2つの配列同士の,要素毎のスケーリングされた積を求めます. /// </summary> /// <param name="src1">1番目の入力配列</param> /// <param name="src2">src1 と同じサイズ,同じ型である2番目の入力配列</param> /// <param name="dst">src1 と同じサイズ,同じ型の出力配列</param> /// <param name="scale">オプションであるスケールファクタ. [既定値は1]</param> /// <param name="dtype"></param> #else /// <summary> /// Calculates the per-element scaled product of two arrays /// </summary> /// <param name="src1">The first source array</param> /// <param name="src2">The second source array of the same size and the same type as src1</param> /// <param name="dst">The destination array; will have the same size and the same type as src1</param> /// <param name="scale">The optional scale factor. [By default this is 1]</param> /// <param name="dtype"></param> #endif public static void Multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1) { if (src1 == null) throw new ArgumentNullException("src1"); if (src2 == null) throw new ArgumentNullException("src2"); if (dst == null) throw new ArgumentNullException("dst"); src1.ThrowIfDisposed(); src2.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_multiply(src1.CvPtr, src2.CvPtr, dst.CvPtr, scale, dtype); GC.KeepAlive(src1); GC.KeepAlive(src2); dst.Fix(); }
/// <summary> /// clusters the input data using k-Means algorithm /// </summary> /// <param name="data"></param> /// <param name="k"></param> /// <param name="bestLabels"></param> /// <param name="criteria"></param> /// <param name="attempts"></param> /// <param name="flags"></param> /// <param name="centers"></param> /// <returns></returns> public static double Kmeans(InputArray data, int k, InputOutputArray bestLabels, TermCriteria criteria, int attempts, KMeansFlags flags, OutputArray centers = null) { if (data == null) throw new ArgumentNullException("data"); if (bestLabels == null) throw new ArgumentNullException("bestLabels"); data.ThrowIfDisposed(); bestLabels.ThrowIfDisposed(); double ret = NativeMethods.core_kmeans(data.CvPtr, k, bestLabels.CvPtr, criteria, attempts, (int)flags, ToPtr(centers)); bestLabels.Fix(); if(centers != null) centers.Fix(); GC.KeepAlive(data); return ret; }
/// <summary> /// computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="flags"></param> /// <param name="conjB"></param> public static void MulSpectrums( InputArray a, InputArray b, OutputArray c, DftFlags flags, bool conjB = false) { if (a == null) throw new ArgumentNullException("a"); if (b == null) throw new ArgumentNullException("b"); if (c == null) throw new ArgumentNullException("c"); a.ThrowIfDisposed(); b.ThrowIfDisposed(); c.ThrowIfNotReady(); NativeMethods.core_mulSpectrums(a.CvPtr, b.CvPtr, c.CvPtr, (int)flags, conjB ? 1 : 0); GC.KeepAlive(a); GC.KeepAlive(b); c.Fix(); }
/// <summary> /// computes SVD of src /// </summary> /// <param name="src"></param> /// <param name="w"></param> /// <param name="u"></param> /// <param name="vt"></param> /// <param name="flags"></param> // ReSharper disable once InconsistentNaming public static void SVDecomp(InputArray src, OutputArray w, OutputArray u, OutputArray vt, SVD.Flags flags = SVD.Flags.None) { if (src == null) throw new ArgumentNullException("src"); if (w == null) throw new ArgumentNullException("w"); if (u == null) throw new ArgumentNullException("u"); if (vt == null) throw new ArgumentNullException("vt"); src.ThrowIfDisposed(); w.ThrowIfNotReady(); u.ThrowIfNotReady(); vt.ThrowIfNotReady(); NativeMethods.core_SVDecomp(src.CvPtr, w.CvPtr, u.CvPtr, vt.CvPtr, (int)flags); w.Fix(); u.Fix(); vt.Fix(); }
/// <summary> /// スケーリング後,絶対値を計算し,結果を結果を 8 ビットに変換します. /// </summary> /// <param name="src">入力配列</param> /// <param name="dst">出力配列</param> /// <param name="alpha">オプションのスケールファクタ. [既定値は1]</param> /// <param name="beta">スケーリングされた値に加えられるオプション値. [既定値は0]</param> #else /// <summary> /// Scales, computes absolute values and converts the result to 8-bit. /// </summary> /// <param name="src">The source array</param> /// <param name="dst">The destination array</param> /// <param name="alpha">The optional scale factor. [By default this is 1]</param> /// <param name="beta">The optional delta added to the scaled values. [By default this is 0]</param> #endif public static void ConvertScaleAbs(InputArray src, OutputArray dst, double alpha = 1, double beta = 0) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_convertScaleAbs(src.CvPtr, dst.CvPtr, alpha, beta); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Finds lines in the input image. /// This is the output of the default parameters of the algorithm on the above shown image. /// </summary> /// <param name="image">A grayscale (CV_8UC1) input image. </param> /// <param name="lines">A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. /// Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly oriented depending on the gradient.</param> /// <param name="width">Vector of widths of the regions, where the lines are found. E.g. Width of line.</param> /// <param name="prec">Vector of precisions with which the lines are found.</param> /// <param name="nfa">Vector containing number of false alarms in the line region, /// with precision of 10%. The bigger the value, logarithmically better the detection.</param> public virtual void Detect(InputArray image, OutputArray lines, OutputArray width = null, OutputArray prec = null, OutputArray nfa = null) { if (image == null) throw new ArgumentNullException(nameof(image)); if (lines == null) throw new ArgumentNullException(nameof(lines)); image.ThrowIfDisposed(); lines.ThrowIfNotReady(); width?.ThrowIfNotReady(); prec?.ThrowIfNotReady(); nfa?.ThrowIfNotReady(); NativeMethods.imgproc_LineSegmentDetector_detect_OutputArray(ptr, image.CvPtr, lines.CvPtr, Cv2.ToPtr(width), Cv2.ToPtr(prec), Cv2.ToPtr(nfa)); GC.KeepAlive(image); lines.Fix(); width?.Fix(); prec?.Fix(); nfa?.Fix(); }
/// <summary> /// transforms array of numbers using a lookup table: dst(i)=lut(src(i)) /// </summary> /// <param name="src">Source array of 8-bit elements</param> /// <param name="lut">Look-up table of 256 elements. /// In the case of multi-channel source array, the table should either have /// a single channel (in this case the same table is used for all channels) /// or the same number of channels as in the source array</param> /// <param name="dst">Destination array; /// will have the same size and the same number of channels as src, /// and the same depth as lut</param> /// <param name="interpolation"></param> public static void LUT(InputArray src, InputArray lut, OutputArray dst, int interpolation = 0) { if (src == null) throw new ArgumentNullException("src"); if (lut == null) throw new ArgumentNullException("lut"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); lut.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_LUT(src.CvPtr, lut.CvPtr, dst.CvPtr); GC.KeepAlive(src); GC.KeepAlive(lut); dst.Fix(); }
/// <summary> /// returns the list of locations of non-zero pixels /// </summary> /// <param name="src"></param> /// <param name="idx"></param> public static void FindNonZero(InputArray src, OutputArray idx) { if (src == null) throw new ArgumentNullException("src"); if (idx == null) throw new ArgumentNullException("idx"); src.ThrowIfDisposed(); idx.ThrowIfNotReady(); NativeMethods.core_findNonZero(src.CvPtr, idx.CvPtr); GC.KeepAlive(src); idx.Fix(); }
/// <summary> /// computes mean value and standard deviation of all or selected array elements /// </summary> /// <param name="src">The source array; it should have 1 to 4 channels /// (so that the results can be stored in Scalar's)</param> /// <param name="mean">The output parameter: computed mean value</param> /// <param name="stddev">The output parameter: computed standard deviation</param> /// <param name="mask">The optional operation mask</param> public static void MeanStdDev( InputArray src, OutputArray mean, OutputArray stddev, InputArray mask = null) { if (src == null) throw new ArgumentNullException("src"); if (mean == null) throw new ArgumentNullException("mean"); if (stddev == null) throw new ArgumentNullException("stddev"); src.ThrowIfDisposed(); mean.ThrowIfNotReady(); stddev.ThrowIfNotReady(); NativeMethods.core_meanStdDev_OutputArray(src.CvPtr, mean.CvPtr, stddev.CvPtr, ToPtr(mask)); mean.Fix(); stddev.Fix(); GC.KeepAlive(src); GC.KeepAlive(mask); }
/// <summary> /// performs back substitution for the previously computed SVD /// </summary> /// <param name="w"></param> /// <param name="u"></param> /// <param name="vt"></param> /// <param name="rhs"></param> /// <param name="dst"></param> // ReSharper disable once InconsistentNaming public static void SVBackSubst(InputArray w, InputArray u, InputArray vt, InputArray rhs, OutputArray dst) { if (w == null) throw new ArgumentNullException("w"); if (u == null) throw new ArgumentNullException("u"); if (vt == null) throw new ArgumentNullException("vt"); if (rhs == null) throw new ArgumentNullException("rhs"); if (dst == null) throw new ArgumentNullException("dst"); w.ThrowIfDisposed(); u.ThrowIfDisposed(); vt.ThrowIfDisposed(); rhs.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_SVBackSubst(w.CvPtr, u.CvPtr, vt.CvPtr, rhs.CvPtr, dst.CvPtr); dst.Fix(); }
/// <summary> /// 2つの配列同士,あるいは配列とスカラの 要素毎の差を求めます. /// </summary> /// <param name="src1">1番目の入力配列</param> /// <param name="src2">src1 と同じサイズ,同じ型である2番目の入力配列</param> /// <param name="dst">src1 と同じサイズ,同じ型の出力配列.</param> /// <param name="mask">オプション.8ビット,シングルチャンネル配列の処理マスク.出力配列内の変更される要素を表します. [既定値はnull]</param> /// <param name="dtype"></param> #else /// <summary> /// Calculates per-element difference between two arrays or array and a scalar /// </summary> /// <param name="src1">The first source array</param> /// <param name="src2">The second source array. It must have the same size and same type as src1</param> /// <param name="dst">The destination array; it will have the same size and same type as src1</param> /// <param name="mask">The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed. [By default this is null]</param> /// <param name="dtype"></param> #endif public static void Subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = null, int dtype = -1) { if (src1 == null) throw new ArgumentNullException("src1"); if (src2 == null) throw new ArgumentNullException("src2"); if (dst == null) throw new ArgumentNullException("dst"); src1.ThrowIfDisposed(); src2.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.core_subtract(src1.CvPtr, src2.CvPtr, dst.CvPtr, ToPtr(mask), dtype); GC.KeepAlive(src1); GC.KeepAlive(src2); dst.Fix(); }