Python-ctypes、ダイナミックライブラリの呼び出し:ピットレコード

公式ドキュメント:https//docs.python.org/zh-cn/3/library/ctypes.html

ctypesは、Cと互換性のあるいくつかの基本的なデータ型を定義します

ここに画像の説明を挿入

ピット1を踏む:

sheetDeteInterface.h

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

Python呼び出し(エラーの例)

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呼び出し(正しい例)

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))

関数を呼び出すときに、Python構文のキーワードを使用してパラメーターを渡すため、angleに対応する値はダイナミックライブラリに渡されませんが、プログラムはエラーを報告しないため、長い間検索しました。

したがって、動的ライブラリ関数を呼び出すときに、Pythonキーワードを使用してパラメータを渡すことはできません。

おすすめ

転載: blog.csdn.net/m0_38007695/article/details/112655696