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); } }
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; }
public IExportedImage Export(IExporter exporter, Action <IExportConfiguration> configuration) { ExportConfiguration exportConfiguration; configuration(exportConfiguration = new ExportConfiguration(exporter)); _exportedImage = exportConfiguration.Export(_scanImage, exportConfiguration.Options); return(_exportedImage); }