private void Btn_identify_Click(object sender, RoutedEventArgs e) { if (img_path == null) { MessageBox.Show("图片为空"); return; } xspm_img_model model = new xspm_img_model { file_name = this.img_path, area = new string[] { this.top_left_x, this.top_left_y, this.bot_right_x, this.bot_right_y }, top = tb_top.Text, bottom = tb_bottom.Text, color_count = tb_color.Text }; save_file(model); string path_python = Path.Combine(file_path, file_python); string path_json = Path.Combine(file_path, file_json); string result = RunCMD.run_python(path_python, path_json); bll.analysis_pythonstr(result); Console.WriteLine(result); }
private void save_file(xspm_img_model model) { // 保存 Json 文件 DirectoryInfo dir; if (!Directory.Exists(file_path)) { dir = Directory.CreateDirectory(file_path); } else { dir = new DirectoryInfo(file_path); } string fp = Path.Combine(file_path, file_json); if (!System.IO.File.Exists(fp)) { FileStream fs = new FileStream(fp, FileMode.Create, FileAccess.ReadWrite); fs.Close(); } System.IO.File.WriteAllText(fp, JsonConvert.SerializeObject(model)); }