python怎样调用opencv库_python人脸检测之调用于老师公开的动态链接库。

经过多天学习,终于了解了python如何调用于老师提供的人脸检测动态库,感觉检测速度很快,CPU占用率在50%左右(09年的神舟笔记本),本着开源的精神,与大家坦诚交流的态度,现将源码放出,一起学习,不足之处多指正。

---------------------------------------------------------------------------帅气的分割线---------------------------------------------------------------------------------

def detectFaceC(image):

# 调用Dll动态链接库

import ctypes

DETECT_BUFFER_SIZE = 0x20000 # 设置缓存大小

sBuf = b'a'*DETECT_BUFFER_SIZE # 设置缓存,用于存储识别数据

pStr = ctypes.cast(sBuf, ctypes.POINTER(ctypes.c_short)) # 缓存指针,用于读取缓存数据

dll = ctypes.CDLL('libfacedetect.dll') # 调用脸部识别动太链接库

# 动态链接库功能调用方法,有三种:1. dll.funname() 2. fun=getattr(dll, '?funname@HYY***@@Z') 3. dll[num]

# 不同库可能调用的方法不一样,下面是这个库的调用方法。

# facedetect_front = dll[1] # 脸检测, 无检测角度

# facedetect_frontal_surveillance = dll[2] # 暗光线下检测,无检测角度

# facedetect_multiview = dll[3] # 脸部角度检测

# facedetect_multiview_reinforce = dll[4] # 加强版脸部角度检测

imggray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

row, col = imggray.shape[:2]

doLandmark = 1

result = dll[1](sBuf, imggray.ctypes.data, col, row, col, ctypes.c_float(1.2), 2, 48, 0, doLandmark)

for i in range(pStr[0]):

p = 2 + 142*i

# 显示脸部坐标,neighbors,angle

print('x1:',pStr[p], 'y1:', pStr[p+1], 'x2:', pStr[p]+pStr[p+2], 'y2:', pStr[p+1]+pStr[p+3], 'neighbors:', pStr[p+4], 'angle:', pStr[p+5])

cv2.rectangle(image, (pStr[p], pStr[p+1]), (pStr[p]+pStr[p+2], pStr[p+1]+pStr[p+3]), (0,0,255), 2)

if doLandmark:

for j in range(68):

# circle(result_frontal, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 255, 0))

cv2.circle(image, (pStr[p+6+2*j], pStr[p+6+2*j+1]), 2, (0,255,0))

return image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值