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

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

face_class.py
 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',POINTER(MRECT)),(u'faceOrient',POINTER(c_int32)),(u'faceNum', c_int32)]
15 # _fields_=[(u'faceRect',MRECT*50),(u'faceOrient',c_int32*50),(u'faceNum',c_int32)]
16 #人脸特征 人脸特征,人脸特征长度
17 class ASF_FaceFeature(Structure):
18 _fields_=[('feature',c_void_p),('featureSize',c_int32)]
19 #自定义图片类
20 class IM:
21 def __init__(self):
22 self.filepath=None
23 self.date=None
24 self.width=0
25 self.height=0

  face_dll.py

 1 from ctypes import *
2 from face_class import *
3 wuyongdll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face.dll')
4 dll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face_engine.dll')
5 ASF_DETECT_MODE_VIDEO = 0x00000000
6 ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF
7 c_ubyte_p = POINTER(c_ubyte)
8 #激活
9 jihuo=dll.ASFActivation
10 jihuo.restype = c_int32
11 jihuo.argtypes = (c_char_p,c_char_p)
12 #初始化
13 chushihua=dll.ASFInitEngine
14 chushihua.restype=c_int32
15 chushihua.argtypes=(c_long,c_int32,c_int32,c_int32,c_int32,POINTER(c_void_p))
16 #人脸识别
17 shibie=dll.ASFDetectFaces
18 shibie.restype=c_int32
19 shibie.argtypes=(c_void_p,c_int32,c_int32,c_int32,POINTER(c_ubyte),POINTER(ASF_MultiFaceInfo))

  main.py

