예제 #1
0
        /// <summary>
        /// converts matrix type, ex from float to uchar depending on type
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="dtype"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public void EnqueueConvert(GpuMat src, GpuMat dst, int dtype, double a = 1, double b = 0)
        {
            ThrowIfDisposed();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_Stream_enqueueConvert(ptr, src.CvPtr, dst.CvPtr, dtype, a, b);
        }
예제 #2
0
        /// <summary>
        /// Copy asynchronously
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        public void EnqueueCopy(GpuMat src, GpuMat dst)
        {
            ThrowIfDisposed();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_Stream_enqueueCopy(ptr, src.CvPtr, dst.CvPtr);
        }
예제 #3
0
        /// <summary>
        /// Uploads asynchronously.
        /// Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        public void EnqueueUpload(Mat src, GpuMat dst)
        {
            ThrowIfDisposed();
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_Stream_enqueueUpload_Mat(ptr, src.CvPtr, dst.CvPtr);
        }
예제 #4
0
        /// <summary>
        /// Applies the Laplacian operator to an image.
        /// </summary>
        /// <param name="src">Source image. CV_8UC1 and CV_8UC4 source types are supported.</param>
        /// <param name="dst">Destination image. The size and number of channels is the same as src.</param>
        /// <param name="ddepth">Desired depth of the destination image. It supports only the same depth as the source image depth.</param>
        /// <param name="ksize">Aperture size used to compute the second-derivative filters.
        /// It must be positive and odd. Only ksize = 1 and ksize = 3 are supported.</param>
        /// <param name="scale">Optional scale factor for the computed Laplacian values.</param>
        /// <param name="borderType">Pixel extrapolation method.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void Laplacian(
            GpuMat src, GpuMat dst, int ddepth, int ksize = 1, double scale = 1,
            BorderType borderType = BorderType.Default, Stream stream       = null)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_Laplacian(
                src.CvPtr, dst.CvPtr, ddepth, ksize, scale, (int)borderType, Cv2.ToPtr(stream));
        }
예제 #5
0
        /// <summary>
        /// Applies the generalized Sobel operator to an image.
        /// </summary>
        /// <param name="src">Source image.
        /// CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_16SC3, CV_32SC1, CV_32FC1 source types are supported.</param>
        /// <param name="dst">Destination image with the same size and number of channels as source image.</param>
        /// <param name="ddepth">Destination image depth. CV_8U, CV_16S, CV_32S, and CV_32F are supported.</param>
        /// <param name="dx">Derivative order in respect of x.</param>
        /// <param name="dy">Derivative order in respect of y.</param>
        /// <param name="ksize">Size of the extended Sobel kernel. Possible values are 1, 3, 5 or 7.</param>
        /// <param name="scale">Optional scale factor for the computed derivative values. By default, no scaling is applied.</param>
        /// <param name="rowBorderType">Pixel extrapolation method in the vertical direction.</param>
        /// <param name="columnBorderType">Pixel extrapolation method in the horizontal direction.</param>
        public static void Sobel(GpuMat src, GpuMat dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1,
                                 BorderType rowBorderType = BorderType.Default, BorderType columnBorderType      = BorderType.Auto)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_Sobel1(
                src.CvPtr, dst.CvPtr, ddepth, dx, dy, ksize, scale,
                (int)rowBorderType, (int)columnBorderType);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="ksize"></param>
        /// <param name="sigma1"></param>
        /// <param name="sigma2"></param>
        /// <param name="rowBorderType"></param>
        /// <param name="columnBorderType"></param>
        public static void GaussianBlur(
            GpuMat src, GpuMat dst, Size ksize, double sigma1, double sigma2 = 0,
            BorderType rowBorderType = BorderType.Default, BorderType columnBorderType = BorderType.Auto)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            NativeMethods.gpu_GaussianBlur1(
                src.CvPtr, dst.CvPtr, ksize, sigma1, sigma2,
                (int)rowBorderType, (int)columnBorderType);
        }
예제 #7
0
        /// <summary>
        /// Smooths the image using the normalized box filter.
        /// </summary>
        /// <param name="src">Input image. CV_8UC1 and CV_8UC4 source types are supported.</param>
        /// <param name="dst">Output image type. The size and type is the same as src.</param>
        /// <param name="ddepth">Output image depth. If -1, the output image has the same depth as the input one.
        /// The only values allowed here are CV_8U and -1.</param>
        /// <param name="ksize">Kernel size.</param>
        /// <param name="anchor">Anchor point. The default value Point(-1, -1) means that
        /// the anchor is at the kernel center.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void BoxFilter(
            GpuMat src, GpuMat dst, int ddepth, Size ksize, Point?anchor,
            Stream stream = null)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));

            NativeMethods.gpu_boxFilter(src.CvPtr, dst.CvPtr, ddepth, ksize, anchor0, Cv2.ToPtr(stream));
        }
