Ejemplo n.º 1
0
        private bool OpenProject()
        {
            if ((project != null) && (projectDirty || boxDirty))
            {
                if (MessageBox.Show("Do you want to save the current project?", "JTesseract", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SaveProject();
                }
            }

            CloseProject();

            project = new JProject();
            string projectFilePath   = null;
            bool   existingProject   = false;
            string projectFolderPath = null;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "JTesseract Project Files (*.tes)|*.tes";

            while (!existingProject)
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    projectFilePath = openFileDialog.FileName;

                    projectFolderPath = projectFilePath.Substring(0, projectFilePath.LastIndexOf('.'));

                    if (!Directory.Exists(projectFolderPath))
                    {
                        MessageBox.Show("Seems like a currupted project: " + projectFolderPath + ". Please try another!", "JTesseract", MessageBoxButtons.OK);
                    }
                    else
                    {
                        existingProject = true;
                    }
                }
                else
                {
                    return(false);
                }
            }

            if (project.LoadProject(projectFilePath))
            {
                textBoxFrequentWordsList.Text = File.ReadAllText(projectFolderPath + @"\frequent_words.txt");
                textBoxWordsList.Text         = File.ReadAllText(projectFolderPath + @"\words.txt");
                textBoxUserWords.Text         = File.ReadAllText(projectFolderPath + @"\user_words.txt");
                textBoxAmbiguity.Text         = File.ReadAllText(projectFolderPath + @"\ambiguities.txt");

                this.Text = "JTesseract - " + projectFilePath;
            }

            projectDirty = false;

            return(UpdateListViewSourceImages());
        }
Ejemplo n.º 2
0
        private void CloseProject()
        {
            if ((project != null) && (projectDirty || boxDirty))
            {
                if (MessageBox.Show("Do you want to save the current project?", "JTesseract", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SaveProject();
                }
            }

            project = null;
            textBoxFrequentWordsList.Text = "";
            textBoxWordsList.Text         = "";
            textBoxUserWords.Text         = "";
            textBoxAmbiguity.Text         = "";

            projectDirty = false;
            boxDirty     = false;

            canvas.CurrentBox         = -1;
            preview.CurrentBox        = null;
            previewPerChar.CurrentBox = null;
            canvas.MainImage          = null;
            preview.MainImage         = null;
            previewPerChar.MainImage  = null;
            listViewSourceImages.Items.Clear();
            listView.Items.Clear();
            textBoxChars.Text        = "";
            textBoxUnicode1.Text     = "";
            textBoxUnicode2.Text     = "";
            textBoxUnicode3.Text     = "";
            textBoxUnicode4.Text     = "";
            textBoxUnicode5.Text     = "";
            textBoxUnicode6.Text     = "";
            textBoxBoxFile.Text      = "";
            textBoxTrainingFile.Text = "";
            textBoxTesseractLog.Text = "";

            this.Text = "JTesseract";
        }
Ejemplo n.º 3
0
        //public bool ImportImages()
        //{
        //    if (project == null)
        //    {
        //        NewProject();
        //    }

        //    OpenFileDialog openFileDialog = new OpenFileDialog();
        //    openFileDialog.Filter = "TIFF (*.tif, *.tiff)|*.tif;*.tiff";
        //    openFileDialog.Multiselect = true;

        //    if (openFileDialog.ShowDialog() == DialogResult.OK)
        //    {
        //        int count = openFileDialog.FileNames.Length;
        //        for (int i = 0; i < count; i++)
        //        {
        //            string fileName = openFileDialog.FileNames[i];
        //            project.ImportSourceImage(fileName);
        //        }
        //    }

        //    CreateBoxesWithoutOverwriting();

        //    UpdateListViewSourceImages();

        //    return true;
        //}

        //public void CreateBoxesWithoutOverwriting()
        //{
        //    int count = project.SourceImages.Count;

        //    for (int i = 0; i < count; i++)
        //    {
        //        string fileName = (string)project.SourceImages[i];
        //        string fileNameSegment = fileName.Substring(0, fileName.LastIndexOf('.'));

        //        if (!File.Exists(project.ProjectFolder + fileNameSegment + ".box"))
        //        {
        //            wrapper.CreateBoxFile(project.ProjectFolder, fileName);
        //        }
        //    }
        //}


        #region Project functions

        private bool NewProject()
        {
            if ((project != null) && (projectDirty || boxDirty))
            {
                if (MessageBox.Show("Do you want to save the current project?", "JTesseract", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SaveProject();
                }
            }

            CloseProject();

            string projectFilePath   = null;
            bool   existingProject   = true;
            string projectFolderPath = null;

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "JTesseract Project Files (*.tes)|*.tes";
            ProjectSettings projectSettings = new ProjectSettings();

            projectSettings.LanguageName = "eng";

            if (projectSettings.ShowDialog() == DialogResult.OK)
            {
                while (existingProject)
                {
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        projectFilePath = saveFileDialog.FileName;


                        projectFolderPath = projectFilePath.Substring(0, projectFilePath.LastIndexOf('.'));

                        if (Directory.Exists(projectFolderPath))
                        {
                            if (MessageBox.Show("Do you want to overwrite the existing folder: " + projectFolderPath, "JTesseract", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                existingProject = false;
                            }
                        }
                        else
                        {
                            existingProject = false;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            project = new JProject();
            project.LanguageName = projectSettings.LanguageName; // TODO: validate the language name, example - 3 letter language code, invalid chars etc..
            project.NewProject(projectFilePath);

            this.Text = "JTesseract - " + projectFilePath;

            textBoxFrequentWordsList.Text = File.ReadAllText(projectFolderPath + @"\frequent_words.txt");
            textBoxWordsList.Text         = File.ReadAllText(projectFolderPath + @"\words.txt");
            textBoxUserWords.Text         = File.ReadAllText(projectFolderPath + @"\user_words.txt");
            textBoxAmbiguity.Text         = File.ReadAllText(projectFolderPath + @"\ambiguities.txt");
            projectDirty = false;

            return(UpdateListViewSourceImages());
        }