コード例 #1
0
 /// <summary>
 /// Return the class (model) names that were passed in constructor or method load or extracted from models filenames in those methods.
 /// </summary>
 /// <returns></returns>
 public string[] GetClassNames()
 {
     using (var outVec = new VectorOfString())
     {
         NativeMethods.objdetect_LatentSvmDetector_getClassNames(ptr, outVec.CvPtr);
         return(outVec.ToArray());
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates a tailored language model transitions table from a given list of words (lexicon)
        /// </summary>
        /// <param name="vocabulary">The language vocabulary (chars when ASCII English text)</param>
        /// <param name="lexicon">The list of words that are expected to be found in a particular image</param>
        /// <returns>Table with transition probabilities between character pairs</returns>
        public static Mat CreateOCRHMMTransitionsTable(string vocabulary, IList <string> lexicon)
        {
            Mat result = new Mat();

            using (var transition_t = new OutputArray(result))
                using (var vecLex = new VectorOfString(lexicon))
                {
                    NativeMethods.text_createOCRHMMTransitionsTable(vocabulary, vecLex.CvPtr, transition_t.CvPtr);
                }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Recognize text using Beam Search
        /// Optionally provides also the Rects for individual text elements found (e.g. words), and the list of those text elements with their confidence values.
        /// </summary>
        /// <param name="image">Input image CV_8UC1 with a single text line (or word)</param>
        /// <param name="mask">Text mask CV_8UC1 image</param>
        /// <param name="rects">Method will output a list of Rects for the individual text elements found (e.g. words)</param>
        /// <param name="texts">Method will output a list of text strings for the recognition of individual text elements found (e.g. words)</param>
        /// <param name="confidences">Method will output a list of confidence values for the recognition of individual text elements found (e.g. words)</param>
        /// <param name="component_level"></param>
        /// <returns></returns>
        public override string Run(Mat image, Mat mask, out Rect[] rects, out string[] texts, out float[] confidences, CvText.OCRLevel component_level)
        {
            using (VectorOfRect vecRects = new VectorOfRect())
                using (VectorOfString vecTexts = new VectorOfString())
                    using (VectorOfFloat vecConfidences = new VectorOfFloat())
                    {
                        NativeMethods.text_OCRBeamSearchDecoder_run2(ptr, image.CvPtr, mask.CvPtr, vecRects.CvPtr, vecTexts.CvPtr, vecConfidences.CvPtr, (int)component_level);

                        rects       = vecRects.ToArray();
                        texts       = vecTexts.ToArray();
                        confidences = vecConfidences.ToArray();
                    }

            return(texts.Length > 0 ? texts[0] : String.Empty);
        }
コード例 #4
0
ファイル: QRCodeDetector.cs プロジェクト: yuxkang/opencvsharp
        /// <summary>
        /// Decodes QR codes 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="decodedInfo">UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded. </param>
        /// <param name="straightQrCode">The optional output image containing rectified and binarized QR code</param>
        /// <param name="isOutputStraightQrCode"><see langword="true"/> to output <paramref name="straightQrCode"/></param>
        /// <returns></returns>
        protected bool DecodeMulti(InputArray img, IEnumerable <Point2f> points, out string?[] decodedInfo, out Mat[] straightQrCode, bool isOutputStraightQrCode)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            img.ThrowIfDisposed();

            using var decodedInfoVec = new VectorOfString();
            using var pointsVec      = new VectorOfPoint2f(points);

            int ret;

            if (isOutputStraightQrCode)
            {
                NativeMethods.HandleException(
                    NativeMethods.objdetect_QRCodeDetector_decodeMulti(
                        ptr, img.CvPtr, pointsVec.CvPtr, decodedInfoVec.CvPtr, out var straightQrCodePtr, out ret));

                using var straightQrCodeVec = new VectorOfMat(straightQrCodePtr);
                straightQrCode = straightQrCodeVec.ToArray();
            }
            else
            {
                NativeMethods.HandleException(
                    NativeMethods.objdetect_QRCodeDetector_decodeMulti_NoStraightQrCode(
                        ptr, img.CvPtr, pointsVec.CvPtr, decodedInfoVec.CvPtr, out ret));
                straightQrCode = Array.Empty <Mat>();
            }

            // decode utf-8 bytes.
            decodedInfo = decodedInfoVec.ToArray();

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

            return(ret != 0);
        }
コード例 #5
0
        /// <summary>
        /// Both detects and decodes QR code.
        /// To simplify the usage, there is a only API: detectAndDecode
        /// </summary>
        /// <param name="inputImage">supports grayscale or color(BGR) image.</param>
        /// <param name="bbox">optional output array of vertices of the found QR code quadrangle.Will be empty if not found.</param>
        /// <param name="results">list of decoded string.</param>
        public void DetectAndDecode(InputArray inputImage, out Mat[] bbox, out string[] results)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }
            inputImage.ThrowIfDisposed();

            using var bboxVec = new VectorOfMat();
            using var texts   = new VectorOfString();
            NativeMethods.HandleException(
                NativeMethods.wechat_qrcode_WeChatQRCode_detectAndDecode(
                    ptr, inputImage.CvPtr, bboxVec.CvPtr, texts.CvPtr));

            bbox    = bboxVec.ToArray();
            results = texts.ToArray();
            GC.KeepAlive(this);
            GC.KeepAlive(inputImage);
        }