我直接贴段代码,原理类似c#如何调用exe文件
using PIE.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
namespace OpenCVMapApplication
{
/// <summary>
/// PIESDK和Opencv结合命令
/// </summary>
class OpenCVTestCommand : DesktopCommand
{
/// <summary>
/// 构造函数
/// </summary>
public OpenCVTestCommand()
{
this.Caption = "OpenCVTestCommand";
this.Name = "OpenCVTestCommand";
}
/// <summary>
/// 单击事件
/// </summary>
public override void OnClick()
{
string exe_path = @"E:\Software\PIE示例教程\PIE示例数据\图片\OpencvTest.exe";// 执行调用exe路径
string[] the_args = { @"E:\Software\PIE示例教程\PIE示例数据\OpenCV文件\window7.png" };// exe执行的参数
bool result = StartProcess(exe_path, the_args);
if (result == false)
{
System.Windows.Forms.MessageBox.Show("执行失败!");
}
}
/// <summary>
/// 进程调用
/// </summary>
/// <param name="exePath">exe执行程序调用</param>
/// <param name="args">参数</param>
/// <returns></returns>
public bool StartProcess(string exePath, params string[] args)
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
#region 第一种方法
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo(exePath, s); // 括号里是(程序名,参数)
process.StartInfo = startInfo;
process.Start();
#endregion
#region 线程第二种方法
//Thread thread = new Thread(delegate () {
// System.Diagnostics.Process p = new System.Diagnostics.Process();
// p.StartInfo.FileName = exePath; ; // 被调exe
// p.StartInfo.UseShellExecute = false;//是否使用操作系统的shell启动
// p.StartInfo.RedirectStandardInput = false;//接受来自调用程序的输入
// p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息
// p.StartInfo.RedirectStandardError = false;
// p.StartInfo.CreateNoWindow = true;//不显示调用程序的窗口
// p.StartInfo.Arguments = s; //参数 多个参数使用空格分开
// p.Start();
// p.WaitForExit();
// p.Close();
//});
//thread.Start();
#endregion
return true;
}
}
}
最后在PIE程序界面添加一个按钮,按钮的点击事件设置为toolStripButton_LoadOpenCV_Click,程序运行起来点击按钮就可以调用OpenCV编译可运行的的exe