Win10 64位,python3.5, 用ctypes调用DLL,读取摄像头,存为numpy数据格式. 40C

Win10 64位,python3.5, 用ctypes调用MVCAMSDK_X64.DLL,读取mindvision的摄像头,生成jpg图像,存为numpy数据格式,求完整python代码。以下运行到Cameraplay出错,以下对应C的原形:

typedef int CameraHandle;

原型:
MVSDK_API CameraSdkStatus
CameraSdkInit
(
int iLanguageSel
);
MVSDK_API CameraSdkStatus
CameraInit
(
tSdkCameraDevInfo* pCameraInfo,
int emParamLoadMode,
int emTeam,
CameraHandle* pCameraHandle
);
MVSDK_API CameraSdkStatus
CameraPlay
(
CameraHandle hCamera
);
MVSDK_API CameraSdkStatus
CameraEnumerateDevice
(
tSdkCameraDevInfo *pDSCameraList,
INT *piNums
);

以下为python 代码;
from ctypes import *
import numpy as np
from ctypes.wintypes import *

mylib=cdll.LoadLibrary('C:\Program Files (x86)\MindVision\SDK\X64\MVCAMSDK_X64.DLL')
hand=HANDLE()

i = c_int(1)
t=c_int(-1)
s=c_int(1)
class tSdkCameraDevInfo(Structure):
    _fields_ = [('uVendorID', c_uint),
            ('uProductID', c_uint),
            ('acVendorName',c_char),
            ('acProductSeries',c_char),
            ('acProductName',c_char),
            ('acFriendlyName',c_char),
            ('acDevFileName',c_char),
            ('acFirmwareVersion',c_char),
            ('acSensorType',c_char),
            ('acPortType',c_char)]

pi=pointer(i)
ti=pointer(t)
p_i=POINTER(c_int)
p_p_i=p_i(i)
pii=create_string_buffer(2)
piii = create_unicode_buffer(2)
cInfor=tSdkCameraDevInfo()

l=mylib.CameraSdkInit(1)
pp = create_unicode_buffer(4)
j=mylib.CameraEnumerateDevice(byref(cInfor),pi)
mylib.CameraInitEx.argtypes=(c_int,c_int,c_int)
k = mylib.CameraInit(byref(cInfor), -1, -1, byref(hand))
g=mylib.Cameraplay(hand)  ####这里出错了

print(l)
print(j)
print(k)
print(hand)

2个回答

g=mylib.Cameraplay(hand)
这行代码就是调用摄像头,你看下上一行k返回了什么,是不是摄像头没有正确初始化,没有安装好,或者被别的程序占用了。

k返回是0,表示初始化成功,但我不清楚是不是hand 的用法是不是有问题,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