Beispiel #1
0
        private async Task InitTextRecognizer(System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
#endif
        {
            if (_ocr == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                manager.AddFile(
                    "https://github.com/emgucv/models/raw/master/scene_text/crnn_cs_CN.onnx",
                    _modelFolderName,
                    "C760BF82D684B87DFABB288E6C0F92D41A8CD6C1780661CA2C3CD10C2065A9BA");

                manager.AddFile(
                    "https://github.com/emgucv/models/raw/master/scene_text/alphabet_3944.txt",
                    _modelFolderName,
                    "8027C9832D86764FECCD9BDD8974829C86994617E5787F178ED97DB2BDA1481A");

                manager.OnDownloadProgressChanged += onDownloadProgressChanged;
#if UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE || UNITY_WEBGL
                yield return(manager.Download());
#else
                await manager.Download();
#endif

                if (manager.AllFilesDownloaded)
                {
                    _ocr            = new TextRecognitionModel(manager.Files[0].LocalFile);
                    _ocr.DecodeType = "CTC-greedy";
                    String[] vocab = File.ReadAllLines(manager.Files[1].LocalFile);
                    _ocr.Vocabulary = vocab;
                    _ocr.SetInputScale(1.0 / 127.5);
                    _ocr.SetInputMean(new MCvScalar(127.5, 127.5, 127.5));
                    _ocr.SetInputSize(new Size(100, 32));


                    /*
                     * if (Emgu.CV.Cuda.CudaInvoke.HasCuda)
                     * {
                     *  _vehicleAttrRecognizer.SetPreferableBackend(Emgu.CV.Dnn.Backend.Cuda);
                     *  _vehicleAttrRecognizer.SetPreferableTarget(Emgu.CV.Dnn.Target.Cuda);
                     * }*/
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Release the memory associated with this scene text detector.
        /// </summary>
        protected override void DisposeObject()
        {
            if (_textDetector != null)
            {
                _textDetector.Dispose();
                _textDetector = null;
            }

            if (_ocr != null)
            {
                _ocr.Dispose();
                _ocr = null;
            }

            if (_freetype != null)
            {
                _freetype.Dispose();
                _freetype = null;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Clear and reset the model. Required Init function to be called again before calling ProcessAndRender.
        /// </summary>
        public void Clear()
        {
            if (_textDetector != null)
            {
                _textDetector.Dispose();
                _textDetector = null;
            }

            if (_ocr != null)
            {
                _ocr.Dispose();
                _ocr = null;
            }

            if (_freetype != null)
            {
                _freetype.Dispose();
                _freetype = null;
            }
        }