1 import face_dll,face_class
2 from ctypes import *
3 import cv2
4 Appkey=b''
5 SDKey=b''
6 Handle=c_void_p() #全局句柄
7 c_ubyte_p = POINTER(c_ubyte)
8 # 激活函数
9 def JH():
10 ret=face_dll.jihuo(Appkey,SDKey)
11 return ret
12 # 初始化函数
13 def CSH():# 1:视频或图片模式,2角度,3最小人脸尺寸推荐16,4最多人脸数最大50,5功能,6返回激活句柄
14 ret=face_dll.chushihua(0xFFFFFFFF,0x1,16,50,5,byref(Handle))
15 return ret
16 # cv2记载图片并处理
17 def LoadImg(im):
18 img=cv2.imread(im.filepath)
19 sp=img.shape
20 img=cv2.resize(img,(sp[1]//4*4,sp[0]//4*4))
21 sp=img.shape
22 im.data=img
23 im.width=sp[1]
24 im.height=sp[0]
25 return im
26 def RLSB(im):
27 faces=face_class.ASF_MultiFaceInfo()
28 img=im.data
29 imgby=bytes(im.data)
30 imgcuby=cast(imgby,c_ubyte_p)
31 ret=face_dll.shibie(Handle,im.width,im.height,0x201,imgcuby,byref(faces))
32 # print('ret',faces.faceNum)
33 # for i in range(0,faces.faceNum):
34 # rr=faces.faceRect[i]
35 # print('range',rr.left1)
36 # print('jd',faces.faceOrient[i])
37 if ret==0:
38 return faces
39 else:
40 return ret
41 # 激活
42 ret=JH()
43 if ret==0 or ret==90114:
44 print('激活成功:',ret)
45 else:
46 print('激活失败:',ret)
47 pass
48 # 初始化
49 ret=CSH()
50 if ret==0:
51 print('初始化成功:',ret,'句柄',Handle)
52 else:
53 print('初始化失败:',ret)
54 # 显示人脸识别图片
55 def showimg(im,faces):
56 for i in range(0,faces.faceNum):
57 ra=faces.faceRect[i]
58 cv2.rectangle(im.data,(ra.left1,ra.top1),(ra.right1,ra.bottom1),(255,0,0,),2)
59 cv2.imshow('faces',im.data)
60 cv2.waitKey(0)
61 # 加载图片
62 im=face_class.IM()
63 im.filepath='e:/4.jpg'
64 im=LoadImg(im)
65 print(im.filepath,im.width,im.height)
66 # cv2.imshow('im',im.data)
67 # cv2.waitKey(0)
68 print('加载图片完成:',im)
69
70 ret=RLSB(im)
71 if ret==-1:
72 print('人脸识别失败:',ret)
73 pass
74 else:
75 print('人脸识别成功:',ret)
76 # 显示人脸照片
77 showimg(im,ret)

  

python调用虹软2.0的更多相关文章

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

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

  2. python调用虹软2.0第三版

    这一版,对虹软的功能进行了一些封装,添加了人脸特征比对,比对结果保存到文件,和从文件提取特征进行比对,大体功能基本都已经实现,可以进行下一步的应用开发了 face_class.py from ctyp ...

  3. python调用虹软2.0第二版

    第一版踩了无数的坑,终于第二版把坑全添了,这次更新可以正常获取人脸数,角度,代码可读性更高,继续更新中 第三版已发出 https://www.cnblogs.com/wxt51/p/10125460. ...

  4. 【初学python】使用python调用monkey测试

    目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下: import os apk = {'j': 'com.***.test1 ...

  5. python调用py中rar的路径问题。

    1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...

  6. python调用其他程序或脚本方法(转)

    python运行(调用)其他程序或脚本 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地 ...

  7. python调用c\c++

    前言 python 这门语言,凭借着其极高的易学易用易读性和丰富的扩展带来的学习友好性和项目友好性,近年来迅速成为了越来越多的人们的首选.然而一旦拿python与传统的编程语言(C/C++)如来比较的 ...

  8. python调用zabbix接口实现Action配置

    要写这篇博客其实我的内心是纠结的,老实说,我对zabbix的了解实在不多.但新公司的需求不容置疑,当我顶着有两个头大的脑袋懵懵转入运维领域时,面前摆着两百多组.上千台机器等着写入zabbix监控的需求 ...

  9. python调用ggsci.exe程序

    需求:通过python调用windows server 2008下的ogg同步程序,实现图形化控制. 简单GUI

随机推荐

  1. django 正向,反向

    表名 ,foreignkey, 正向 obj.表名小写_set.all() 反向操作.

  2. window bat 运行 cmd 命令

    新建一个.bat批处理文件,编写以下切换目录 并且执行 ipconfig 命令: cmd /k "cd /d D:phpStudy/WWW & ipconfig" cmd ...

  3. 详解centos6和centos7防火墙

    CentOS6.5查看防火墙的状态: ? 1 [zh@localhost ~]$service iptable status 显示结果: ? 1 2 3 4 5 6 7 8 9 [zh@localho ...

  4. 翻译 Improved Word Representation Learning with Sememes

    翻译 Improved Word Representation Learning with Sememes 题目 Improved Word Representation Learning with ...

  5. poj 3744 Scout (Another) YYF I - 概率与期望 - 动态规划 - 矩阵快速幂

      (Another) YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into th ...

  6. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  7. Jbarcode 条形码生成工具

    一.准备jar包 https://sourceforge.net/projects/jbcode/?source=typ_redirect 二.编写工具类 package com.example.de ...

  8. Node.js实践

    在 iOS 模拟器中调试 Web 页面 safari调试iOS App web 1, npm init 2, npm install ejs --save 简单Node 指令 $ node -v  / ...

  9. ODAC(V9.5.15) 学习笔记(六)TOraSQL、TOraTable和TOraStoredProc

    TOraSQL是一个SQL语句执行控件,包括PL/SQL块等,不返回数据集结果. 名称 类型 说明 ChangeCursor Boolean 在非阻塞模式下是否允许改变屏幕的光标 WaitExecut ...

  10. 最最简单的c语言函数汇编分析

    0x01 环境 xp+vc6.0 0x02 代码 int plus(int x, int y) { return 0; } 以下是vc6.0的反汇编窗口 1: int plus(int x, int ...