Example #1
0
        /// <summary>
        /// Downloads results from cuda::CornersDetector::detect to host memory.
        /// </summary>
        /// <param name="d_corners">Result of cuda::CornersDetector::detect .</param>
        /// <param name="c_corners">Output host array.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public virtual void downloadResults(InputArray d_corners, out Point2f[] c_corners, Stream stream = null)
        {
            if (d_corners == null)
            {
                throw new ArgumentNullException(nameof(d_corners));
            }
            d_corners.ThrowIfDisposed();

            using (var vec = new VectorOfVec2f()) {
                NativeMethods.cuda_imgproc_CornersDetector_downloadResults(ptr, d_corners.CvPtr, vec.CvPtr
                                                                           , stream?.CvPtr ?? Stream.Null.CvPtr);
                c_corners = vec.ToArray <Point2f>();
            }

            GC.KeepAlive(this);
            GC.KeepAlive(d_corners);
            GC.KeepAlive(c_corners);
        }
        /// <summary>
        /// Downloads results from cuda::HoughLinesDetector::detect to host memory.
        /// </summary>
        /// <param name="d_lines">Result of cuda::HoughLinesDetector::detect .</param>
        /// <param name="h_lines">Output host array.</param>
        /// <param name="h_votes">Optional output array for line's votes.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public virtual void downloadResults(InputArray d_lines, out LineSegmentPolar[] h_lines, OutputArray h_votes = null, Stream stream = null)
        {
            if (d_lines == null)
            {
                throw new ArgumentNullException(nameof(d_lines));
            }
            d_lines.ThrowIfDisposed();

            using (var vec = new VectorOfVec2f()) {
                NativeMethods.cuda_imgproc_HoughLinesDetector_downloadResults(ptr, d_lines.CvPtr, vec.CvPtr
                                                                              , h_votes?.CvPtr ?? IntPtr.Zero, stream?.CvPtr ?? Stream.Null.CvPtr);
                h_lines = vec.ToArray <LineSegmentPolar>();
            }

            GC.KeepAlive(this);
            GC.KeepAlive(d_lines);
            GC.KeepAlive(h_lines);
            GC.KeepAlive(h_votes);
            h_votes?.Fix();
        }
        /// <summary>
        /// 標準ハフ変換を用いて,2値画像から直線を検出します.
        /// </summary>
        /// <param name="image">8ビット,シングルチャンネルの2値入力画像.この画像は関数により書き換えられる可能性があります</param>
        /// <param name="rho">ピクセル単位で表される投票空間の距離分解能</param>
        /// <param name="theta">ラジアン単位で表される投票空間の角度分解能</param>
        /// <param name="threshold">投票の閾値パラメータ.十分な票( &gt; threshold )を得た直線のみが出力されます</param>
        /// <param name="srn">マルチスケールハフ変換において,距離分解能 rho  の除数となる値.[既定値は0]</param>
        /// <param name="stn">マルチスケールハフ変換において,角度分解能 theta  の除数となる値. [既定値は0]</param>
        /// <returns>検出された直線.各直線は,2要素のベクトル (rho, theta) で表現されます.
        /// rho は原点(画像の左上コーナー)からの距離, theta はラジアン単位で表される直線の回転角度です</returns>
#else
        /// <summary>
        /// Finds lines in a binary image using standard Hough transform.
        /// </summary>
        /// <param name="image">The 8-bit, single-channel, binary source image. The image may be modified by the function</param>
        /// <param name="rho">Distance resolution of the accumulator in pixels</param>
        /// <param name="theta">Angle resolution of the accumulator in radians</param>
        /// <param name="threshold">The accumulator threshold parameter. Only those lines are returned that get enough votes ( &gt; threshold )</param>
        /// <param name="srn">For the multi-scale Hough transform it is the divisor for the distance resolution rho. [By default this is 0]</param>
        /// <param name="stn">For the multi-scale Hough transform it is the divisor for the distance resolution theta. [By default this is 0]</param>
        /// <returns>The output vector of lines. Each line is represented by a two-element vector (rho, theta) . 
        /// rho is the distance from the coordinate origin (0,0) (top-left corner of the image) and theta is the line rotation angle in radians</returns>
#endif
        public static CvLineSegmentPolar[] HoughLines(InputArray image, double rho, double theta, int threshold, 
            double srn = 0, double stn = 0)
        {
            if (image == null)
                throw new ArgumentNullException("image");

            using (var vec = new VectorOfVec2f())
            {
                NativeMethods.imgproc_HoughLines(image.CvPtr, vec.CvPtr, rho, theta, threshold, srn, stn);
                return vec.ToArray<CvLineSegmentPolar>();
            }
        }