提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.module; |
H |
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import com.iailab.netsdk.lib.ImageAlgLib; |
|
6 |
import com.iailab.netsdk.lib.ToolKits; |
|
7 |
import com.iailab.netsdk.lib.NetSDKLib; |
|
8 |
import com.iailab.netsdk.lib.NetSDKLib.*; |
|
9 |
|
|
10 |
|
|
11 |
public class ThermalCameraModule { |
|
12 |
|
|
13 |
static ImageAlgLib imageAlgApi = ImageAlgLib.IMAGEALG_INSTANCE; |
|
14 |
|
|
15 |
public static class ThermalCameraStatus { |
|
16 |
public boolean bSearching = false; // 是否正在查找 |
|
17 |
public int nFinderHanle; // 取到的查询句柄 |
|
18 |
public int nTotalCount; // 符合此次查询条件的结果总条数 |
|
19 |
public LLong hRadiometryHandle = new LLong(0); // 订阅句柄 |
|
20 |
} |
|
21 |
|
|
22 |
private static ThermalCameraStatus status = new ThermalCameraStatus(); |
|
23 |
|
|
24 |
/** |
|
25 |
* 订阅温度分布数据(热图) |
|
26 |
*/ |
|
27 |
public static boolean radiometryAttach(int nChannel, fRadiometryAttachCB cbNotify) { |
|
28 |
/* |
|
29 |
* 入参 |
|
30 |
*/ |
|
31 |
NET_IN_RADIOMETRY_ATTACH stIn = new NET_IN_RADIOMETRY_ATTACH(); |
|
32 |
stIn.nChannel = nChannel; // 通道号 |
|
33 |
stIn.cbNotify = cbNotify; // 回调函数 |
|
34 |
|
|
35 |
/* |
|
36 |
* 出参 |
|
37 |
*/ |
|
38 |
NET_OUT_RADIOMETRY_ATTACH stOut = new NET_OUT_RADIOMETRY_ATTACH(); |
|
39 |
status.hRadiometryHandle = LoginModule.netsdk.CLIENT_RadiometryAttach(LoginModule.m_hLoginHandle, stIn, stOut, 3000); |
|
40 |
|
|
41 |
if(status.hRadiometryHandle.longValue() == 0) { |
|
42 |
System.err.printf("RadiometryAttach Failed!" + ToolKits.getErrorCodePrint()); |
|
43 |
} |
|
44 |
|
|
45 |
return status.hRadiometryHandle.longValue() != 0; |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* 获取查询总个数 |
|
50 |
*/ |
|
51 |
public static boolean isAttaching() { |
|
52 |
return status.hRadiometryHandle.longValue() != 0; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* 开始获取热图数据 |
|
57 |
*/ |
|
58 |
public static int radiometryFetch(int nChannel) { |
|
59 |
|
|
60 |
int nStatus = -1; |
|
61 |
|
|
62 |
/* |
|
63 |
* 入参 |
|
64 |
*/ |
|
65 |
NET_IN_RADIOMETRY_FETCH stIn = new NET_IN_RADIOMETRY_FETCH(); |
|
66 |
stIn.nChannel = nChannel; // 通道号 |
|
67 |
|
|
68 |
/* |
|
69 |
* 出参 |
|
70 |
*/ |
|
71 |
NET_OUT_RADIOMETRY_FETCH stOut = new NET_OUT_RADIOMETRY_FETCH(); |
|
72 |
|
|
73 |
if(!LoginModule.netsdk.CLIENT_RadiometryFetch(LoginModule.m_hLoginHandle, stIn, stOut, 3000)) { |
|
74 |
System.err.printf("RadiometryFetch Failed!" + ToolKits.getErrorCodePrint()); |
|
75 |
} else { |
|
76 |
nStatus = stOut.nStatus; |
|
77 |
} |
|
78 |
|
|
79 |
return nStatus; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* 处理回调数据(热图) |
|
84 |
* @throws IOException |
|
85 |
*/ |
|
86 |
public static boolean saveData(NET_RADIOMETRY_DATA radiometryData) throws IOException { |
|
87 |
|
|
88 |
if (radiometryData == null) { |
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
int nWidth = radiometryData.stMetaData.nWidth; |
|
93 |
int nHeight = radiometryData.stMetaData.nHeight; |
|
94 |
|
|
95 |
short[] pGrayImg = new short[nWidth * nHeight]; |
|
96 |
float[] pTempForPixels = new float[nWidth * nHeight]; |
|
97 |
|
|
98 |
if(LoginModule.netsdk.CLIENT_RadiometryDataParse(radiometryData, pGrayImg, pTempForPixels)) { |
|
99 |
byte[] pYData = new byte[nWidth*nHeight*2]; |
|
100 |
imageAlgApi.drcTable(pGrayImg, (short)nWidth, (short)nHeight, 0, pYData, null); |
|
101 |
ToolKits.savePicture(pYData, "./GrayscaleMap.yuv"); |
|
102 |
} else { |
|
103 |
System.err.println("saveData failed!" + ToolKits.getErrorCodePrint()); |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
return true; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* 取消订阅温度分布数据 |
|
112 |
*/ |
|
113 |
public static void radiometryDetach() { |
|
114 |
if(status.hRadiometryHandle.longValue() != 0) { |
|
115 |
LoginModule.netsdk.CLIENT_RadiometryDetach(status.hRadiometryHandle); |
|
116 |
status.hRadiometryHandle.setValue(0); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* 查询测温点 |
|
122 |
*/ |
|
123 |
public static NET_RADIOMETRYINFO queryPointTemper(int nChannel, short x, short y) { |
|
124 |
int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_POINT_TEMPER; |
|
125 |
|
|
126 |
// 入参 |
|
127 |
NET_IN_RADIOMETRY_GETPOINTTEMPER stIn = new NET_IN_RADIOMETRY_GETPOINTTEMPER(); |
|
128 |
stIn.nChannel = nChannel; |
|
129 |
stIn.stCoordinate.nx = x; |
|
130 |
stIn.stCoordinate.ny = y; |
|
131 |
|
|
132 |
// 出参 |
|
133 |
NET_OUT_RADIOMETRY_GETPOINTTEMPER stOut = new NET_OUT_RADIOMETRY_GETPOINTTEMPER(); |
|
134 |
|
|
135 |
stIn.write(); |
|
136 |
stOut.write(); |
|
137 |
boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000); |
|
138 |
if(!bRet) { |
|
139 |
System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint()); |
|
140 |
return null; |
|
141 |
} |
|
142 |
|
|
143 |
stOut.read(); |
|
144 |
return stOut.stPointTempInfo; |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* 查询测温项 |
|
149 |
*/ |
|
150 |
public static NET_RADIOMETRYINFO queryItemTemper(int nChannel, int nPresetId, int nRuleId, int nMeterType) { |
|
151 |
int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_TEMPER; |
|
152 |
|
|
153 |
// 入参 |
|
154 |
NET_IN_RADIOMETRY_GETTEMPER stIn = new NET_IN_RADIOMETRY_GETTEMPER(); |
|
155 |
stIn.stCondition.nPresetId = nPresetId; |
|
156 |
stIn.stCondition.nRuleId = nRuleId; |
|
157 |
stIn.stCondition.nMeterType = nMeterType; // eg: NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_AREA; |
|
158 |
stIn.stCondition.nChannel = nChannel; |
|
159 |
|
|
160 |
// 出参 |
|
161 |
NET_OUT_RADIOMETRY_GETTEMPER stOut = new NET_OUT_RADIOMETRY_GETTEMPER(); |
|
162 |
|
|
163 |
stIn.write(); |
|
164 |
stOut.write(); |
|
165 |
boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000); |
|
166 |
if(!bRet) { |
|
167 |
System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint()); |
|
168 |
return null; |
|
169 |
} |
|
170 |
|
|
171 |
stOut.read(); |
|
172 |
return stOut.stTempInfo; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* 开始查询信息 |
|
177 |
*/ |
|
178 |
public static boolean startFind(NET_IN_RADIOMETRY_STARTFIND stuIn) { |
|
179 |
if(status.bSearching) { |
|
180 |
stopFind(); |
|
181 |
} |
|
182 |
|
|
183 |
/* |
|
184 |
* 出参 |
|
185 |
*/ |
|
186 |
NET_OUT_RADIOMETRY_STARTFIND stuOut = new NET_OUT_RADIOMETRY_STARTFIND(); |
|
187 |
stuIn.write(); |
|
188 |
stuOut.write(); |
|
189 |
status.bSearching = LoginModule.netsdk.CLIENT_StartFind(LoginModule.m_hLoginHandle, |
|
190 |
NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000); |
|
191 |
if (status.bSearching) { |
|
192 |
stuOut.read(); |
|
193 |
status.nFinderHanle = stuOut.nFinderHanle; |
|
194 |
status.nTotalCount = stuOut.nTotalCount; |
|
195 |
}else { |
|
196 |
System.err.printf("startFind Failed!" + ToolKits.getErrorCodePrint()); |
|
197 |
} |
|
198 |
|
|
199 |
return status.bSearching; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* 获取查询总个数 |
|
204 |
*/ |
|
205 |
public static int getTotalCount() { |
|
206 |
return status.nTotalCount; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* 查询信息 |
|
211 |
*/ |
|
212 |
public static NET_OUT_RADIOMETRY_DOFIND doFind(int nOffset, int nCount) { |
|
213 |
if(!status.bSearching) { |
|
214 |
System.err.printf("DoFind Failed! [need startFind]"); |
|
215 |
return null; |
|
216 |
} |
|
217 |
|
|
218 |
/* |
|
219 |
* 入参 |
|
220 |
*/ |
|
221 |
NET_IN_RADIOMETRY_DOFIND stuIn = new NET_IN_RADIOMETRY_DOFIND(); |
|
222 |
stuIn.nFinderHanle = status.nFinderHanle; |
|
223 |
stuIn.nBeginNumber = nOffset; |
|
224 |
stuIn.nCount = nCount; |
|
225 |
|
|
226 |
/* |
|
227 |
* 出参 |
|
228 |
*/ |
|
229 |
NET_OUT_RADIOMETRY_DOFIND stuOut = new NET_OUT_RADIOMETRY_DOFIND(); |
|
230 |
|
|
231 |
stuIn.write(); |
|
232 |
stuOut.write(); |
|
233 |
if (!LoginModule.netsdk.CLIENT_DoFind(LoginModule.m_hLoginHandle, |
|
234 |
NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000)) { |
|
235 |
System.err.printf("DoFind Failed!" + ToolKits.getErrorCodePrint()); |
|
236 |
return null; |
|
237 |
} |
|
238 |
|
|
239 |
stuOut.read(); |
|
240 |
return stuOut; |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* 停止查询信息 |
|
245 |
*/ |
|
246 |
public static void stopFind() { |
|
247 |
if(!status.bSearching) { |
|
248 |
return; |
|
249 |
} |
|
250 |
|
|
251 |
/* |
|
252 |
* 入参 |
|
253 |
*/ |
|
254 |
NET_IN_RADIOMETRY_STOPFIND stuIn = new NET_IN_RADIOMETRY_STOPFIND(); |
|
255 |
stuIn.nFinderHanle = status.nFinderHanle; |
|
256 |
|
|
257 |
/* |
|
258 |
* 出参 |
|
259 |
*/ |
|
260 |
NET_OUT_RADIOMETRY_STOPFIND stuOut = new NET_OUT_RADIOMETRY_STOPFIND(); |
|
261 |
|
|
262 |
stuIn.write(); |
|
263 |
stuOut.write(); |
|
264 |
LoginModule.netsdk.CLIENT_StopFind(LoginModule.m_hLoginHandle, |
|
265 |
NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000); |
|
266 |
|
|
267 |
status.bSearching = false; |
|
268 |
status.nFinderHanle = 0; |
|
269 |
// status.nTotalCount = 0; |
|
270 |
|
|
271 |
return; |
|
272 |
} |
|
273 |
} |