1. python模块
import cv2
import numpy as np
import sys
def f(path):
img = cv2.imread(path,0)
height,width = img.shape
size = np.random.randint(1,6)
return height,width,size
if __name__ == '__main__':
print(f(sys.argv[1]))
2. C#模块
using System;
using System.Diagnostics;
namespace InterfaceDefect
{
class Program
{
static void Main(string[] args)
{
string filename = @"D:\Softwares\Anaconda3\python.exe"; // python解释器
// pyhon模块 arg1 arg2
string strArgument = @"D:\code\Projects\ConsoleApplication2\ConsoleApplication2\nn_module.py D:\code\Projects\ConsoleApplication2\ConsoleApplication2\0621.png";
ProcessStartInfo startPythonInfo = new ProcessStartInfo(filename, strArgument);
startPythonInfo.UseShellExecute = false; // 是否使用操作系统的shell启动进程
startPythonInfo.RedirectStandardOutput = true; // 是否将应用程序的输出写入到Process.StandardOutput流中。
startPythonInfo.RedirectStandardError = true; // 是否将应用程序的错误输出写入到Process.StandardError流中。
Process process = new Process();
process.StartInfo = startPythonInfo;
process.OutputDataReceived += CaptureOutpt;
//process.OutputDataReceived += CaptureRrror;
process.Start();
process.BeginOutputReadLine();
//process.BeginErrorReadLine();
process.WaitForExit();
Console.ReadKey();
}
static void CaptureOutpt(object sender, DataReceivedEventArgs e)
{
if (e.Data != null) // e.Data就是python模块的返回值
{
Console.WriteLine("计算结果:{0}", e.Data);
}
}
}
}