示例#1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        void DisplayResultImage()
        {
            if (lstImage.Items.Count == 0 || lstImage.SelectedItems.Count == 0)
            {
                return;
            }

            string fileName = lstImage.SelectedItems[0].Text;


            string inputPath = TGMTutil.CorrectPath(txtFolderInput.Text);
            string failedDir = txtFailedDir.Text != "" ? TGMTutil.CorrectPath(txtFailedDir.Text) : "";
            string outputDir = txtFolderOutput.Text != "" ? TGMTutil.CorrectPath(txtFolderOutput.Text) : "";

            if (txtFolderOutput.Text != "" && File.Exists(outputDir + fileName))
            {
                picResult.ImageLocation = outputDir + fileName;
                PrintMessage(outputDir + fileName);
            }
            else if (File.Exists(inputPath + fileName))
            {
                picResult.ImageLocation = inputPath + fileName;
                PrintMessage(inputPath + fileName);
            }
            else if (txtFailedDir.Text != "" && File.Exists(failedDir + fileName))
            {
                picResult.ImageLocation = failedDir + fileName;
                PrintMessage(failedDir + fileName);
            }
            else
            {
                PrintError("File " + inputPath + fileName + " does not exist");
            }
        }
示例#2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            string filePath = TGMTutil.CorrectPath(txtFolderInput.Text);

            filePath += lstImage.SelectedItems[0].Text;
            if (!File.Exists(filePath))
            {
                PrintMessage("File does not exist");
            }


            if (e.ClickedItem.Name == "btnCopyPath")
            {
                Clipboard.SetText(filePath);
                PrintMessage("Copied path to clipboard");
            }
            else if (e.ClickedItem.Name == "btnCopyImage")
            {
                StringCollection paths = new StringCollection();
                paths.Add(filePath);
                Clipboard.SetFileDropList(paths);
                PrintMessage("Copied image to clipboard");
            }
            else if (e.ClickedItem.Name == "btnOpenImage")
            {
                System.Diagnostics.Process.Start(filePath);
            }
            else if (e.ClickedItem.Name == "btnDelete")
            {
                FileSystem.DeleteFile(filePath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
            }
        }
示例#3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void bgWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar1.Visible = false;
            timerProgressbar.Stop();
            btnDetect.Text = "Start detect (F5)";
            if (txtFolderOutput.Text != "")
            {
                PrintMessage("Save report to " + TGMTutil.CorrectPath(txtFolderInput.Text) + "_report.csv");
            }
        }
示例#4
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void lstImage_KeyDown(object sender, KeyEventArgs e)
        {
            string filePath = TGMTutil.CorrectPath(txtFolderInput.Text);

            filePath += lstImage.SelectedItems[0].Text;
            if (e.KeyCode == Keys.Enter)
            {
                System.Diagnostics.Process.Start(filePath);
            }
            else if (e.KeyCode == Keys.Delete)
            {
                FileSystem.DeleteFile(filePath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
            }
        }
示例#5
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region BackgroundWorker

        private void bgWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string inputPath = "";

            if (txtFolderInput.Text != "")
            {
                inputPath = TGMTutil.CorrectPath(txtFolderInput.Text);
            }
            string failedDir = "";

            if (txtFailedDir.Text != "")
            {
                failedDir = TGMTutil.CorrectPath(txtFailedDir.Text);
            }

            string validDir = "";

            if (txtValidDir.Text != "")
            {
                validDir = TGMTutil.CorrectPath(txtValidDir.Text);
            }

            string invalidDir = "";

            if (txtInvalidDir.Text != "")
            {
                invalidDir = TGMTutil.CorrectPath(txtInvalidDir.Text);
            }

            int    exactlyCount = 0;
            string content      = "";

            for (int i = 0; i < lstImage.Items.Count; i++)
            {
                if (bgWorker1.CancellationPending)
                {
                    return;
                }
                bgWorker1.ReportProgress(i + 1);

                bikeDetector.OutputFileName = lstImage.Items[i].Text;

                string filePath = inputPath + lstImage.Items[i].Text;
                string ext      = filePath.Substring(filePath.Length - 4).ToLower();
                content += Path.GetFileName(filePath) + ",";

                if (ext != ".jpg" && ext != ".png" && ext != ".bmp")
                {
                    continue;
                }
                PrintMessage(i + " / " + lstImage.Items.Count + " " + filePath);

                Bitmap bmp;
                try
                {
                    bmp = (Bitmap)Bitmap.FromFile(filePath);
                }
                catch (Exception ex)
                {
                    continue;
                }

                BikePlate result = bikeDetector.ReadPlate(bmp);
                bmp.Dispose();

                if (result.hasPlate)
                {
                    if (lstImage.Items[i].SubItems.Count == 1)
                    {
                        lstImage.Items[i].SubItems.Add(result.text);
                    }
                    else
                    {
                        lstImage.Items[i].SubItems[1].Text = result.text;
                    }
                    lstImage.Items[i].ForeColor = result.isValid ? Color.Blue : Color.Black;
                    content += "x,";

                    if (result.isValid)
                    {
                        exactlyCount++;
                        if (chkMoveValid.Checked)
                        {
                            Task.Run(() => File.Move(inputPath + lstImage.Items[i].Text, validDir + lstImage.Items[i].Text));
                        }
                    }
                    else
                    {
                        if (chkMoveInvalid.Checked)
                        {
                            Task.Run(() => File.Move(inputPath + lstImage.Items[i].Text, invalidDir + lstImage.Items[i].Text));
                        }
                    }
                }
                else
                {
                    if (lstImage.Items[i].SubItems.Count == 1)
                    {
                        lstImage.Items[i].SubItems.Add(result.error);
                    }
                    else
                    {
                        lstImage.Items[i].SubItems[1].Text = result.error;
                    }
                    if (chkMoveFail.Checked)
                    {
                        Task.Run(() => File.Move(inputPath + lstImage.Items[i].Text, failedDir + lstImage.Items[i].Text));
                    }

                    lstImage.Items[i].ForeColor = Color.Red;
                    content += ",";
                }

                content += result.text;
                content += "\r\n";


                result.Dispose();


                lstImage.EnsureVisible(i);
            }

            if (inputPath != "")
            {
                content += "Exactly " + exactlyCount + " / " + lstImage.Items.Count + " plates\r\n";
                File.WriteAllText(Path.GetDirectoryName(inputPath) + "\\_report.csv", content);
            }
        }