コード例 #1
0
        private void namesFileButton_Click(object sender, EventArgs e)
        {
            string filePath = GetFilePath(filterString: "YOLO Names File (*.names)|*names", defaultFile: "coco.names", startPath: GetDir(namesTextBox.Text));

            if (filePath != null)
            {
                namesTextBox.Text            = filePath;
                namesTextBox.SelectionStart  = namesTextBox.Text.Length;
                namesTextBox.SelectionLength = 0;

                try
                {
                    igorCore.igorCore igor = new igorCore.igorCore();
                    igor.ThereWolfThereCastle(cfg: "", weights: "", namesTextBox.Text);
                    numberOfObjectsLabel.Text = "The selected model will code images for " + igor.theBags.Count() + " different object classes.";
                    igor.WhatHump();
                    gotNames = true;
                }
                catch
                {
                    numberOfObjectsLabel.Text = "There was a problem with your \"names\" file.";
                    namesTextBox.Text         = "";
                    MessageBox.Show("There was a problem with your \"names\" file. Igor was unable to read the list of objects contained within. " +
                                    "Please check that your file is correctly formatted and is accessible for Igor to read.", "I Ain't Got No Body", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    gotNames = false;
                }
            }
            else
            {
                namesTextBox.Text         = "";
                numberOfObjectsLabel.Text = "There is no \"names\" file selected.";
                gotNames = false;
            }
        }
コード例 #2
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Bags bags = (Bags)e.Argument;

            igorCore.igorCore igor = new igorCore.igorCore();

            try
            {
                igor.ThereWolfThereCastle(bags.GetCfg(), bags.GetWeight(), bags.GetNames());
                igor.WalkThisWay();
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was a problem initializing your YOLO model. Please share the following information with the software developer:" + Environment.NewLine + ex.ToString(),
                                "Damn Your Eyes!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            var inputFiles = Directory.EnumerateFiles(bags.GetFolderIn(), searchPattern: "*.*", searchOption: bags.getDirDepth())
                             .Where(s => s.EndsWith(".jpg") || s.EndsWith(".png"));



            using (FileStream fileStream = new FileStream(bags.GetFileOut(), FileMode.Append, FileAccess.Write, FileShare.Read))
                using (StreamWriter streamWriter = new StreamWriter(fileStream, System.Text.Encoding.UTF8))
                {
                    string headerRow = "\"Filename\"";
                    for (int i = 0; i < igor.bagCount; i++)
                    {
                        headerRow += ",\"" + igor.theBags[i] + "\"";
                    }

                    streamWriter.WriteLine(headerRow);


                    foreach (string file in inputFiles)
                    {
                        if (bgworker.CancellationPending)
                        {
                            break;
                        }
                        bgworker.ReportProgress(0, file.Replace(bags.GetFolderIn(), ""));

                        Dictionary <string, int> imageObjects = new Dictionary <string, int>();
                        for (int i = 0; i < igor.bagCount; i++)
                        {
                            imageObjects.Add(igor.theBags[i], 0);
                        }

                        try
                        {
                            List <string> items = igor.Blücher(file);

                            foreach (string item in items)
                            {
                                imageObjects[item]++;
                            }

                            #region build/write output

                            StringBuilder outputRow = new StringBuilder();

                            //add the filename to the output
                            outputRow.Append("\"" + file.Replace(bags.GetFolderIn(), "").Replace("\"", "\"\"") + "\"");
                            for (int i = 0; i < igor.bagCount; i++)
                            {
                                outputRow.Append(',');
                                outputRow.Append(imageObjects[igor.theBags[i]]);
                            }

                            streamWriter.WriteLine(outputRow.ToString());
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            using (FileStream fs = new FileStream(bags.GetFileOut() + ".log", FileMode.Create, FileAccess.Write, FileShare.Read))
                                using (StreamWriter logWriter = new StreamWriter(fileStream, System.Text.Encoding.UTF8))
                                {
                                    logWriter.WriteLine("================================================");
                                    logWriter.WriteLine("Error processing " + file);
                                    logWriter.WriteLine(Environment.NewLine);
                                    logWriter.WriteLine(ex.ToString());
                                }
                        }
                    }
                }

            igor.WhatHump();
        }