在Python中调用C++模块

时间:2022-11-17 19:47:07

一、一般调用流程

http://www.cnblogs.com/huangshujia/p/4394276.html

二、Python读取图像并传入C++函数,再从C++返回结果图像给Python

https://*.com/questions/19031836/get-background-model-from-backgroundsubtractormog2-in-python

注意:1.Python传入数据的类型要与C++参数类型一致,类型参考下面链接

 ctypes基本数据类型映射表

参数类型预先设定好,或者在调用函数时再把参数转成相应的c_***类型。ctypes的类型对应如下:

http://blog.csdn.net/linda1000/article/details/12623527

ctypes type C type Python Type
c_char char 1-character string
c_wchar wchar_t 1-character unicode string
c_byte char int/long
c_ubyte unsigned char int/long
c_bool bool bool
c_short short int/long
c_ushort unsigned short int/long
c_int int int/long
c_uint unsigned int int/long
c_long long int/long
c_ulong unsigned long int/long
c_longlong __int64 or longlong int/long
c_ulonglong unsigned __int64 or unsigned long long int/long
c_float float float
c_double double float
c_longdouble long double float float
c_char_p char * string or None
c_wchar_p wchar_t * unicode or None
c_void_p void * int/long or None

2. 注意编译生成 so库的命令要正确,包括include和library的配置