Ejemplo n.º 1
0
        public ILearnedImage Learn(IExportedImage content, IAlphabet alphabet, LearnerOptions options)
        {
            //save current dir
            var dir      = Environment.CurrentDirectory;
            var tempPath = Path.Combine(Path.GetTempPath(), "octave");

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            Directory.CreateDirectory(tempPath);

            Environment.CurrentDirectory = tempPath;
            try
            {
                // файл с данными
                var data = Path.GetRandomFileName();
                File.WriteAllText(data, content.ExportData);
                // выходной файл
                var outFile = Path.GetRandomFileName();

                // главный скрипт
                var mainContent = GetScriptContent("main.m")
                                  .Replace("%0%", alphabet.Labels.ToString(CultureInfo.InvariantCulture))
                                  .Replace("%1%", data)
                                  .Replace("%2%", outFile);

                var mainScript = Path.GetRandomFileName();
                File.WriteAllText(mainScript, mainContent);

                CopyScriptsToLocalFolder();

                var process = new Process
                {
                    StartInfo =
                    {
                        FileName               = options.ExecutePath,
                        Arguments              = mainScript,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow         = false
                    }
                };

                process.Start();

                Debug.WriteLine(process.StandardOutput.ReadToEnd());

                process.WaitForExit();

                var d = File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, outFile));
                return(new LearnedImage(content, d));
            }
            finally
            {
                // restore current dir
                Environment.CurrentDirectory = dir;
                Directory.Delete(tempPath, true);
            }
        }
Ejemplo n.º 2
0
 public LearnedImage(IExportedImage exported, string[] data)
 {
     Image = exported.Image;
     Blobs = new IBlob[exported.Blobs.Length];
     exported.Blobs.CopyTo(Blobs, 0);
     ExportData  = exported.ExportData;
     LearnedData = data;
 }
Ejemplo n.º 3
0
        public IExportedImage Export(IExporter exporter, Action <IExportConfiguration> configuration)
        {
            ExportConfiguration exportConfiguration;

            configuration(exportConfiguration = new ExportConfiguration(exporter));

            _exportedImage = exportConfiguration.Export(_scanImage, exportConfiguration.Options);
            return(_exportedImage);
        }