我已经用swig构建了python包装器,但是需要将const *float
变量传递给c ++函数。那么如何调用这个变量呢?还是用python代码代替?
get_face_feature的c ++属性为get_face_feature(const char* image,int img_type,const float* &feature)
这是python函数:
import face
import numpy as np
a = face.BaiduFaceApi()
a.sdk_init()
feature=[]
b = a.get_face_feature('1.jpg', 2,feature)
print(b)
这是swig包装代码:
%module face
%{
#include "baidu_face_api.h"
%}
// %inline %{
// float *GetReference(BaiduFaceApi *api, const char* image,int
//img_type)
// {
// float *feature;
// float *&ptr = feature;
// api->get_face_feature(image, img_type, ptr);
// return ptr;
// }
// %}
%include "baidu_face_api.h"
以下是用于构建python软件包的设置函数:
from distutils.core import setup,Extension
pht_module=Extension('_face',
include_dirs=['../../include/'],
library_dirs=['../../facelib/'],
libraries=['BaiduFaceApi-ubuntu16', 'FaceSDK'],
runtime_library_dirs=['../../facelib/'],
sources=['python_wrapper_wrap.cxx'],
extra_compile_args=['-O3', '-std=c++0x', '-fPIC' ],
swig_opts=['-c++'],
)
setup(name='face',
version='0.1',
author='SWIG Docs',
description='Simple wsig pht from docs',
ext_modules=[pht_module],
py_modules=['face']
)
我已经尝试过typemap和指针,但是没有成功