private async Task InitLicensePlateDetector(Dnn.Backend preferredBackend, Dnn.Target preferredTarget, System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
        {
            if (_vehicleLicensePlateDetectionModel == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                manager.AddFile(
                    "https://storage.openvinotoolkit.org/repositories/open_model_zoo/2021.2/models_bin/3/vehicle-license-plate-detection-barrier-0106/FP32/vehicle-license-plate-detection-barrier-0106.xml",
                    _modelFolderName);
                manager.AddFile(
                    "https://storage.openvinotoolkit.org/repositories/open_model_zoo/2021.2/models_bin/3/vehicle-license-plate-detection-barrier-0106/FP32/vehicle-license-plate-detection-barrier-0106.bin",
                    _modelFolderName);

                manager.OnDownloadProgressChanged += onDownloadProgressChanged;
                await manager.Download();

                _vehicleLicensePlateDetectionModel =
                    new DetectionModel(manager.Files[1].LocalFile, manager.Files[0].LocalFile);
                _vehicleLicensePlateDetectionModel.SetInputSize(new Size(300, 300));
                _vehicleLicensePlateDetectionModel.SetInputMean(new MCvScalar());
                _vehicleLicensePlateDetectionModel.SetInputScale(1.0);
                _vehicleLicensePlateDetectionModel.SetInputSwapRB(false);
                _vehicleLicensePlateDetectionModel.SetInputCrop(false);


                _vehicleLicensePlateDetectionModel.SetPreferableBackend(preferredBackend);
                _vehicleLicensePlateDetectionModel.SetPreferableTarget(preferredTarget);
            }
        }
Example #2
0
        public async Task Init(System.Net.DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
#endif
        {
            if (_faceDetectionModel == null)
            {
                FileDownloadManager manager = new FileDownloadManager();

                manager.AddFile(
                    "https://github.com/opencv/opencv_3rdparty/raw/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel",
                    _modelFolderName,
                    "2A56A11A57A4A295956B0660B4A3D76BBDCA2206C4961CEA8EFE7D95C7CB2F2D");

                manager.AddFile(
                    "https://raw.githubusercontent.com/opencv/opencv/4.0.1/samples/dnn/face_detector/deploy.prototxt",
                    _modelFolderName,
                    "F62621CAC923D6F37BD669298C428BB7EE72233B5F8C3389BB893E35EBBCF795");

                if (onDownloadProgressChanged != null)
                {
                    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)
                {
                    _faceDetectionModel = new DetectionModel(manager.Files[0].LocalFile, manager.Files[1].LocalFile);
                    _faceDetectionModel.SetInputMean(new MCvScalar(104, 177, 123));
                    _faceDetectionModel.SetInputSize(new Size(300, 300));
                    _faceDetectionModel.SetInputSwapRB(false);
                    _faceDetectionModel.SetInputScale(1.0);
                    _faceDetectionModel.SetInputCrop(false);

#if !(UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_STANDALONE || UNITY_WEBGL)
                    if (Emgu.CV.Cuda.CudaInvoke.HasCuda)
                    {
                        _faceDetectionModel.SetPreferableBackend(Emgu.CV.Dnn.Backend.Cuda);
                        _faceDetectionModel.SetPreferableTarget(Emgu.CV.Dnn.Target.Cuda);
                    }
#endif
                }
            }
        }