unity 通过 dll 传递字符串给python,实现小冰颜值鉴定
生活随笔
收集整理的這篇文章主要介紹了
unity 通过 dll 传递字符串给python,实现小冰颜值鉴定
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳入一個路徑字符串(C#):
public void PassXiaoIce() {try{string img_path = @"D:\XLS_AI_PRO\FaceTest\photo\11.jpg";Debug.Log(img_path.Length);string str = GetIceJson(img_path,img_path.Length);Debug.Log("result_str:" + str);//返回鑒定結果}catch{Debug.LogError("初始化異常!");} }//圖片路徑,返回顏值鑒定結果。 public String GetIceJson(string img_path, int psize) {IntPtr temp = FaceBind.GetResultIce(img_path, psize);string str = Marshal.PtrToStringAnsi(temp).ToString();temp = IntPtr.Zero;return str; }DLL接口(C#):
[DllImport("XiaoICE", EntryPoint = "get_result_ice", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] static extern IntPtr get_result_ice([MarshalAs(UnmanagedType.LPStr)]string g_path,int size);DLL實現代碼(C++)
static char str_json[2048]; #define _csharp_double extern "C" __declspec(dllexport) const char * _csharp_double get_result_ice(wchar_t * img_byte, int bt_size) {import_array();PyObject * pValue = Py_BuildValue("(s#)", img_byte, bt_size);PyObject * pyResult = PyEval_CallObject(pGetXiaoIce, pValue);memset(str_json, 0, sizeof(str_json)); if (pyResult) {const char * str_js;PyArg_Parse(pyResult,"s",&str_js);strcpy_s(str_json, str_js);}else {strcpy_s(str_json, "error!");}Py_CLEAR(pValue);Py_CLEAR(pyResult);return str_json; }?調用入口(python)
#傳入圖片路徑,返回顏值鑒定結果 def identification(img_path):score = Score()re_str = score.start(img_path)return re_str總結
以上是生活随笔為你收集整理的unity 通过 dll 传递字符串给python,实现小冰颜值鉴定的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php xls 繁体字 问号,【专题】如
- 下一篇: 贝勒大学计算机专业,贝勒大学计算机科学.