예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // _licensePlateDetector = new LicensePlateDetector("x64/");
            _licensePlateDetector = new LicensePlateDetector(ocrPath + System.IO.Path.DirectorySeparatorChar);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _imageView = FindViewById <ImageView>(Resource.Id.imageView1);
            Button loadPictureBtn = FindViewById <Button>(Resource.Id.LoadPictureBtn);

            loadPictureBtn.Click += LoadPicture;

            Button tesseractBtn = FindViewById <Button>(Resource.Id.TesseractBtn);

            tesseractBtn.Click += ExecuteTesseract;

            if (IsThereAnAppToTakePictures())
            {
                CreateDirectoryForPictures();
                Button takePicture = FindViewById <Button>(Resource.Id.TakePictureBtn);
                takePicture.Click += TakeAPicture;
            }

            _sensorManager = (SensorManager)GetSystemService(SensorService);
            battery        = (BatteryManager)GetSystemService(BatteryService);
        }
 public PhotoLPRWindow()
 {
     InitializeComponent();
     _userManagement       = new UserManager();
     _fileParser           = new FileParser();
     _licensePlateDetector = new LicensePlateDetector(@"C:\Emgu\emgucv-windesktop_x64-cuda 3.1.0.2504\Emgu.CV.World\tessdata");
 }
