作者热门文章
- html - 我的下拉菜单的内容关闭得太快
- c# - 使用 Html Agility Pack 从网页中的表中获取值而不使用 "SelectNode'
- html - 内容容器下的 CSS 下拉菜单
- html - 如何停止嵌套列表重叠父列表?
我在这个使用emgucv(.net的opencv包装器)的程序中挣扎了大约2周。不幸的是,问题不是编程,而是以一种可行的方式设置emgucv。我没有为vb.net做到这一点,所以我尝试为ironpython这样做(因为我也知道python)。 Emgucv在使用ironpython时似乎可以完美地工作,因此我创建了一个函数,该函数将图像作为参数并按照我想要的方式对其进行分析,并返回其中包含结果的另一个图像。问题是我想调用此函数,从VB.net中给它提供图像参数(它可能是包含路径的字符串),并成为另一个包含结果图像作为返回值的字符串。稍后我计划将该项目打包在安装程序中,以便我可以重新分发它。
所以我问你们:您知道一种简单的方法来调用VB.net中的IronPython函数,这样我也可以打包整个项目并将其重新分发给人们吗?
非常感谢您阅读本文,如果您也可以帮助我解决我的问题,那就太好了! :)
最佳答案
虽然IronPython不是我的专长,但我对EMGU及其应用程序非常熟悉。如果您坚持使用IronPython,则以下网站清楚地说明了如何将字符串传递给IronPython Class.
以下代码是从链接中获取的,而不是我自己的:
Option Explicit On
Option Strict On
Imports Microsoft.Scripting.Hosting
Imports IronPython.Hosting
Imports IronPython.Runtime.Types
Module Module1
Sub Main()
Dim helloWorld As New HelloWorldVB()
Console.WriteLine(helloWorld.HelloWorld("Maurice"))
Dim runtime As ScriptRuntime = PythonEngine.CurrentEngine.Runtime
Dim scope As ScriptScope = runtime.ExecuteFile("HelloWorld.py")
Dim pythonType As PythonType = scope.GetVariable(Of PythonType)("HelloWorldIronPython")
helloWorld = CType(runtime.Operations.Call(pythonType), HelloWorldVB)
Console.WriteLine(helloWorld.HelloWorld("Maurice"))
Console.ReadLine()
End Sub
End Module
**Imports Microsoft.Scripting.Hosting
Imports IronPython.Hosting
Imports IronPython.Runtime.Types**
**Dim runtime As ScriptRuntime = PythonEngine.CurrentEngine.Runtime
Dim scope As ScriptScope = runtime.ExecuteFile("HelloWorld.py")
Dim pythonType As PythonType = scope.GetVariable(Of PythonType)("HelloWorldIronPython")
helloWorld = CType(runtime.Operations.Call(pythonType), HelloWorldVB)
Console.WriteLine(helloWorld.HelloWorld("Maurice"))**
关于vb.net - 如何从VB.net轻松调用IronPython函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7112024/
我是一名优秀的程序员,十分优秀!