提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.module; |
H |
2 |
|
|
3 |
import com.iailab.netsdk.lib.NetSDKLib; |
|
4 |
import com.iailab.netsdk.lib.ToolKits; |
|
5 |
import com.iailab.netsdk.lib.NetSDKLib.*; |
|
6 |
|
|
7 |
import com.sun.jna.Memory; |
|
8 |
import com.sun.jna.ptr.IntByReference; |
|
9 |
|
|
10 |
/** |
|
11 |
* 以图搜图接口实现,跟查询人脸库里的人员信息的查找接口是一样的,入参和实现有区别 |
|
12 |
* 目前只支持IVSS |
|
13 |
*/ |
|
14 |
public class SearchByPictureModule { |
|
15 |
// 查询密令 |
|
16 |
public static int nToken = 0; |
|
17 |
|
|
18 |
private static LLong m_FindHandle = null; |
|
19 |
|
|
20 |
// 订阅句柄 |
|
21 |
private static LLong attachFaceHandle = new LLong(0); |
|
22 |
|
|
23 |
/** |
|
24 |
* 按条件查询目标识别结果 |
|
25 |
* @param memory 图片缓存 |
|
26 |
* @param startTime 起始时间, 历史库需要时间,人脸库不需要时间 |
|
27 |
* @param endTime 结束时间, 历史库需要时间,人脸库不需要时间 |
|
28 |
* @param isHistory 是否是历史库, true-历史库; false-人脸库 |
|
29 |
* @param nChn 通道号, 历史库需要通道号,人脸库不需要通道号 |
|
30 |
* @param similary 相似度 |
|
31 |
* @return 查询到的所有人员个数 |
|
32 |
*/ |
|
33 |
public static int startFindPerson(Memory memory, |
|
34 |
String startTime, |
|
35 |
String endTime, |
|
36 |
boolean isHistory, |
|
37 |
int nChn, |
|
38 |
String similary) { |
|
39 |
|
|
40 |
m_FindHandle = null; |
|
41 |
nToken = 0; |
|
42 |
int nTotalCount = 0; |
|
43 |
|
|
44 |
/* |
|
45 |
* 入参, IVVS设备,查询条件只有 stuInStartFind.stPerson 里的参数有效 |
|
46 |
*/ |
|
47 |
NET_IN_STARTFIND_FACERECONGNITION stuIn = new NET_IN_STARTFIND_FACERECONGNITION(); |
|
48 |
|
|
49 |
// 人员信息查询条件是否有效, 并使用扩展结构体 |
|
50 |
stuIn.bPersonExEnable = 1; |
|
51 |
|
|
52 |
// 图片信息 |
|
53 |
if(memory != null) { |
|
54 |
stuIn.pBuffer = memory; |
|
55 |
stuIn.nBufferLen = (int)memory.size(); |
|
56 |
stuIn.stPersonInfoEx.wFacePicNum = 1; |
|
57 |
stuIn.stPersonInfoEx.szFacePicInfo[0].dwOffSet = 0; |
|
58 |
stuIn.stPersonInfoEx.szFacePicInfo[0].dwFileLenth = (int)memory.size(); |
|
59 |
} |
|
60 |
|
|
61 |
// 相似度 |
|
62 |
if(!similary.isEmpty()) { |
|
63 |
stuIn.stMatchOptions.nSimilarity = Integer.parseInt(similary); |
|
64 |
} |
|
65 |
|
|
66 |
stuIn.stFilterInfo.nGroupIdNum = 0; |
|
67 |
stuIn.stFilterInfo.nRangeNum = 1; |
|
68 |
|
|
69 |
if(isHistory) { // 历史库 |
|
70 |
// 通道号 |
|
71 |
stuIn.nChannelID = nChn; |
|
72 |
stuIn.stFilterInfo.szRange[0] = EM_FACE_DB_TYPE.NET_FACE_DB_TYPE_HISTORY; // 待查询数据库类型,设备只支持一个 |
|
73 |
// 开始时间 |
|
74 |
String[] startTimeStr = startTime.split("-"); |
|
75 |
stuIn.stFilterInfo.stStartTime.dwYear = Integer.parseInt(startTimeStr[0]); |
|
76 |
stuIn.stFilterInfo.stStartTime.dwMonth = Integer.parseInt(startTimeStr[1]); |
|
77 |
stuIn.stFilterInfo.stStartTime.dwDay = Integer.parseInt(startTimeStr[2]); |
|
78 |
stuIn.stFilterInfo.stStartTime.dwHour= 0; |
|
79 |
stuIn.stFilterInfo.stStartTime.dwMinute= 0; |
|
80 |
stuIn.stFilterInfo.stStartTime.dwSecond= 0; |
|
81 |
// 结束时间 |
|
82 |
String[] endTimeStr = endTime.split("-"); |
|
83 |
stuIn.stFilterInfo.stEndTime.dwYear = Integer.parseInt(endTimeStr[0]); |
|
84 |
stuIn.stFilterInfo.stEndTime.dwMonth = Integer.parseInt(endTimeStr[1]); |
|
85 |
stuIn.stFilterInfo.stEndTime.dwDay = Integer.parseInt(endTimeStr[2]); |
|
86 |
stuIn.stFilterInfo.stEndTime.dwHour=23; |
|
87 |
stuIn.stFilterInfo.stEndTime.dwMinute=59; |
|
88 |
stuIn.stFilterInfo.stEndTime.dwSecond=59; |
|
89 |
stuIn.stFilterInfo.emFaceType = EM_FACERECOGNITION_FACE_TYPE.EM_FACERECOGNITION_FACE_TYPE_ALL; |
|
90 |
} else { // 人脸库 |
|
91 |
stuIn.stFilterInfo.szRange[0] = EM_FACE_DB_TYPE.NET_FACE_DB_TYPE_BLACKLIST; // 待查询数据库类型,设备只支持一个 |
|
92 |
} |
|
93 |
|
|
94 |
/* |
|
95 |
* 出参 |
|
96 |
*/ |
|
97 |
NET_OUT_STARTFIND_FACERECONGNITION stuOut = new NET_OUT_STARTFIND_FACERECONGNITION(); |
|
98 |
stuIn.write(); |
|
99 |
stuOut.write(); |
|
100 |
if(LoginModule.netsdk.CLIENT_StartFindFaceRecognition(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000)) { |
|
101 |
m_FindHandle = stuOut.lFindHandle; |
|
102 |
nTotalCount = stuOut.nTotalCount; |
|
103 |
nToken = stuOut.nToken; |
|
104 |
} else { |
|
105 |
System.out.println("CLIENT_StartFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); |
|
106 |
} |
|
107 |
|
|
108 |
return nTotalCount; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* 查找目标识别结果 |
|
113 |
* @param beginNum 查询起始序号 |
|
114 |
* @param nCount 当前想查询的记录条数 |
|
115 |
* @return 返回的人员信息数组 |
|
116 |
*/ |
|
117 |
public static CANDIDATE_INFOEX[] doFindNextPerson(int beginNum, int nCount) { |
|
118 |
/* |
|
119 |
*入参 |
|
120 |
*/ |
|
121 |
NetSDKLib.NET_IN_DOFIND_FACERECONGNITION stuIn = new NetSDKLib.NET_IN_DOFIND_FACERECONGNITION(); |
|
122 |
stuIn.lFindHandle = m_FindHandle; |
|
123 |
stuIn.nCount = nCount; // 当前想查询的记录条数 |
|
124 |
stuIn.nBeginNum = beginNum; // 查询起始序号 |
|
125 |
|
|
126 |
/* |
|
127 |
* 出参 |
|
128 |
*/ |
|
129 |
NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION stuOut = new NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION();; |
|
130 |
stuOut.bUseCandidatesEx = 1; // 是否使用候选对象扩展结构体 |
|
131 |
|
|
132 |
// 必须申请内存,每次查询几个,必须至少申请几个,最大申请20个 |
|
133 |
for(int i = 0; i < nCount; i++) { |
|
134 |
stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].nFilePathLen = 256; |
|
135 |
stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].pszFilePath = new Memory(256); |
|
136 |
} |
|
137 |
|
|
138 |
stuIn.write(); |
|
139 |
stuOut.write(); |
|
140 |
if(LoginModule.netsdk.CLIENT_DoFindFaceRecognition(stuIn, stuOut, 4000)) { |
|
141 |
stuIn.read(); |
|
142 |
stuOut.read(); |
|
143 |
|
|
144 |
if(stuOut.nCadidateExNum == 0) { |
|
145 |
return null; |
|
146 |
} |
|
147 |
|
|
148 |
// 获取到的信息 |
|
149 |
CANDIDATE_INFOEX[] stuCandidatesEx = new CANDIDATE_INFOEX[stuOut.nCadidateExNum]; |
|
150 |
for(int i = 0; i < stuOut.nCadidateExNum; i++) { |
|
151 |
stuCandidatesEx[i] = new CANDIDATE_INFOEX(); |
|
152 |
stuCandidatesEx[i] = stuOut.stuCandidatesEx[i]; |
|
153 |
} |
|
154 |
|
|
155 |
return stuCandidatesEx; |
|
156 |
} else { |
|
157 |
System.out.println("CLIENT_DoFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); |
|
158 |
} |
|
159 |
|
|
160 |
return null; |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* 结束查询 |
|
165 |
*/ |
|
166 |
public static boolean doFindClosePerson() { |
|
167 |
boolean bRet = false; |
|
168 |
if(m_FindHandle.longValue() != 0) { |
|
169 |
bRet = LoginModule.netsdk.CLIENT_StopFindFaceRecognition(m_FindHandle); |
|
170 |
} |
|
171 |
return bRet; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* 订阅人脸查询状态 |
|
176 |
* @param faceFindStateCb 人脸状态回调函数 |
|
177 |
* @return |
|
178 |
*/ |
|
179 |
public static boolean attachFaceFindState(fFaceFindState faceFindStateCb) { |
|
180 |
/* |
|
181 |
* 入参 |
|
182 |
*/ |
|
183 |
NET_IN_FACE_FIND_STATE stuIn = new NET_IN_FACE_FIND_STATE(); |
|
184 |
stuIn.nTokenNum = 1; |
|
185 |
stuIn.nTokens = new IntByReference(nToken); // 查询令牌 |
|
186 |
stuIn.cbFaceFindState = faceFindStateCb; |
|
187 |
|
|
188 |
/* |
|
189 |
* 出参 |
|
190 |
*/ |
|
191 |
NET_OUT_FACE_FIND_STATE stuOut = new NET_OUT_FACE_FIND_STATE(); |
|
192 |
|
|
193 |
stuIn.write(); |
|
194 |
attachFaceHandle = LoginModule.netsdk.CLIENT_AttachFaceFindState(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); |
|
195 |
stuIn.read(); |
|
196 |
|
|
197 |
if(attachFaceHandle.longValue() != 0) { |
|
198 |
System.out.println("AttachFaceFindState Succeed!"); |
|
199 |
return true; |
|
200 |
} |
|
201 |
|
|
202 |
return false; |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* 关闭订阅 |
|
207 |
*/ |
|
208 |
public static void detachFaceFindState() { |
|
209 |
if(attachFaceHandle.longValue() != 0) { |
|
210 |
LoginModule.netsdk.CLIENT_DetachFaceFindState(attachFaceHandle); |
|
211 |
attachFaceHandle.setValue(0); |
|
212 |
} |
|
213 |
} |
|
214 |
} |