这是我的主要文件
String filePath, path;
OpenFileDialog ofd = new OpenFileDialog();
Nullable<bool> result = ofd.ShowDialog();
if (result == true)
{
filePath = ofd.FileName;
var sections = filePath.Split('\\');
var fileNam = sections[sections.Length - 1];
path=Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string destFile = System.IO.Path.Combine(path, fileNam);
System.IO.File.Copy(filePath, destFile, true);
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromFile(path + "\\Image.py");
source.Execute(scope);
Object myclass = engine.Operations.Invoke(scope.GetVariable("pythonScriptClass"));
object[] parameters = new object[] { fileNam };
engine.Operations.InvokeMember(myclass, "Image", parameters);
}
这是我的图片.py文件
import cv2
import numpy
class pythonScriptClass:
def Image(filename):
img=cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite("result.png",gray)
Image(filename)
“我犯了个错误”IronPython.Runtime.Exceptions异常.ImportException:'没有名为cv2的模块'
目前没有回答
相关问题 更多 >
编程相关推荐