Python —— ctypes, call dynamic library: pit record

Official document: https://docs.python.org/zh-cn/3/library/ctypes.html

ctypes defines some basic data types compatible with C

Insert picture description here

Step on the pit 1:

sheetDeteInterface.h

// define
char* detectSheet(const char* imagePath, bool flag, const double angle=0.0);

python call (error example)

from ctypes import *
from ctypes import cdll

solib = cdll.LoadLibrary(so_path)
solib.detectSheet(c_char_p(image_path.encode('utf-8')), c_bool(flag), angle=c_double(angle))

python call (correct example)

from ctypes import *
from ctypes import cdll

solib = cdll.LoadLibrary(so_path)
solib.detectSheet(c_char_p(image_path.encode('utf-8')), c_bool(flag), c_double(angle))

Because when calling the function, the keyword of python syntax is used to pass parameters, so the value corresponding to angle is not passed into the dynamic library, but the program does not report an error, so I searched for it for a long time.

Therefore, you cannot use python keywords to pass parameters when calling dynamic library functions.

Guess you like

Origin blog.csdn.net/m0_38007695/article/details/112655696