Exemplo n.º 1
0
        private void ChangeDisplayPosition()
        {
            MessageBarManager.SharedInstance.ShowFromBottom = !MessageBarManager.SharedInstance.ShowFromBottom;

            changeDisplayPositionElement.Caption =
                MessageBarManager.SharedInstance.ShowFromBottom
                    ? "Show from top"
                    : "Show from bottom";

            changeDisplayPositionElement.GetImmediateRootElement().Reload(changeDisplayPositionElement, UITableViewRowAnimation.Automatic);


            MessageBarManager.SharedInstance.ShowMessage(
                "Info",
                string.Format("Display from {0}", MessageBarManager.SharedInstance.ShowFromBottom ? "bottom" : "top"),
                MessageType.Info);
        }
        /*
         * 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
            });
        }
Exemplo n.º 3
0
        private void Checkbox_Click(object sender, EventArgs e)
        {
            var  element = sender as Element;
            bool isChecked;
            var  cie = element as CheckboxImageElement;

            if (cie == null)
            {
                var ce = element as CheckboxElement;
                if (ce == null)
                {
                    return;
                }
                else
                {
                    isChecked = ce.Value;
                }
            }
            else
            {
                isChecked = cie.Value;
            }

            int index = section.Elements.IndexOf(element);

            if (index < 0)
            {
                return;
            }

            // get the clicked item
            Item   currentItem = currentList[index];
            Folder folder      = App.ViewModel.Folders.Single(f => f.ID == currentItem.FolderID);

            if (isChecked)
            {
                // add the clicked item to the value list
                valueList.Items.Add(currentItem);
                folder.Items.Add(currentItem);
                StorageHelper.WriteFolder(folder);

                // enqueue the Web Request Record
                RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                                                  new RequestQueue.RequestRecord()
                {
                    ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                    Body    = currentItem
                });
            }
            else
            {
                // remove the clicked item from the value list
                valueList.Items.Remove(currentItem);
                folder.Items.Remove(currentItem);
                StorageHelper.WriteFolder(folder);

                // enqueue the Web Request Record
                RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                                                  new RequestQueue.RequestRecord()
                {
                    ReqType = RequestQueue.RequestRecord.RequestType.Delete,
                    Body    = currentItem
                });
            }

            // re-render the comma-delimited list in the Element that was passed in
            RenderCommaList(stringElement, valueList);
            stringElement.GetImmediateRootElement().Reload(stringElement, UITableViewRowAnimation.None);
        }
Exemplo n.º 4
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
            });
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Console.WriteLine("[AppDelegate] FinishedLaunching");

            UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            _downloader          = new Downloader();
            _downloader.Finished = FinishedDownload;
            _downloads           = new Section("Downloads")
            {
            };

            string templateurl  = "http://pokeprice.local/api/v1/card/image/BLW/{0}";
            string zipurl       = "http://pokeprice.local/api/v1/card/zip/{0}";
            string httpurl      = "http://pokeprice.local/api/v1/http/{0}";
            string redirecturl  = "http://pokeprice.local/api/v1/http/redirect/infinite/0";
            string scollections = "AOR,AQ,AR,B2,BCR,BEST,BKT,BLW,BS,CG,CL,DCR,DEX,DF,DP,DR,DRV,DRX,DS,DX,EM,EPO,EX,FFI,FLF,FO,G1,G2,GE,HL,HP,HS,JU,KSS,LA,LC,LM,LTR,MA,MCD2011,MCD2012,MD,MT,N1,N2,N3,N4,NINTENDOBLACK,NVI,NXD,PHF,PK,PL,PLB,PLF,PLS,POP1,POP2,POP3,POP4,POP5,POP6,POP7,POP8,POP9,PR-BLW,PR-DP,PR-HS,PR-XY,PRC,RG,ROS,RR,RS,RU,SF,SI,SK,SS,SV,SW,TM,TR,TRR,UD,UF,UL,VICTORY,WIZARDSBLACK,XY";

            string[] collections = scollections.Split(',');

                        #if REMOTE
            templateurl = templateurl.Replace("http://pokeprice.local", "https://pokeprice.com");
            zipurl      = zipurl.Replace("http://pokeprice.local", "https://pokeprice.com");
            httpurl     = httpurl.Replace("http://pokeprice.local", "https://pokeprice.com");
            redirecturl = redirecturl.Replace("http://pokeprice.local", "https://pokeprice.com");
                        #endif

            var enable = new BooleanElement("Enabled", true);
            enable.ValueChanged += (sender, e) => {
                _downloader.Enabled = enable.Value;
            };

            var globalprogress = new StringElement("");
            var root           = new RootElement("Root")
            {
                new Section("Management")
                {
                    enable,
                    globalprogress
                },
                _downloads
            };

            _downloader.Progress += (progress) => {
                float  percent  = (progress.Written / (float)progress.Total) * 100;
                int    ipercent = (int)percent;
                string caption  = string.Format("{0} {1} {2}% ({3} / {4})",
                                                "Global",
                                                progress.State.ToString(),
                                                ipercent,
                                                progress.Written,
                                                progress.Total
                                                );
                InvokeOnMainThread(() => {
                    globalprogress.Caption = caption;
                    globalprogress
                    .GetImmediateRootElement()
                    .Reload(globalprogress, UITableViewRowAnimation.Automatic);
                });
            };

            _sample = new DialogViewController(root);

            var add = new UIBarButtonItem("Add",
                                          UIBarButtonItemStyle.Bordered,
                                          (sender, e) => {
                string url = string.Format(templateurl, 1);
                Add(url);
            });

            var addall = new UIBarButtonItem("All",
                                             UIBarButtonItemStyle.Bordered,
                                             (sender, e) => {
                for (int i = 1; i < 80; i++)
                {
                    string url = string.Format(templateurl, i);
                    Add(url);
                }
            });

            var zips = new UIBarButtonItem("Z",
                                           UIBarButtonItemStyle.Bordered,
                                           (sender, e) => {
                foreach (string coll in collections)
                {
                    string url = string.Format(zipurl, coll);
                    Add(url);
                }
            });


            var s404 = new UIBarButtonItem("4",
                                           UIBarButtonItemStyle.Bordered,
                                           (sender, e) => {
                string url = string.Format(httpurl, 404);
                Add(url);
            });

            var s500 = new UIBarButtonItem("5",
                                           UIBarButtonItemStyle.Bordered,
                                           (sender, e) => {
                string url = string.Format(httpurl, 500);
                Add(url);
            });

            var s301 = new UIBarButtonItem("3",
                                           UIBarButtonItemStyle.Bordered,
                                           (sender, e) => {
                string url = string.Format(httpurl, 301);
                Add(url);
            });


            var s301p = new UIBarButtonItem("3+",
                                            UIBarButtonItemStyle.Bordered,
                                            (sender, e) => {
                string url = string.Format(redirecturl, 301);
                Add(url);
            });

            var reset = new UIBarButtonItem("Reset",
                                            UIBarButtonItemStyle.Bordered,
                                            async(sender, e) => {
                await _downloader.Reset();
                Sync();
            });

            var sync = new UIBarButtonItem("S",
                                           UIBarButtonItemStyle.Bordered,
                                           (sender, e) => {
                Sync();
            });


            Navigation = new UINavigationController();
            Window.RootViewController = Navigation;
            Window.MakeKeyAndVisible();

            Navigation.PushViewController(_sample, false);

            _sample.SetToolbarItems(new [] { add, addall, zips, s404, s500, s301, s301p, reset, sync }, true);
            Navigation.SetToolbarHidden(false, true);

            return(true);
        }