dongyukun
2024-11-05 e8ad669f7c97d45cd23630dc101180a130d6c17e
提交 | 用户 | 时间
ce910c 1 package com.iailab.module.data.dev.dahua;
H 2
3 import com.alibaba.fastjson.JSON;
4 import com.iailab.module.data.common.utils.HttpRequest;
5 import com.iailab.module.data.dev.task.CameraHeartTask;
6 import com.netsdk.lib.NetSDKLib;
7 import com.sun.jna.Pointer;
8
9 import javax.imageio.ImageIO;
10 import java.awt.image.BufferedImage;
11 import java.io.ByteArrayInputStream;
12 import java.io.File;
13 import java.io.IOException;
14 import java.util.Calendar;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * 设置抓图回调
20  *
21  * @author PanZhibao
22  * @Description
23  * @createTime 2024年03月06日
24  */
25 public class DHCaptureReceiveCB implements NetSDKLib.fSnapRev {
26
27     public static String url = "http://127.0.0.1:8080/iailab/api/recognition";
28
29     @Override
30     public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int revLen, int encodeType, int cmdSerial, Pointer dwUser) {
31         System.out.println("DHCaptureReceiveCB:");
32         Calendar calendar = Calendar.getInstance();
33 //        calendar.set(Calendar.MONTH, 0);
34 //        calendar.set(Calendar.SECOND, 0);
35         if (pBuf != null && revLen > 0) {
36             String strFileName = DHSavePath.getSavePath().getSaveCapturePath(String.valueOf(cmdSerial), calendar.getTime());
37             System.out.println("cmdSerial=" + cmdSerial);
38             System.out.println("strFileName=" + strFileName);
39
40             byte[] buf = pBuf.getByteArray(0, revLen);
41             ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
42             try {
43                 BufferedImage bufferedImage = ImageIO.read(byteArrInput);
44                 if (bufferedImage == null) {
45                     return;
46                 }
47                 ImageIO.write(bufferedImage, "jpg", new File(strFileName));
48             } catch (IOException e) {
49                 e.printStackTrace();
50             }
51
52             // 开始识别
53             Map<String, String> params = new HashMap<>();
54             params.put("strFileName", strFileName);
55             params.put("cmdSerial", Integer.valueOf(cmdSerial).toString());
56             HttpRequest.doPost(url, JSON.toJSONString(params), "utf-8", "");
57
58             CameraHeartTask.cameraCapTime.put(Integer.valueOf(cmdSerial), System.currentTimeMillis());
59         }
60     }
61 }