예제 #3
0
        public LicensePlateRecognitionForm()
        {
            InitializeComponent();
            _licensePlateDetector = new LicensePlateDetector("");
            Mat  m  = new Mat("E:\\C#\\高级程序设计\\图像处理\\王先文高级程序设计\\Image+Processing\\Image Processing\\Image Processing\\license-plate.jpg");
            UMat um = m.GetUMat(AccessType.ReadWrite);

            imageBox1.Image = um;
            ProcessImage(m);
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();

            for (var i = 1; i < 15; i++)
            {
                ListView1.Items.Add(new ParkingEntry {
                    Name = $"Person #{i}", PlateNumber = $"Plate #{i}", DateEntry = DateTime.Now, DateExit = DateTime.Now.AddHours(i)
                });
            }

            var path   = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var folder = System.IO.Path.Combine(path, "tessdata");

            _licensePlateDetector = new LicensePlateDetector(folder);

            Mat  m  = new Mat(@"C:\Users\cayent\Desktop\ImageTest\222.jpg");
            UMat um = m.GetUMat(AccessType.ReadWrite);

            this.ImagePlate.Image = um;
            //ProcessImage(m);
            _ocr = new Tesseract(folder, "eng", OcrEngineMode.TesseractLstmCombined, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890");
            _ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890");


            //create OCR engine
            //_ocr = new Tesseract(System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\\", "eng", OcrEngineMode.TesseractLstmCombined);
            //_ocr.Init("", "eng", OcrEngineMode.TesseractLstmCombined);
            //_ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890");

            _ocr.SetImage(m);
            _ocr.Recognize();

            var text1 = _ocr.GetBoxText();
            var text2 = _ocr.GetCharacters();
            var text3 = _ocr.GetHOCRText();
            //var text4 = _ocr.GetOsdText(1);
            var text5 = _ocr.GetTSVText();
            var text6 = _ocr.GetUNLVText();
            var text7 = _ocr.GetUTF8Text();

            Plate.Text = text7;
        }
예제 #5
0
        public UploadFile ProcessImage(IInputOutputArray image)
        {
            string                   path                           = AppContext.BaseDirectory;
            string                   base64string                   = string.Empty;
            UploadFile               uploadFile                     = new UploadFile();
            LicensePlateDetector     _licensePlateDetector          = new LicensePlateDetector(path);
            List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
            List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
            List <RotatedRect>       licenseBoxList                 = new List <RotatedRect>();
            List <string>            words                          = _licensePlateDetector.DetectLicensePlate(
                image,
                licensePlateImagesList,
                filteredLicensePlateImagesList,
                licenseBoxList);
            Point startPoint = new Point(10, 10);

            for (int i = 0; i < words.Count; i++)
            {
                Mat dest = new Mat();
                CvInvoke.VConcat(licensePlateImagesList[i], filteredLicensePlateImagesList[i], dest);
                PointF[] verticesF = licenseBoxList[i].GetVertices();
                Point[]  vertices  = Array.ConvertAll(verticesF, Point.Round);
                using (VectorOfPoint pts = new VectorOfPoint(vertices))
                    CvInvoke.Polylines(image, pts, true, new Bgr(Color.Red).MCvScalar, 2);
                UMat mat = (UMat)filteredLicensePlateImagesList[i];
                Image <Bgr, byte> LpImage = mat.ToImage <Bgr, byte>();
                byte[]            LpBytes = LpImage.ToJpegData();
                uploadFile.RawData.Add(new RawData {
                    RawImage = "data:image/jpg;base64," + Convert.ToBase64String(LpBytes, 0, LpBytes.Length), Number = words[i]
                });
            }
            using (Image <Bgr, byte> img = (Image <Bgr, byte>)image)
            {
                Byte[] bytes = img.ToJpegData();
                base64string          = "data:image/jpg;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
                uploadFile.OutputFile = base64string;
            }
            return(uploadFile);
        }
        /*
         * private static void TesseractDownloadLangFile(String folder, String lang)
         * {
         *  String subfolderName = "tessdata";
         *  String folderName = System.IO.Path.Combine(folder, subfolderName);
         *  if (!System.IO.Directory.Exists(folderName))
         *  {
         *      System.IO.Directory.CreateDirectory(folderName);
         *  }
         *  String dest = System.IO.Path.Combine(folderName, String.Format("{0}.traineddata", lang));
         *  if (!System.IO.File.Exists(dest))
         *      using (System.Net.WebClient webclient = new System.Net.WebClient())
         *      {
         *          String source =
         *              String.Format("https://github.com/tesseract-ocr/tessdata/blob/4592b8d453889181e01982d22328b5846765eaad/{0}.traineddata?raw=true", lang);
         *
         *          Console.WriteLine(String.Format("Downloading file from '{0}' to '{1}'", source, dest));
         *          webclient.DownloadFile(source, dest);
         *          Console.WriteLine(String.Format("Download completed"));
         *      }
         * }*/

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            RootElement root = Root;

            root.UnevenRows = true;
            UIImageView   imageView      = new UIImageView(View.Frame);
            StringElement messageElement = new StringElement("");
            StringElement licenseElement = new StringElement("");

            root.Add(new Section()
            {
                new StyledStringElement("Process", delegate
                {
                    String path = "tessdata";

                    messageElement.Value = String.Format("Checking Tesseract language data...");
                    try
                    {
                        LicensePlateDetector.TesseractDownloadLangFile(path, "eng");
                        LicensePlateDetector.TesseractDownloadLangFile(path, "osd");
                    }
                    catch (System.Net.WebException)
                    {
                        messageElement.Value =
                            String.Format(
                                "Failed to download Tesseract language file, please check internet connection.");
                        return;
                    }
                    catch (Exception e)
                    {
                        messageElement.Value = e.Message;
                        return;
                    }
                    messageElement.Value = String.Format("Checking Tesseract language data...");

                    using (Image <Bgr, Byte> image = new Image <Bgr, byte>("license-plate.jpg"))
                    {
                        LicensePlateDetector detector = new LicensePlateDetector(path);
                        Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                        List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
                        List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
                        List <RotatedRect> licenseBoxList = new List <RotatedRect>();
                        List <string> words = detector.DetectLicensePlate(
                            image,
                            licensePlateImagesList,
                            filteredLicensePlateImagesList,
                            licenseBoxList);

                        watch.Stop(); //stop the timer
                        messageElement.Value = String.Format("{0} milli-seconds", watch.Elapsed.TotalMilliseconds);

                        StringBuilder builder = new StringBuilder();
                        foreach (String w in words)
                        {
                            builder.AppendFormat("{0} ", w);
                        }
                        licenseElement.Value = builder.ToString();

                        messageElement.GetImmediateRootElement().Reload(messageElement, UITableViewRowAnimation.Automatic);
                        licenseElement.GetImmediateRootElement().Reload(licenseElement, UITableViewRowAnimation.Automatic);
                        foreach (RotatedRect box in licenseBoxList)
                        {
                            image.Draw(box, new Bgr(Color.Red), 2);
                        }
                        Size frameSize = FrameSize;
                        using (Mat resized = new Mat())
                        {
                            CvInvoke.ResizeForFrame(image, resized, frameSize);
                            imageView.Image = resized.ToUIImage();
                            imageView.Frame = new RectangleF(PointF.Empty, resized.Size);
                        }
                        imageView.SetNeedsDisplay();
                        ReloadData();
                    }
                }
                                        )
            });
            root.Add(new Section("Recognition Time")
            {
                messageElement
            });
            root.Add(new Section("License Plate")
            {
                licenseElement
            });
            root.Add(new Section()
            {
                imageView
            });
        }
