版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34510308/article/details/85120199
公共语言扩展 参考链接:http://www.srplab.com/cn/index.html
C#调用python3.0及以上:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Star_csharp;
namespace cshape_tensorflow
{
class Program
{
static void Main(string[] args)
{
DateTime beforDT = System.DateTime.Now;
StarCoreFactory starcore = StarCoreFactory.GetFactory();
StarServiceClass Service = starcore._InitSimple("test", "123", 0, 0);
StarSrvGroupClass SrvGroup = (StarSrvGroupClass)Service._Get("_ServiceGroup");
SrvGroup._InitRaw("python35", Service);
//--load python module
SrvGroup._LoadRawModule("python35","","test.py", false);
StarObjectClass python = Service._ImportRawContext("python35", "", false, "");
//--call python function tt, the return contains two integer, which will be packed into parapkg
int ParaPkg = (int)python._Call("tt", "hello", "world");
DateTime afterDT = System.DateTime.Now;
TimeSpan ts = afterDT.Subtract(beforDT);
Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds);
Console.WriteLine(ParaPkg);
SrvGroup._ClearService();
starcore._ModuleExit();
}
}
}
Python调用C++ dll
cytes参考链接:https://docs.python.org/3.5/library/ctypes.html
import numpy as np
import ctypes
from ctypes import *
import cv2
# TemFun = cdll.LoadLibrary('test0717.dll')
TemFun=ctypes.CDLL("test0717.dll")
TemFun.DetectionBox.restype = ctypes.c_char_p
print(TemFun)
flage=TemFun.DetectionBox("D:/Image/1116/20181116pic_1_merge/1076278A1B7CBC9.TIF".encode("utf-8"))
print(str(flage))
if flage==b'success':
print("hihihi")