c# - C# 中的 Visual Studio 2017 Python 脚本
问题描述
这是我的主文件
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);
}
这是我的 Image.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:'No module named cv2'”
解决方案
推荐阅读
- jquery - ajax 和 fetch 中的数据是不同的
- jetbrains-ide - 无法在 JetBrains DataGrip 2020.1.4 中设置 SQLServer 连接
- html - 淡化 CSS(不是过渡)
- javascript - for-loop 和 await fetch
- firebase - 无法访问 Cloud Firestore 后端错误
- javascript - 使用 JavaScript 在新选项卡中打开网页
- javascript - 在下面给出的情况下,回调函数有什么用?
- assembly - Java 到汇编语言 ASM
- php - 循环搜索 PHP
- android - 启动模拟器后黑屏