private void Lst_Profiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox lst = sender as ListBox;

            if (lst.SelectedItem != null)
            {
                _selectedRegionProfile = _regionProfiles.GetRegionProfile(lst.SelectedItem.ToString());
                if (_selectedRegionProfile != null)
                {
                    txt_ProfileName.Text     = _selectedRegionProfile.Name;
                    txt_ProfileName.Enabled  = true;
                    txt_PaperName.Text       = _selectedRegionProfile.PaperSize;
                    txt_SampleImagePath.Text = _selectedRegionProfile.TemplateFile;
                    btn_Delete.Enabled       = true;
                    lst_Regions.Enabled      = true;
                    lst_Regions.UpdateUI(_selectedRegionProfile.Regions);
                }
                else
                {
                    MessageBox.Show("Không thể tải lên cấu hình này.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lst_Profiles.UpdateUI(_regionProfiles.Profiles);
                    RestoreDefaultFormState();
                }
            }
            else
            {
                RestoreDefaultFormState();
            }
        }
Beispiel #2
0
 public static DialogResult ShowCustomDialog(ROIProfile profile)
 {
     using (ProfileSaveDialog dialog = new ProfileSaveDialog(profile))
     {
         return(dialog.ShowDialog());
     }
 }
        public void DeleteRegionProfile(ROIProfile regionProfile)
        {
            string path = Path.Combine(_path, $"{regionProfile.Name}");

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
        public void AddOrUpdateRegionProfile(ROIProfile regionProfile)
        {
            string path = Path.Combine(_path, $"{regionProfile.Name}");

            using (BinaryWriter binary = new BinaryWriter(File.OpenWrite(path)))
            {
                binary.Write(regionProfile.Serialize());
            }
        }
Beispiel #5
0
 private static void InitialLaguagePack(ROIProfile regions)
 {
     foreach (ROI r in regions.Regions)
     {
         if (!_tesseracts.ContainsKey(r.Language))
         {
             _tesseracts.Add(r.Language, GetTesseractWithLanguage(r.Language));
         }
     }
 }
 private void RestoreDefaultFormState()
 {
     _selectedRegionProfile      = null;
     txt_PaperName.Text          = "";
     txt_PaperName.Enabled       = false;
     txt_ProfileName.Text        = "";
     txt_ProfileName.Enabled     = false;
     txt_SampleImagePath.Text    = "";
     txt_SampleImagePath.Enabled = false;
     btn_Delete.Enabled          = false;
     btn_Update.Enabled          = false;
     lst_Regions.Enabled         = false;
     lst_Regions.UpdateUI();
 }
Beispiel #7
0
 private ProfileSaveDialog(ROIProfile profile)
 {
     InitializeComponent();
     _regionProfile = profile;
 }
Beispiel #8
0
        public List <Dictionary <string, string> > GetUtf8TextBaseOnRegions(IImage image, ROIProfile regions, out IImage imgdrawed)
        {
            imgdrawed = null;
            List <Dictionary <string, string> > result = new List <Dictionary <string, string> >();

            if (image == null)
            {
                return(result);
            }

            if (regions == null)
            {
                return(result);
            }

            IPaperResource paperResource = PaperResource.DefaultInstance();
            PaperProfile   paperProfile  = paperResource.GetPaperProfile(regions.PaperSize);

            if (paperProfile == null)
            {
                return(result);
            }

            InitialLaguagePack(regions);
            Dictionary <string, string> onePage     = new Dictionary <string, string>();
            Image <Gray, byte>          imgOriginal = image is Image <Gray, byte>?image as Image <Gray, byte> : new Image <Gray, byte>(image.Bitmap);
            Image <Bgr, byte>           imgColor    = imgOriginal.Copy().Convert <Bgr, byte>();

            foreach (ROI region in regions.Regions)
            {
                Rectangle rect = region.RegionRectangle.ConvertActualyImageSizeToImageResize(paperProfile, imgOriginal.Bitmap);
                imgOriginal.ROI = rect;
                imgColor.Draw(rect, new Bgr(Color.Red), 1);
                _tesseracts[region.Language].SetImage(imgOriginal.Copy());
                string          txt = _tesseracts[region.Language].GetUTF8Text();
                MatchCollection ms  = Regex.Matches(txt, region.GenaratedRegexPattern, RegexOptions.Multiline);
                Match           m   = ms.Cast <Match>().OrderByDescending(s => s.Length).Take(1).FirstOrDefault();
                onePage.Add(region.RegionName, m?.Value);
                imgOriginal.ROI = Rectangle.Empty;
            }
            imgdrawed = imgColor;
            result.Add(onePage);
            return(result);
        }