private void Form1_Load(object sender, EventArgs e) { string appPath = AppDomain.CurrentDomain.BaseDirectory; string appDir = Directory.GetParent(appPath).FullName; string modelsDir = appPath + "models"; modelsTextBox.Text = modelsDir; string detPath = modelsDir + "\\" + detNameTextBox.Text; string clsPath = modelsDir + "\\" + clsNameTextBox.Text; string recPath = modelsDir + "\\" + recNameTextBox.Text; string keysPath = modelsDir + "\\" + keysNameTextBox.Text; bool isDetExists = File.Exists(detPath); if (!isDetExists) { MessageBox.Show("模型文件不存在:" + detPath); } bool isClsExists = File.Exists(clsPath); if (!isClsExists) { MessageBox.Show("模型文件不存在:" + clsPath); } bool isRecExists = File.Exists(recPath); if (!isRecExists) { MessageBox.Show("模型文件不存在:" + recPath); } bool isKeysExists = File.Exists(recPath); if (!isKeysExists) { MessageBox.Show("Keys文件不存在:" + keysPath); } if (isDetExists && isClsExists && isRecExists && isKeysExists) { ocrEngin = new OcrLite(); ocrEngin.InitModels(detPath, clsPath, recPath, keysPath, (int)numThreadNumeric.Value); } else { MessageBox.Show("初始化失败,请确认模型文件夹和文件后,重新初始化!"); } }
/// <summary> /// 光学扫描初始化 /// </summary> private void OcrLiteInit() { string appPath = AppDomain.CurrentDomain.BaseDirectory; //string appDir = Directory.GetParent(appPath).FullName; string modelsDir = appPath + "models"; string detPath = modelsDir + "\\dbnet.onnx"; string clsPath = modelsDir + "\\angle_net.onnx"; string recPath = modelsDir + "\\crnn_lite_lstm.onnx"; string keysPath = modelsDir + "\\keys.txt"; bool isDetExists = File.Exists(detPath); if (!isDetExists) { MessageBox.Show("模型文件不存在:" + detPath); } bool isClsExists = File.Exists(clsPath); if (!isClsExists) { MessageBox.Show("模型文件不存在:" + clsPath); } bool isRecExists = File.Exists(recPath); if (!isRecExists) { MessageBox.Show("模型文件不存在:" + recPath); } bool isKeysExists = File.Exists(recPath); if (!isKeysExists) { MessageBox.Show("Keys文件不存在:" + keysPath); } if (isDetExists && isClsExists && isRecExists && isKeysExists) { ocrEngin = new OcrLite(); ocrEngin.InitModels(detPath, clsPath, recPath, keysPath, Properties.Settings.Default.OCRThreadCount); } else { MessageBox.Show("初始化失败,请确认模型文件夹和文件后,重新初始化!"); } }
private void initBtn_Click(object sender, EventArgs e) { string modelsDir = modelsTextBox.Text; string detPath = modelsDir + "\\" + detNameTextBox.Text; string clsPath = modelsDir + "\\" + clsNameTextBox.Text; string recPath = modelsDir + "\\" + recNameTextBox.Text; string keysPath = modelsDir + "\\" + keysNameTextBox.Text; bool isDetExists = File.Exists(detPath); if (!isDetExists) { MessageBox.Show("模型文件不存在:" + detPath); } bool isClsExists = File.Exists(clsPath); if (!isClsExists) { MessageBox.Show("模型文件不存在:" + clsPath); } bool isRecExists = File.Exists(recPath); if (!isRecExists) { MessageBox.Show("模型文件不存在:" + recPath); } bool isKeysExists = File.Exists(recPath); if (!isKeysExists) { MessageBox.Show("Keys文件不存在:" + keysPath); } if (isDetExists && isClsExists && isRecExists && isKeysExists) { ocrEngin = new OcrLite(); ocrEngin.InitModels(detPath, clsPath, recPath, keysPath, (int)numThreadNumeric.Value); } else { MessageBox.Show("初始化失败,请确认模型文件夹和文件后,重新初始化!"); } }