예제 #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            RootElement root = Root;

            root.UnevenRows = true;
            UIImageView   imageView      = new UIImageView(View.Frame);
            StringElement messageElement = new StringElement("");
            StringElement licenseElement = new StringElement("");

            root.Add(new Section()
            {
                new StyledStringElement("Process", delegate {
                    using (Image <Bgr, Byte> image = new Image <Bgr, Byte>("license-plate.jpg"))
                    {
                        LicensePlateDetector detector = new LicensePlateDetector(".");
                        Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                        List <Image <Gray, Byte> > licensePlateImagesList         = new List <Image <Gray, byte> >();
                        List <Image <Gray, Byte> > filteredLicensePlateImagesList = new List <Image <Gray, byte> >();
                        List <RotatedRect> licenseBoxList = new List <RotatedRect>();
                        List <string> words = detector.DetectLicensePlate(
                            image,
                            licensePlateImagesList,
                            filteredLicensePlateImagesList,
                            licenseBoxList);

                        watch.Stop(); //stop the timer
                        messageElement.Value = String.Format("{0} milli-seconds", watch.Elapsed.TotalMilliseconds);

                        StringBuilder builder = new StringBuilder();
                        foreach (String w in words)
                        {
                            builder.AppendFormat("{0} ", w);
                        }
                        licenseElement.Value = builder.ToString();

                        messageElement.GetImmediateRootElement().Reload(messageElement, UITableViewRowAnimation.Automatic);
                        licenseElement.GetImmediateRootElement().Reload(licenseElement, UITableViewRowAnimation.Automatic);
                        foreach (RotatedRect box in licenseBoxList)
                        {
                            image.Draw(box, new Bgr(Color.Red), 2);
                        }
                        Size frameSize = FrameSize;
                        using (Image <Bgr, byte> resized = image.Resize(frameSize.Width, frameSize.Height, Emgu.CV.CvEnum.Inter.Cubic, true))
                        {
                            imageView.Image = resized.ToUIImage();
                            imageView.Frame = new RectangleF(PointF.Empty, resized.Size);
                        }
                        imageView.SetNeedsDisplay();
                        ReloadData();
                    }
                }
                                        )
            });
            root.Add(new Section("Recognition Time")
            {
                messageElement
            });
            root.Add(new Section("License Plate")
            {
                licenseElement
            });
            root.Add(new Section()
            {
                imageView
            });
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            OnImagePicked += (sender, image) =>
            {
                if (image == null)
                {
                    return;
                }

                ISharedPreferences preference = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
                String             appVersion = PackageManager.GetPackageInfo(PackageName, Android.Content.PM.PackageInfoFlags.Activities).VersionName;
                if (!preference.Contains("tesseract-data-version") || !preference.GetString("tesseract-data-version", null).Equals(appVersion) ||
                    !preference.Contains("tesseract-data-path"))
                {
                    AndroidFileAsset.OverwriteMethod overwriteMethod = AndroidFileAsset.OverwriteMethod.AlwaysOverwrite;

                    FileInfo a8 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.traineddata", "tmp", overwriteMethod);
                    FileInfo a0 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.bigrams", "tmp", overwriteMethod);
                    FileInfo a1 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.fold", "tmp", overwriteMethod);
                    FileInfo a2 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.lm", "tmp", overwriteMethod);
                    FileInfo a3 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.nn", "tmp", overwriteMethod);
                    FileInfo a4 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.params", "tmp", overwriteMethod);
                    FileInfo a5 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.size", "tmp", overwriteMethod);
                    FileInfo a6 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.cube.word-freq", "tmp", overwriteMethod);
                    FileInfo a7 = AndroidFileAsset.WritePermanantFileAsset(this, "tessdata/eng.tesseract_cube.nn", "tmp", overwriteMethod);

                    //save tesseract data path
                    ISharedPreferencesEditor editor = preference.Edit();
                    editor.PutString("tesseract-data-version", appVersion);
                    editor.PutString("tesseract-data-path", System.IO.Path.Combine(a0.DirectoryName, "..") + System.IO.Path.DirectorySeparatorChar);
                    editor.Commit();
                }

                LicensePlateDetector detector = new LicensePlateDetector(preference.GetString("tesseract-data-path", null));
                Stopwatch            watch    = Stopwatch.StartNew(); // time the detection process

                List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
                List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
                List <RotatedRect>       licenseBoxList = new List <RotatedRect>();
                List <string>            words          = detector.DetectLicensePlate(
                    image,
                    licensePlateImagesList,
                    filteredLicensePlateImagesList,
                    licenseBoxList);

                watch.Stop(); //stop the timer

                StringBuilder builder = new StringBuilder();
                builder.Append(String.Format("{0} milli-seconds. ", watch.Elapsed.TotalMilliseconds));
                foreach (String w in words)
                {
                    builder.AppendFormat("{0} ", w);
                }
                SetMessage(builder.ToString());

                foreach (RotatedRect box in licenseBoxList)
                {
                    Rectangle rect = box.MinAreaRect();
                    CvInvoke.Rectangle(image, rect, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                }

                SetImageBitmap(image.ToBitmap());
                image.Dispose();
            };


            OnButtonClick += delegate
            {
                PickImage("license-plate.jpg");
            };
        }
