1. 程式人生 > >python調用虹軟2.0(全網首發)-更新中

python調用虹軟2.0(全網首發)-更新中

color 數組 需要 角度 ++ 加載 type 識別 vid

python調用虹軟2.0目前沒有任何demo可以參考,自己研究了2個晚上終於把第一步做出來了,使用了opencv來加載和顯示圖片,龜速更新中

 1 from ctypes import *
 2 #人臉框
 3 class MRECT(Structure):
 4     _fields_=[(uleft1,c_int32),(utop1,c_int32),(uright1,c_int32),(ubottom1,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_=[(ufaceRect,MRECT*50),(ufaceOrient,c_int32*50),(ufaceNum,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.ASFActivation
14 #激活函數返回0,初始化成功,返回90114已激活,其他則為失敗 ,重新激活需刪除asf_install.dat 文件
15 ret=Facedll.ASFActivation(Appkey,SDKey)
16 print(激活:,ret)
17 #初始化引擎
18 ASF_OP_0_ONLY = 0x1
19 ASF_DETECT_MODE_VIDEO = 0x00000000
20 ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF
21 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 = 0x601
28 ASVL_PAF_RGB24_B8G8R8 = 0x201
29 img1=cv2.imread(e:/5.jpg)
30 sp=img1.shape
31 #調整圖片大小,正好是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.shape
37 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.contents
54     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(全網首發)-更新中