找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2535|回复: 0

[求助] python调用dll返回多个值

1

主题

1

帖子

1

积分

贫民

积分
1
小鱼叉 发表于 2017-8-23 10:56:30 | 显示全部楼层 |阅读模式
import scipy.io as scio
import os
import ctypes
import datetime
import numpy as np

#读取dll文件
#这里的地址目录是HessianFilter.dll所在的文件夹
start = datetime.datetime.now()
cur_path = os.path.dirname(r'C:\Users\Administrator\Desktop\code_and_data\code\HessianFilter\\')
dll_path = os.path.join(cur_path,'HessianFilter.dll')
print dll_path
dll = ctypes.windll.LoadLibrary(dll_path)

#读取mat文件,Mat文件所在的文件夹中读取
matPath = r'C:\Users\Administrator\Desktop\code_and_data\data\Nodule19664.mat'
imgData = scio.loadmat(matPath)

#从mat文件中我们取到了整个三维数组
imgDataArray  = imgData['imagetest1']

#得到数组文件的参数:宽,高,层数
widthSrc,heightSrc,sliceNumSrc = imgDataArray.shape

#声明一个三维的c_float类型的数组,用于存放mat数据,并将数据转化为c_float
imgDataArray_p = (((ctypes.c_float*sliceNumSrc)*heightSrc)*widthSrc)()

for i in range(widthSrc):
    for j in range(heightSrc):
        for k in range(sliceNumSrc):
            imgDataArray_p[i][j][k] = ctypes.c_float(imgDataArray[i][j][k])

imgDataP = ctypes.POINTER(ctypes.c_float)(imgDataArray_p)
print '---------->'
#需要再声明两个返回值
HessianDot = (ctypes.c_float*(widthSrc*heightSrc*sliceNumSrc))()
HessianLine = (ctypes.c_float*(widthSrc*heightSrc*sliceNumSrc))()

HessianDot_p = ctypes.POINTER(ctypes.c_float)(HessianDot)
HessianLine_p = ctypes.POINTER(ctypes.c_float)(HessianLine)

#定义一个常数
sigma = ctypes.c_float(8)

#定义一个三维数组
imgSize = [widthSrc,heightSrc,sliceNumSrc]
imageSize = (ctypes.c_float*len(imgSize))(*imgSize)

#定义一个指向三维数组的指针
imageSizeP = ctypes.POINTER(ctypes.c_float)(imageSize)

#这个就是调用dll中的函数了
dll.RunHessianMultiThread(ctypes.byref(imgDataArray_p),sigma,ctypes.byref(imageSizeP),ctypes.byref(HessianDot_p),ctypes.byref(HessianLine_p),4)
print '--调用后-点数据--'
print HessianDot_p
print HessianDot_p[0:24]
#print HessianDot_p.contents
print '--调用后-线数据--'
print HessianLine_p
print HessianLine_p[0:24]
#print HessianLine_p.contents
print '<---------Over------------->\n\n'
print datetime.datetime.now()-start                           


这是dll中函数的声明

这是dll中函数的声明
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表