예제 #8
0
        /// <summary>
        /// Applies a separable 2D linear filter to an image.
        /// </summary>
        /// <param name="src">Source image.
        /// CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 source types are supported.</param>
        /// <param name="dst">Destination image with the same size and number of channels as src.</param>
        /// <param name="ddepth">Destination image depth. CV_8U, CV_16S, CV_32S, and CV_32F are supported.</param>
        /// <param name="kernelX">Horizontal filter coefficients.</param>
        /// <param name="kernelY">Vertical filter coefficients.</param>
        /// <param name="buf"></param>
        /// <param name="anchor">Anchor position within the kernel.
        /// The default value (-1, 1) means that the anchor is at the kernel center.</param>
        /// <param name="rowBorderType">Pixel extrapolation method in the vertical direction.</param>
        /// <param name="columnBorderType">Pixel extrapolation method in the horizontal direction.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void SepFilter2D(
            GpuMat src, GpuMat dst, int ddepth, Mat kernelX, Mat kernelY, GpuMat buf,
            Point?anchor = null, BorderType rowBorderType = BorderType.Default,
            BorderType columnBorderType = BorderType.Auto, Stream stream = null)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (kernelX == null)
            {
                throw new ArgumentNullException(nameof(kernelX));
            }
            if (kernelY == null)
            {
                throw new ArgumentNullException(nameof(kernelY));
            }
            if (buf == null)
            {
                throw new ArgumentNullException(nameof(buf));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            kernelX.ThrowIfDisposed();
            kernelY.ThrowIfDisposed();
            buf.ThrowIfDisposed();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));

            NativeMethods.gpu_sepFilter2D2(
                src.CvPtr, dst.CvPtr, ddepth, kernelX.CvPtr, kernelY.CvPtr, buf.CvPtr,
                anchor0, (int)rowBorderType, (int)columnBorderType, Cv2.ToPtr(stream));
        }
예제 #9
0
 /// <summary>
 /// Computes a proximity map for a raster template and an image where the template is searched for.
 /// </summary>
 /// <param name="image">Source image. CV_32F and CV_8U depth images (1..4 channels) are supported for now.</param>
 /// <param name="templ">Template image with the size and type the same as image.</param>
 /// <param name="result">Map containing comparison results (CV_32FC1). If image is W x H and templ is w x h, then result must be W-w+1 x H-h+1.</param>
 /// <param name="method">Specifies the way to compare the template with the image.</param>
 /// <param name="stream">Stream for the asynchronous version.</param>
 public static void MatchTemplate(
     GpuMat image, GpuMat templ, GpuMat result, MatchTemplateMethod method,
     Stream stream = null)
 {
     ThrowIfGpuNotAvailable();
     if (image == null)
     {
         throw new ArgumentNullException(nameof(image));
     }
     if (templ == null)
     {
         throw new ArgumentNullException(nameof(templ));
     }
     if (result == null)
     {
         throw new ArgumentNullException(nameof(result));
     }
     image.ThrowIfDisposed();
     templ.ThrowIfDisposed();
     result.ThrowIfDisposed();
     NativeMethods.gpu_matchTemplate1(
         image.CvPtr, templ.CvPtr, result.CvPtr, (int)method, Cv2.ToPtr(stream));
 }
