python3+虹软2.0的所有功能整合测试完成,并对虹软所有功能进行了封装,现提供demo
主要功能,
1.人脸识别
2.人脸特征提取
3.特征比对
4.特征数据存储与比对
其他特征没有添加

虹软SDK下载戳这里

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.msvcrt
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))
#特征提取
tezheng=dll.ASFFaceFeatureExtract
tezheng.restype=c_int32
tezheng.argtypes=(c_void_p,c_int32,c_int32,c_int32,POINTER(c_ubyte),POINTER(ASF_SingleFaceInfo),POINTER(ASF_FaceFeature)) #特征比对
bidui=dll.ASFFaceFeatureCompare
bidui.restype=c_int32
bidui.argtypes=(c_void_p,POINTER(ASF_FaceFeature),POINTER(ASF_FaceFeature),POINTER(c_float))
malloc = dllc.malloc
free = dllc.free
memcpy = dllc.memcpy malloc.restype = c_void_p
malloc.argtypes = (c_size_t, )
free.restype = None
free.argtypes = (c_void_p, )
memcpy.restype = c_void_p
memcpy.argtypes = (c_void_p, c_void_p, c_size_t)

face_function.py


import face_dll,face_class
from ctypes import *
import cv2
from 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 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))
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

Main1.py


import face_dll,face_class
from ctypes import *
import cv2
import face_function as fun
Appkey=b''
SDKey=b''
# 激活
ret=fun.JH(Appkey,SDKey)
if ret==0 or ret==90114:
print('激活成功:',ret)
else:
print('激活失败:',ret)
pass
# 初始化
ret=fun.CSH()
if ret[0]==0:
print('初始化成功:',ret,'句柄',fun.Handle)
else:
print('初始化失败:',ret)
# 加载图片
im=face_class.IM()
im.filepath='e:/2.jpg'
im=fun.LoadImg(im)
print(im.filepath,im.width,im.height)
# cv2.imshow('im',im.data)
# cv2.waitKey(0)
print('加载图片完成:',im) ret=fun.RLSB(im)
if ret[0]==-1:
print('人脸识别失败:',ret)
pass
else:
print('人脸识别成功:',ret)
# 显示人脸照片
# showimg(im,ret)
#提取单人1特征
ft=fun.getsingleface(ret[1],0)
tz1=fun.RLTZ(im,ft)[1]
#提取单人2特征
ft=fun.getsingleface(ret[1],1)
tz2=fun.RLTZ(im,ft)[1]
#特征保存到文件
# fun.writeFTFile(tz1,'d:/1.dat')
# fun.writeFTFile(tz2,'d:/2.dat')
#文件获取特征
tz=fun.ftfromfile('d:/1.dat')
jg=fun.BD(tz1,tz)
print(jg[1])
#结果比对
# jg=fun.BD(tz1,tz2)
# print(jg[1])

 

python3+虹软2.0 离线人脸识别 demo的更多相关文章

  1. python3+arcface2.0 离线人脸识别 demo

    python3+虹软2.0的所有功能整合测试完成,并对虹软所有功能进行了封装,现提供demo主要功能,1.人脸识别2.人脸特征提取3.特征比对4.特征数据存储与比对其他特征没有添加 sdk 下载请戳这 ...

  2. 虹软2.0 离线人脸识别 Android 开发 Demo

    环境要求1.运行环境 armeabi-v7a2.系统要求 Android 5.0 (API Level 21)及以上3.开发环境 Android Studio 下载地址:https://github. ...

  3. 虹软2.0免费离线人脸识别 Demo [C++]

    环境: win10(10.0.16299.0)+ VS2017 sdk版本:ArcFace v2.0 OPENCV3.43版本 x64平台Debug.Release配置都已通过编译 下载地址:http ...

  4. C# 离线人脸识别Demo 使用ArcFace 2.0开发完成

    环境:     win7以上  VS2013以上    sdk版本:ArcFace v2.0    x86 x64平台Debug.Release配置都已通过编译 下载地址:https://github ...

  5. 【C#】 基于ArcFace 2.0—视频人脸识别Demo

    使用的虹软人脸识别技术 啥话不说,不用跪求,直接给下载地址:http://common.tenzont.com/comdll/arcface2demo.zip(话说附件的大小不限制,还是说我的文件太大 ...

  6. 虹软2.0 免费人脸识别C#类库分享

    目前只封装了人脸检测部分的类库,供大家交流学习,肯定有问题,希望大家在阅读使用的时候及时反馈,谢谢!使用虹软技术开发完成 戳这里下载SDKgithub:https://github.com/dayAn ...

  7. 人脸识别demo使用教程

    最近在研究虹软家的arcface 人脸识别 demo,现在就给大家分享一下官方的demo**工程如何使用? **1.下载代码:git clone https://github.com/asdfqwra ...

  8. 离线人脸识别 ArcFaceSharp -- ArcFace 2.0 SDK C#封装库分享

    ArcFaceSharp ArcFaceSharp 是ArcSoft 虹软 ArcFace 2.0 SDK 的一个 C# 封装库,为方便进行 C# 开发而封装.欢迎 Start & Fork. ...

  9. 人脸识别Demo解析C#

    概述 不管你注意到没有,人脸识别已经走进了生活的角角落落,钉钉已经支持人脸打卡,火车站实名认证已经增加了人脸自助验证通道,更别提各个城市建设的『智能城市』和智慧大脑了.在人脸识别业界,通常由人脸识别提 ...

随机推荐

  1. Docker学习笔记之Docker的数据管理和存储

    0x00 概述 数据是应用程序重要的产出,所以很好的管理和存储数据,是对应用程序劳动结果的尊重.特别是在大数据时代,所有的数据都是重要的资产,保护好数据是每个开发者必须掌握的技能.我们知道,在 Doc ...

  2. Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式

    代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...

  3. dubbo spring pom文件报错:提示no declaration can be found for element 'dubbo:service'.

    pom文件报错:The matching wildcard is strict, but no declaration can be found for  element 'dubbo:service ...

  4. How to Conduct High-Impact Research and Produce High-Quality Papers

    How to Conduct High-Impact Research and Produce High-Quality Papers Contents From Slide Russell Grou ...

  5. Java基础——javaMail:使用心得

    想要做一个java发送邮件小功能. 使用的maven搭建的项目. <!-- https://mvnrepository.com/artifact/javax.mail/mail -->&l ...

  6. 什么是TF-A?

    1. TF-A的全称是什么? Arm Trusted Firmware 2. TF-A的作用是什么? 在secure world和non-secure world之间切换 3. TF-A涉及到哪几个部 ...

  7. 因为强行关机, 而导致的fedora23 不能重新启动, 卡在开机logo那里的 修复 解决方案

    其实, fedora23的U盘live 也很好用, 很流畅, 主要还是 要用一个比较好的/快的 U盘. 这样live U盘在4GB(3.75GiB)的内存中还是较快的 原来的U盘live系统用得很卡, ...

  8. dp小结|背包问题

    1.先放上0-1背包模板 二维数组 for(int i=1;i<=n;i++)//枚举 物品 for(int j=1;j<=V;j++)//枚举体积 //这个位置是可以正序枚举的. qwq ...

  9. 3. Elements of a Test Plan

    https://jmeter.apache.org/usermanual/test_plan.html This section describes the different parts of a ...

  10. (转载)MySQl数据库-批量添加数据的两种方法

    方法一:使用excel表格 方法二:使用insert语句(FileWriter批量写入) 使用excel表格 1.打开数据表,按照表的字段在excel中添加数据.注意:表中字段名必须和excel中的名 ...