第一版踩了无数的坑,终于第二版把坑全添了,这次更新可以正常获取人脸数,角度,代码可读性更高,继续更新中

第三版已发出 https://www.cnblogs.com/wxt51/p/10125460.html

face_class.py
 from ctypes import *
#人脸框
class MRECT(Structure):
_fields_=[(u'left1',c_int32),(u'top1',c_int32),(u'right1',c_int32),(u'bottom1',c_int32)]
#版本信息 版本号,构建日期,版权说明
class ASF_VERSION(Structure):
_fields_=[('Version',c_char_p),('BuildDate',c_char_p),('CopyRight',c_char_p)]
#单人人脸信息 人脸狂,人脸角度
class ASF_SingleFaceInfo(Structure):
_fields_=[('faceRect',MRECT),('faceOrient',c_int32)]
#多人人脸信息 人脸框数组,人脸角度数组,人脸数
class ASF_MultiFaceInfo(Structure):
# _fields_=[('faceRect',POINTER(MRECT)),('faceOrient',POINTER( c_int32)),('faceNum',c_int32)]
_fields_=[(u'faceRect',POINTER(MRECT)),(u'faceOrient',POINTER(c_int32)),(u'faceNum', c_int32)]
# _fields_=[(u'faceRect',MRECT*50),(u'faceOrient',c_int32*50),(u'faceNum',c_int32)]
#人脸特征 人脸特征,人脸特征长度
class ASF_FaceFeature(Structure):
_fields_=[('feature',c_void_p),('featureSize',c_int32)]
#自定义图片类
class IM:
def __init__(self):
self.filepath=None
self.date=None
self.width=0
self.height=0
face_dll.py
 from ctypes import *
from face_class import *
wuyongdll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face.dll')
dll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face_engine.dll')
ASF_DETECT_MODE_VIDEO = 0x00000000
ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF
c_ubyte_p = POINTER(c_ubyte)
#激活
jihuo=dll.ASFActivation
jihuo.restype = c_int32
jihuo.argtypes = (c_char_p,c_char_p)
#初始化
chushihua=dll.ASFInitEngine
chushihua.restype=c_int32
chushihua.argtypes=(c_long,c_int32,c_int32,c_int32,c_int32,POINTER(c_void_p))
#人脸识别
shibie=dll.ASFDetectFaces
shibie.restype=c_int32
shibie.argtypes=(c_void_p,c_int32,c_int32,c_int32,POINTER(c_ubyte),POINTER(ASF_MultiFaceInfo))

main.py

 import face_dll,face_class
from ctypes import *
import cv2
Appkey=b''
SDKey=b''
Handle=c_void_p() #全局句柄
c_ubyte_p = POINTER(c_ubyte)
# 激活函数
def JH():
ret=face_dll.jihuo(Appkey,SDKey)
return ret
# 初始化函数
def CSH():# 1:视频或图片模式,2角度,3最小人脸尺寸推荐16,4最多人脸数最大50,5功能,6返回激活句柄
ret=face_dll.chushihua(0xFFFFFFFF,0x1,16,50,5,byref(Handle))
return ret
# cv2记载图片并处理
def LoadImg(im):
img=cv2.imread(im.filepath)
sp=img.shape
img=cv2.resize(img,(sp[1]//4*4,sp[0]//4*4))
sp=img.shape
im.data=img
im.width=sp[1]
im.height=sp[0]
return im
def RLSB(im):
faces=face_class.ASF_MultiFaceInfo()
img=im.data
imgby=bytes(im.data)
imgcuby=cast(imgby,c_ubyte_p)
ret=face_dll.shibie(Handle,im.width,im.height,0x201,imgcuby,byref(faces))
# print('ret',faces.faceNum)
# for i in range(0,faces.faceNum):
# rr=faces.faceRect[i]
# print('range',rr.left1)
# print('jd',faces.faceOrient[i])
if ret==0:
return faces
else:
return ret
# 激活
ret=JH()
if ret==0 or ret==90114:
print('激活成功:',ret)
else:
print('激活失败:',ret)
pass
# 初始化
ret=CSH()
if ret==0:
print('初始化成功:',ret,'句柄',Handle)
else:
print('初始化失败:',ret)
# 显示人脸识别图片
def showimg(im,faces):
for i in range(0,faces.faceNum):
ra=faces.faceRect[i]
cv2.rectangle(im.data,(ra.left1,ra.top1),(ra.right1,ra.bottom1),(255,0,0,),2)
cv2.imshow('faces',im.data)
cv2.waitKey(0)
# 加载图片
im=face_class.IM()
im.filepath='e:/4.jpg'
im=LoadImg(im)
print(im.filepath,im.width,im.height)
# cv2.imshow('im',im.data)
# cv2.waitKey(0)
print('加载图片完成:',im) ret=RLSB(im)
if ret==-1:
print('人脸识别失败:',ret)
pass
else:
print('人脸识别成功:',ret)
# 显示人脸照片
showimg(im,ret)

最新文章

  1. POJ3693 Maximum repetition substring [后缀数组 ST表]
  2. 源码安装mysql
  3. (C/C++) Interview in English. - Memory Allocation/Deallocation.
  4. 如何在Docker中部署DzzOffice
  5. android ROM备份和还原,再也不用当心刷到垃圾ROM,而还原不了原有系统
  6. jdbc 连接mysql Communications link failure的解决办法
  7. Android_Touch_Test
  8. 在eclipse中使用svn
  9. Docker: 限制容器可用的内存
  10. Zabbix实战-简易教程--技巧一(操作类技巧)
  11. Flume - Kafka日志平台整合
  12. JS 数组去重的几种方式
  13. SQL行转列与列转行(转)
  14. eslint常用关闭校验语句
  15. Java知多少(95)绘图基础
  16. 在VS2010中使用Git
  17. SCCM 2012 R2实战系列之十三:辅助站点部署
  18. 3D-爱心
  19. redis中的"HashMap"
  20. 快速排序——PowerShell版

热门文章

  1. Secure Sockets Layer(安全套接层)
  2. Node.js 入门资料
  3. [golang note] 流程控制
  4. json & pickle数据序列化
  5. android 带listview对话框
  6. python介绍和基础(待补充)
  7. iClap助力移动互联网企业高效实现规范化管理
  8. Spring-1-E Game(HDU 5011)解题报告及测试数据
  9. 你知道C语言为什么会有“_”(下划线)吗?
  10. 20145316《Java程序设计》实验一:Java开发环境的熟悉(Windows + IDEA)