예제 #10
0
 /// <summary>
 /// Finds global minimum and maximum array elements and returns their values with locations
 /// </summary>
 /// <param name="src">Single-channel source image.</param>
 /// <param name="minVal">Pointer to the returned minimum value.</param>
 /// <param name="maxVal">Pointer to the returned maximum value.</param>
 /// <param name="minLoc">Pointer to the returned minimum location.</param>
 /// <param name="maxLoc">Pointer to the returned maximum location.</param>
 /// <param name="mask">Optional mask to select a sub-matrix.</param>
 /// <param name="valbuf">Optional values buffer to avoid extra memory allocations.
 /// It is resized automatically.</param>
 /// <param name="locbuf">Optional locations buffer to avoid extra memory allocations.
 /// It is resized automatically.</param>
 public static void MinMaxLoc(
     GpuMat src, out double minVal, out double maxVal, out Point minLoc, out Point maxLoc,
     GpuMat mask, GpuMat valbuf, GpuMat locbuf)
 {
     ThrowIfGpuNotAvailable();
     if (src == null)
     {
         throw new ArgumentNullException(nameof(src));
     }
     if (valbuf == null)
     {
         throw new ArgumentNullException(nameof(valbuf));
     }
     if (locbuf == null)
     {
         throw new ArgumentNullException(nameof(locbuf));
     }
     src.ThrowIfDisposed();
     valbuf.ThrowIfDisposed();
     locbuf.ThrowIfDisposed();
     NativeMethods.gpu_minMaxLoc2(
         src.CvPtr, out minVal, out maxVal, out minLoc, out maxLoc, Cv2.ToPtr(mask),
         valbuf.CvPtr, locbuf.CvPtr);
 }
예제 #11
0
        /// <summary>
        /// Applies an advanced morphological operation to an image.
        /// </summary>
        /// <param name="src">Source image. CV_8UC1 and CV_8UC4 source types are supported.</param>
        /// <param name="dst">Destination image with the same size and type as src.</param>
        /// <param name="op">Type of morphological operation</param>
        /// <param name="kernel">Structuring element.</param>
        /// <param name="buf1"></param>
        /// <param name="buf2"></param>
        /// <param name="anchor">Position of an anchor within the element.
        /// The default value Point(-1, -1) means that the anchor is at the element center.</param>
        /// <param name="iterations">Number of times erosion and dilation to be applied.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void MorphologyEx(
            GpuMat src, GpuMat dst, MorphologyOperation op, Mat kernel, GpuMat buf1, GpuMat buf2,
            Point?anchor = null, int iterations = 1, Stream stream = null)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }
            if (buf1 == null)
            {
                throw new ArgumentNullException(nameof(buf1));
            }
            if (buf2 == null)
            {
                throw new ArgumentNullException(nameof(buf2));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            kernel.ThrowIfDisposed();
            buf1.ThrowIfDisposed();
            buf2.ThrowIfDisposed();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));

            NativeMethods.gpu_morphologyEx2(src.CvPtr, dst.CvPtr, (int)op, kernel.CvPtr,
                                            buf1.CvPtr, buf2.CvPtr, anchor0, iterations, Cv2.ToPtr(stream));
        }
예제 #12
0
        /// <summary>
        /// Dilates an image by using a specific structuring element.
        /// </summary>
        /// <param name="src">Source image. Only CV_8UC1 and CV_8UC4 types are supported.</param>
        /// <param name="dst">Destination image with the same size and type as src.</param>
        /// <param name="kernel">Structuring element used for erosion. If kernel=Mat(),
        /// a 3x3 rectangular structuring element is used.</param>
        /// <param name="anchor">Position of an anchor within the element.
        /// The default value (-1, -1) means that the anchor is at the element center.</param>
        /// <param name="iterations">Number of times erosion to be applied.</param>
        public static void Dilate(
            GpuMat src, GpuMat dst, Mat kernel, Point?anchor = null, int iterations = 1)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            kernel.ThrowIfDisposed();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));

            NativeMethods.gpu_dilate1(src.CvPtr, dst.CvPtr, kernel.CvPtr, anchor0, iterations);
        }
예제 #13
0
        /// <summary>
        /// Applies an advanced morphological operation to an image.
        /// </summary>
        /// <param name="src">Source image. CV_8UC1 and CV_8UC4 source types are supported.</param>
        /// <param name="dst">Destination image with the same size and type as src.</param>
        /// <param name="op">Type of morphological operation</param>
        /// <param name="kernel">Structuring element.</param>
        /// <param name="anchor">Position of an anchor within the element.
        /// The default value Point(-1, -1) means that the anchor is at the element center.</param>
        /// <param name="iterations">Number of times erosion and dilation to be applied.</param>
        public static void MorphologyEx(
            GpuMat src, GpuMat dst, MorphologyOperation op, Mat kernel, Point?anchor = null, int iterations = 1)
        {
            ThrowIfGpuNotAvailable();
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }
            if (kernel == null)
            {
                throw new ArgumentNullException("kernel");
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            kernel.ThrowIfDisposed();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));

            NativeMethods.gpu_morphologyEx1(src.CvPtr, dst.CvPtr, (int)op, kernel.CvPtr, anchor0, iterations);
        }