python调用虹软2.0(全网首发)-更新中,,python调用虹软


python调用虹软2.0目前没有任何demo可以参考,自己研究了2个晚上终于把第一步做出来了,使用了opencv来加载和显示图片,龟速更新中

 1 from ctypes import * 2 #人脸框 3 class MRECT(Structure): 4     _fields_=[(u‘left1‘,c_int32),(u‘top1‘,c_int32),(u‘right1‘,c_int32),(u‘bottom1‘,c_int32)] 5 #版本信息     版本号,构建日期,版权说明 6 class ASF_VERSION(Structure): 7     _fields_=[(‘Version‘,c_char_p),(‘BuildDate‘,c_char_p),(‘CopyRight‘,c_char_p)] 8 #单人人脸信息  人脸狂,人脸角度 9 class ASF_SingleFaceInfo(Structure):10     _fields_=[(‘faceRect‘,MRECT),(‘faceOrient‘,c_int32)]11 #多人人脸信息 人脸框数组,人脸角度数组,人脸数12 class ASF_MultiFaceInfo(Structure):13     # _fields_=[(‘faceRect‘,POINTER(MRECT)),(‘faceOrient‘,POINTER( c_int32)),(‘faceNum‘,c_int32)]14     _fields_=[(u‘faceRect‘,MRECT*50),(u‘faceOrient‘,c_int32*50),(u‘faceNum‘,c_int32)]15 #人脸特征 人脸特征,人脸特征长度16 class ASF_FaceFeature(Structure):17     _fields_=[(‘feature‘,c_byte),(‘featureSize‘,c_int32)]18 #年龄信息 0=未知 >0则检测出年龄 ,人脸数19 class ASF_AgeInfo(Structure):20     _fields_=[(‘ageArray‘,c_int32),(‘num‘,c_int32)]21 #性别 0=男 1=女 -1未知,人脸数22 class ASF_GenderInfo(Structure):23     _fields_=[(‘genderArray‘,c_int32),(‘num‘,c_int32)]
 1 #调用dll需要引入ctypes 2 from ctypes import * 3 from face_class import * 4 import io 5 from PIL import Image 6 import cv2 7 dll=CDLL(‘d:\python\Test\Face\lib\X64\libarcsoft_face.dll‘) 8 Facedll=CDLL(‘d:\python\Test\Face\lib\X64\libarcsoft_face_engine.dll‘) 9 #由于dll是c,所以字符串要做类型转换,否则,激活失败,APPID无效10 Appkey=c_char_p(b‘自己去注册‘)11 SDKey=c_char_p(b‘自己去注册‘)12 # ASF_VERSION a=Facedll.ASFActiviation(Appkey,SDKey)13 vs=Facedll.ASFActivation14 #激活函数返回0,初始化成功,返回90114已激活,其他则为失败 ,重新激活需删除asf_install.dat 文件15 ret=Facedll.ASFActivation(Appkey,SDKey)16 print(‘激活:‘,ret)17 #初始化引擎18 ASF_OP_0_ONLY = 0x119 ASF_DETECT_MODE_VIDEO = 0x0000000020 ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF21 r=c_void_p()22 #初始化引擎23 a=Facedll.ASFInitEngine(c_long(ASF_DETECT_MODE_IMAGE),c_int32(ASF_OP_0_ONLY),c_int32(16),c_int32(50),c_int8(ASF_OP_0_ONLY),byref(r))24 print(‘初始化‘,a)25 print(‘初始化返回‘,r)26 c_ubyte_p = POINTER(c_ubyte) 27 ASVL_PAF_I420 = 0x60128 ASVL_PAF_RGB24_B8G8R8 = 0x20129 img1=cv2.imread(‘e:/5.jpg‘)30 sp=img1.shape31 #调整图片大小,正好是4的倍数,否则会报错32 img=cv2.resize(img1,(sp[1]//4*4,sp[0]//4*4))33 # img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV_I420)34 # img=cv2.cvtColor(img,cv2.COLOR_BGRA2YUV_I420)35 # img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV_IYUV)36 sp=img.shape37 wd=sp[1]38 he=sp[0]39 print(‘宽高‘,wd,he)40 # cv2.imshow(‘1‘,img)41 # cv2.waitKey(0)42 #内存指针返回ASF_MultiFaceInfo类型--回调函数43 tz=POINTER(ASF_MultiFaceInfo)()44 #图片转换成字字节45 b=bytes(img)46 #强转为C++的byte类型47 d=cast(b,c_ubyte_p)48 #调用多人人脸识别49 a=Facedll.ASFDetectFaces(r,c_int32(wd),c_int32(he),c_int32(ASVL_PAF_RGB24_B8G8R8),d,byref(tz))50 print(‘返回特征‘,tz)51 print(‘返回值‘,a)52 if a==0:53     tezheng=tz.contents54     print(tezheng.faceNum)55     for i in range(0,50):56         # cv2.rectangle(img,(tezheng.faceRect[1].left1,tezheng.faceRect[1].top1),(tezheng.faceRect[1].right1,tezheng.faceRect[1].bottom1),(255,0,0),2)57         cv2.rectangle(img,(tezheng.faceRect[i].left1,tezheng.faceRect[i].top1),(tezheng.faceRect[i].right1,tezheng.faceRect[i].bottom1),(255,0,0),2)58     cv2.imshow(‘1‘,img)59     cv2.waitKey(0)

python调用虹软2.0(全网首发)-更新中

评论关闭