国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python調用虹軟2.0第三版的具體使用

2020-02-16 01:20:33
字體:
來源:轉載
供稿:網友

這一版,對虹軟的功能進行了一些封裝,添加了人臉特征比對,比對結果保存到文件,和從文件提取特征進行比對,大體功能基本都已經實現,可以進行下一步的應用開發了

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')dllc=cdll.msvcrtASF_DETECT_MODE_VIDEO = 0x00000000ASF_DETECT_MODE_IMAGE = 0xFFFFFFFFc_ubyte_p = POINTER(c_ubyte) #激活jihuo=dll.ASFActivationjihuo.restype = c_int32jihuo.argtypes = (c_char_p,c_char_p)#初始化chushihua=dll.ASFInitEnginechushihua.restype=c_int32chushihua.argtypes=(c_long,c_int32,c_int32,c_int32,c_int32,POINTER(c_void_p))#人臉識別shibie=dll.ASFDetectFacesshibie.restype=c_int32shibie.argtypes=(c_void_p,c_int32,c_int32,c_int32,POINTER(c_ubyte),POINTER(ASF_MultiFaceInfo))#特征提取tezheng=dll.ASFFaceFeatureExtracttezheng.restype=c_int32tezheng.argtypes=(c_void_p,c_int32,c_int32,c_int32,POINTER(c_ubyte),POINTER(ASF_SingleFaceInfo),POINTER(ASF_FaceFeature))#特征比對bidui=dll.ASFFaceFeatureComparebidui.restype=c_int32bidui.argtypes=(c_void_p,POINTER(ASF_FaceFeature),POINTER(ASF_FaceFeature),POINTER(c_float))malloc = dllc.mallocfree = dllc.freememcpy = dllc.memcpymalloc.restype = c_void_pmalloc.argtypes = (c_size_t, )free.restype = Nonefree.argtypes = (c_void_p, )memcpy.restype = c_void_pmemcpy.argtypes = (c_void_p, c_void_p, c_size_t)

face_function.py

import face_dll,face_classfrom ctypes import *import cv2from io import BytesIO# from Main import *Handle=c_void_p()c_ubyte_p = POINTER(c_ubyte) # 激活函數def JH(appkey,sdkey):  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))  # Main.Handle=Handle  return ret,Handle# 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 imdef 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))  return ret,faces# 顯示人臉識別圖片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)#提取人臉特征def RLTZ(im,ft):  detectedFaces=face_class.ASF_FaceFeature()  img=im.data  imgby=bytes(im.data)  imgcuby=cast(imgby,c_ubyte_p)  ret=face_dll.tezheng(Handle,im.width,im.height,0x201,imgcuby,ft,byref(detectedFaces))  if ret==0:    retz=face_class.ASF_FaceFeature()    retz.featureSize=detectedFaces.featureSize    #必須操作內存來保留特征值,因為c++會在過程結束后自動釋放內存    retz.feature=face_dll.malloc(detectedFaces.featureSize)    face_dll.memcpy(retz.feature,detectedFaces.feature,detectedFaces.featureSize)    # print('提取特征成功:',detectedFaces.featureSize,mem)    return ret,retz  else:    return ret#特征值比對,返回比對結果def BD(tz1,tz2):  jg=c_float()  ret=face_dll.bidui(Handle,tz1,tz2,byref(jg))  return ret,jg.value#單人特征寫入文件def writeFTFile(feature,filepath):  f = BytesIO(string_at(feature.feature,feature.featureSize))  a=open(filepath,'wb')  a.write(f.getvalue())  a.close()#從多人中提取單人數據def getsingleface(singleface,index):  ft=face_class.ASF_SingleFaceInfo()  ra=singleface.faceRect[index]  ft.faceRect.left1=ra.left1  ft.faceRect.right1=ra.right1  ft.faceRect.top1=ra.top1  ft.faceRect.bottom1=ra.bottom1  ft.faceOrient=singleface.faceOrient[index]  return ft#從文件獲取特征值def ftfromfile(filepath):  fas=face_class.ASF_FaceFeature()  f=open('d:/1.dat','rb')  b=f.read()  f.close()  fas.featureSize=b.__len__()  fas.feature=face_dll.malloc(fas.featureSize)  face_dll.memcpy(fas.feature,b,fas.featureSize)  return fas            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石棉县| 康保县| 鹤岗市| 廉江市| 迭部县| 河西区| 根河市| 海阳市| 蒲城县| 桦南县| 敦化市| 天镇县| 泽普县| 合川市| 孝义市| 仁布县| 哈巴河县| 疏附县| 神木县| 三明市| 蕲春县| 瑞丽市| 涟源市| 黎城县| 开阳县| 伊川县| 醴陵市| 永善县| 盐城市| 娱乐| 龙陵县| 志丹县| 宜城市| 巢湖市| 浮梁县| 沧源| 五华县| 宣城市| 财经| 望谟县| 平定县|