我试图使用pyueye库来运行ML摄像头,但遇到了ctypes的问题。有一个函数需要一个类型为“ctypes instance”的参数,尽管尝试了所有可能的变体,但我仍然不知道如何使用ctypes库生成这个参数。此库中没有python文档,但我尝试使用的函数的C文档是:
Syntax
INT is_SetAutoParameter (HIDS hCam, INT param, double* pval1, double* pval2)
Example 1
//Enable auto gain control:
double dEnable = 1;
int ret = is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_GAIN, &dEnable, 0);
我在python中收到的代码和后续错误是:
nRet = ueye.is_SetAutoParameter(hCam, ueye.IS_SET_ENABLE_AUTO_GAIN, ctypes.byref(ctypes.c_long(1)), ctypes.byref(ctypes.c_long(0)))
Error:
ret = _is_SetAutoParameter(_hCam, _param, ctypes.byref(pval1), ctypes.byref(pval2))
TypeError: byref() argument must be a ctypes instance, not 'CArgObject'
关于ctypes实例有什么建议吗?谢谢
编辑:最小可复制示例
from pyueye import ueye
import ctypes
class Turfcam:
def main(self):
turfcam.take_photo()
def take_photo(self):
hCam = ueye.HIDS(0)
pval1 = ctypes.c_double(1)
pval2 = ctypes.c_double(0)
nRet = ueye.is_SetAutoParameter(hCam, ueye.IS_SET_ENABLE_AUTO_GAIN, ctypes.byref(pval1), ctypes.byref(pval2))
# Camera Init
nRet = ueye.is_InitCamera(hCam, None)
if __name__ == "__main__":
turfcam = Turfcam()
turfcam.main()
pyueye
库有一些最基本的文档:包装器正在执行
byref
,因此只需要传递ctypes
对象。uEye docs表示参数可以是输入或输出参数,因此始终创建c_double
对象,并根据传递的函数的需要初始化它们。请注意,对于输出参数,必须为对象指定一个名称,以便它在要查询的调用之后存在。输入参数可以直接将ctypes.c_double(value)
传递给函数,但为了一致性,我总是为对象指定名称:例如:
相关问题 更多 >
编程相关推荐