Exemplo n.º 1
0
        /// <summary>
        /// Recognize text using the tesseract-ocr API.
        /// Takes image on input and returns recognized text in the output_text parameter.
        /// 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 or CV_8UC3</param>
        /// <param name="outputText">Output text of the tesseract-ocr.</param>
        /// <param name="componentRects">If provided the method will output a list of Rects for the individual
        /// text elements found(e.g.words or text lines).</param>
        /// <param name="componentTexts">If provided the method will output a list of text strings for the
        /// recognition of individual text elements found(e.g.words or text lines).</param>
        /// <param name="componentConfidences">If provided the method will output a list of confidence values
        /// for the recognition of individual text elements found(e.g.words or text lines).</param>
        /// <param name="componentLevel">OCR_LEVEL_WORD (by default), or OCR_LEVEL_TEXT_LINE.</param>
        public override void Run(
            Mat image,
            out string outputText,
            out Rect[] componentRects,
            out string?[] componentTexts,
            out float[] componentConfidences,
            ComponentLevels componentLevel = ComponentLevels.Word)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            image.ThrowIfDisposed();

            using var outputTextString           = new StdString();
            using var componentRectsVector       = new VectorOfRect();
            using var componentTextsVector       = new VectorOfString();
            using var componentConfidencesVector = new VectorOfFloat();
            NativeMethods.HandleException(
                NativeMethods.text_OCRTesseract_run1(
                    ptr,
                    image.CvPtr,
                    outputTextString.CvPtr,
                    componentRectsVector.CvPtr,
                    componentTextsVector.CvPtr,
                    componentConfidencesVector.CvPtr,
                    (int)componentLevel));
            outputText           = outputTextString.ToString();
            componentRects       = componentRectsVector.ToArray();
            componentTexts       = componentTextsVector.ToArray();
            componentConfidences = componentConfidencesVector.ToArray();

            GC.KeepAlive(this);
            GC.KeepAlive(image);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public string[] GetParams()
 {
     using (var namesVec = new VectorOfString())
     {
         NativeMethods.core_AlgorithmInfo_getParams(ptr, namesVec.CvPtr);
         return namesVec.ToArray();
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string?[] GetLayerNames()
 {
     using var namesVec = new VectorOfString();
     NativeMethods.HandleException(
         NativeMethods.dnn_Net_getLayerNames(ptr, namesVec.CvPtr));
     GC.KeepAlive(this);
     return(namesVec.ToArray());
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string[] GetLayerNames()
 {
     using (var namesVec = new VectorOfString())
     {
         NativeMethods.dnn_Net_getLayerNames(ptr, namesVec.CvPtr);
         GC.KeepAlive(this);
         return(namesVec.ToArray());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns names of layers with unconnected outputs.
        /// </summary>
        /// <returns></returns>
        public string?[] GetUnconnectedOutLayersNames()
        {
            ThrowIfDisposed();

            using var resultVec = new VectorOfString();
            NativeMethods.HandleException(
                NativeMethods.dnn_Net_getUnconnectedOutLayersNames(ptr, resultVec.CvPtr));
            GC.KeepAlive(this);
            return(resultVec.ToArray());
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 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);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Returns names of layers with unconnected outputs.
        /// </summary>
        /// <returns></returns>
        public string[] GetUnconnectedOutLayersNames()
        {
            ThrowIfDisposed();

            try
            {
                using (var resultVec = new VectorOfString())
                {
                    NativeMethods.dnn_Net_getUnconnectedOutLayersNames(ptr, resultVec.CvPtr);
                    return(resultVec.ToArray());
                }
            }
            finally
            {
                GC.KeepAlive(this);
            }
        }
Exemplo n.º 8
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();
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Returns the list of registered algorithms
 /// </summary>
 /// <returns>The output array of algorithm names.</returns>
 public static string[] GetList()
 {
     using (var vec = new VectorOfString())
     {
         NativeMethods.core_Algorithm_getList(vec.CvPtr);
         return vec.ToArray();
     }
 }