예제 #9
0
        public MainViewModel()
        {
            string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            _licensePlateDetector = new LicensePlateDetector(path + "\\..\\..\\..\\..\\tessdata");
        }
예제 #10
0
        /*
         * private static void TesseractDownloadLangFile(String folder, String lang)
         * {
         *  String subfolderName = "tessdata";
         *  String folderName = System.IO.Path.Combine(folder, subfolderName);
         *  if (!System.IO.Directory.Exists(folderName))
         *  {
         *      System.IO.Directory.CreateDirectory(folderName);
         *  }
         *  String dest = System.IO.Path.Combine(folderName, String.Format("{0}.traineddata", lang));
         *  if (!System.IO.File.Exists(dest))
         *      using (System.Net.WebClient webclient = new System.Net.WebClient())
         *      {
         *          String source = Emgu.CV.OCR.Tesseract.GetLangFileUrl(lang);
         *
         *          Console.WriteLine(String.Format("Downloading file from '{0}' to '{1}'", source, dest));
         *          webclient.DownloadFile(source, dest);
         *          Console.WriteLine(String.Format("Download completed"));
         *      }
         * }*/

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            OnImagePicked += (sender, image) =>
            {
                if (image == null)
                {
                    return;
                }

                String path = System.IO.Path.Combine(this.FilesDir.AbsolutePath, "tessdata");

                try
                {
                    SetProgressMessage("Checking Tesseract Lang files...");
                    LicensePlateDetector.TesseractDownloadLangFile(path, "eng");
                    LicensePlateDetector.TesseractDownloadLangFile(path, "osd");
                    SetProgressMessage("Please wait ...");
                }
                catch (System.Net.WebException e)
                {
                    SetMessage("Unable to download tesseract language file from Internet, please check your Internet connection.");
                    Console.WriteLine(e);
                    return;
                }
                catch (Exception e)
                {
                    SetMessage(e.ToString());
                    Console.WriteLine(e);
                    return;
                }


                LicensePlateDetector detector = new LicensePlateDetector(path + System.IO.Path.DirectorySeparatorChar);


                Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
                List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
                List <RotatedRect>       licenseBoxList = new List <RotatedRect>();
                List <string>            words          = detector.DetectLicensePlate(
                    image,
                    licensePlateImagesList,
                    filteredLicensePlateImagesList,
                    licenseBoxList);

                watch.Stop(); //stop the timer

                StringBuilder builder = new StringBuilder();
                builder.Append(String.Format("{0} milli-seconds. ", watch.Elapsed.TotalMilliseconds));
                foreach (String w in words)
                {
                    builder.AppendFormat("{0} ", w);
                }
                SetMessage(builder.ToString());

                foreach (RotatedRect box in licenseBoxList)
                {
                    Rectangle rect = box.MinAreaRect();
                    CvInvoke.Rectangle(image, rect, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                }

                SetImageBitmap(image.ToBitmap());
                image.Dispose();
            };


            OnButtonClick += delegate
            {
                PickImage("license-plate.jpg");
            };
        }
예제 #11
0
        public void LicensePlateDetectorTest()
        {
            var objectTest = new LicensePlateDetector(@"D:\Downloads\LicencePlateRecognition\GUI-Prototype\testData\image002.png");

            objectTest.DetectLicensePlate()
        }