コード例 #1
0
        /// <summary>
        /// Decodes QR code in image once it's found by the detect() method.
        /// Returns UTF8-encoded output string or empty string if the code cannot be decoded.
        /// </summary>
        /// <param name="img">grayscale or color (BGR) image containing QR code.</param>
        /// <param name="points">Quadrangle vertices found by detect() method (or some other algorithm).</param>
        /// <param name="straightQrCode">The optional output image containing rectified and binarized QR code</param>
        /// <returns></returns>
        public string Decode(InputArray img, IEnumerable <Point2f> points, OutputArray?straightQrCode = null)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }
            img.ThrowIfDisposed();
            straightQrCode?.ThrowIfNotReady();

            using var pointsVec    = new VectorOfPoint2f(points);
            using var resultString = new StdString();
            NativeMethods.HandleException(
                NativeMethods.objdetect_QRCodeDetector_decode(
                    ptr, img.CvPtr, pointsVec.CvPtr, Cv2.ToPtr(straightQrCode), resultString.CvPtr));

            GC.KeepAlive(img);
            GC.KeepAlive(points);
            GC.KeepAlive(straightQrCode);
            GC.KeepAlive(this);

            return(resultString.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Both detects and decodes QR code
        /// </summary>
        /// <param name="img">grayscale or color (BGR) image containing QR code.</param>
        /// <param name="points">opiotnal output array of vertices of the found QR code quadrangle. Will be empty if not found.</param>
        /// <param name="straightQrcode">The optional output image containing rectified and binarized QR code</param>
        /// <returns></returns>
        public string DetectAndDecode(InputArray img, out Point2f[] points, OutputArray straightQrcode = null)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            img.ThrowIfDisposed();
            straightQrcode?.ThrowIfNotReady();

            string result;

            using (var pointsVec = new VectorOfPoint2f())
                using (var resultString = new StdString())
                {
                    NativeMethods.objdetect_QRCodeDetector_detectAndDecode(
                        ptr, img.CvPtr, pointsVec.CvPtr, Cv2.ToPtr(straightQrcode), resultString.CvPtr);
                    points = pointsVec.ToArray();
                    result = resultString.ToString();
                }

            GC.KeepAlive(img);
            GC.KeepAlive(straightQrcode);
            GC.KeepAlive(this);

            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Reads the node element as String
 /// </summary>
 /// <param name="defaultValue"></param>
 /// <returns></returns>
 public string ReadString(string?defaultValue = null)
 {
     using var value = new StdString();
     NativeMethods.HandleException(
         NativeMethods.core_FileNode_read_String(ptr, value.CvPtr, defaultValue));
     GC.KeepAlive(this);
     return(value.ToString());
 }
コード例 #4
0
ファイル: Feature2D.cs プロジェクト: zhaohh1985/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string GetDefaultName()
        {
            ThrowIfDisposed();

            using var returnValue = new StdString();
            NativeMethods.HandleException(
                NativeMethods.features2d_Feature2D_getDefaultName(ptr, returnValue.CvPtr));
            GC.KeepAlive(this);
            return(returnValue.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Returns used backend API name.
        /// Note that stream should be opened.
        /// </summary>
        /// <returns></returns>
        public string GetBackendName()
        {
            ThrowIfDisposed();

            using var returnString = new StdString();
            NativeMethods.HandleException(
                NativeMethods.videoio_VideoWriter_getBackendName(ptr, returnString.CvPtr));

            GC.KeepAlive(this);
            return(returnString.ToString());
        }
コード例 #6
0
        /// <summary>
        /// Returns the node content as text string
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            ThrowIfDisposed();

            using var buf = new StdString();
            NativeMethods.HandleException(
                NativeMethods.core_FileNode_toString(ptr, buf.CvPtr));

            GC.KeepAlive(this);
            return(buf.ToString());
        }
コード例 #7
0
ファイル: FileStorage.cs プロジェクト: zhaohh1985/opencvsharp
        /// <summary>
        /// Returns the normalized object name for the specified file name
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetDefaultObjectName(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            using var buf = new StdString();
            NativeMethods.HandleException(
                NativeMethods.core_FileStorage_getDefaultObjectName(fileName, buf.CvPtr));
            return(buf.ToString());
        }
コード例 #8
0
ファイル: Algorithm.cs プロジェクト: zhoufan1987/opencvsharp
        /// <summary>
        /// Returns the algorithm string identifier.
        /// This string is used as top level xml/yml node tag when the object
        /// is saved to a file or string.
        /// </summary>
        /// <returns></returns>
        public virtual string GetDefaultName()
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            using var buf = new StdString();
            NativeMethods.HandleException(
                NativeMethods.core_Algorithm_getDefaultName(ptr, buf.CvPtr));
            GC.KeepAlive(this);
            return(buf.ToString());
        }
コード例 #9
0
ファイル: FileStorage.cs プロジェクト: zhaohh1985/opencvsharp
        /// <summary>
        /// Closes the file, releases all the memory buffers and returns the text string
        /// </summary>
        /// <returns></returns>
        public string ReleaseAndGetString()
        {
            ThrowIfDisposed();

            try
            {
                using var stdString = new StdString();
                NativeMethods.HandleException(
                    NativeMethods.core_FileStorage_releaseAndGetString(ptr, stdString.CvPtr));
                return(stdString.ToString());
            }
            finally
            {
                Dispose();
            }
        }