时隔3个月后的成功
在(一)中,我参照前辈们试过的方法自己实现了C#调用python的.py文件,但是不知道为什么仅仅只有那一个python代码能够运行,所以我怀疑原因是在我自己测试的python程序中调用了cv库的关系。
终于忙完了C#socket的事情,想到这个让我困惑的问题。终于搭了个梯子找到了答案。(站得高看得远?)
上篇中对Process类中的一些方法没有做详细的介绍(ProcessStartInfo 中的方法),在这篇中记录一下:
- FileName 此字符串属性指定要启动的文件的路径。
- UseShellExecute。设置为true时,此属性指示该进程将由Windows Shell启动。如果为false,则直接启动可执行文件或批处理文件。为了获得输出的信息,我们必须将属性设置为false。
- RedirectStandardOutput。如果要捕获输出的消息,则必须将此属性设置为true。
- RedirectStandardError。必须将此属性设置为true才能读取错误流。
- BeginOutputReadLine。捕获标准输出数据
- BeginErrorReadLine。错误捕获
- WaitForExit。等待启动的进程关闭
本次使用的python程序
(1)
import cv2
import numpy as np
import sys
def f(path):
img = cv2.imread(path,0)
height,width = img.shape
x = np.random.randint(0,width-100)
y = np.random.randint(0,height-100)
w = np.random.randint(10,100)
h = np.random.randint(10,100)
label = np.random