package com.iailab.module.data.dev.dahua;
|
|
import com.alibaba.fastjson.JSON;
|
import com.iailab.module.data.common.utils.HttpRequest;
|
import com.iailab.module.data.dev.task.CameraHeartTask;
|
import com.netsdk.lib.NetSDKLib;
|
import com.sun.jna.Pointer;
|
|
import javax.imageio.ImageIO;
|
import java.awt.image.BufferedImage;
|
import java.io.ByteArrayInputStream;
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.Calendar;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 设置抓图回调
|
*
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年03月06日
|
*/
|
public class DHCaptureReceiveCB implements NetSDKLib.fSnapRev {
|
|
public static String url = "http://127.0.0.1:8080/iailab/api/recognition";
|
|
@Override
|
public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int revLen, int encodeType, int cmdSerial, Pointer dwUser) {
|
System.out.println("DHCaptureReceiveCB:");
|
Calendar calendar = Calendar.getInstance();
|
// calendar.set(Calendar.MONTH, 0);
|
// calendar.set(Calendar.SECOND, 0);
|
if (pBuf != null && revLen > 0) {
|
String strFileName = DHSavePath.getSavePath().getSaveCapturePath(String.valueOf(cmdSerial), calendar.getTime());
|
System.out.println("cmdSerial=" + cmdSerial);
|
System.out.println("strFileName=" + strFileName);
|
|
byte[] buf = pBuf.getByteArray(0, revLen);
|
ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
|
try {
|
BufferedImage bufferedImage = ImageIO.read(byteArrInput);
|
if (bufferedImage == null) {
|
return;
|
}
|
ImageIO.write(bufferedImage, "jpg", new File(strFileName));
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
// 开始识别
|
Map<String, String> params = new HashMap<>();
|
params.put("strFileName", strFileName);
|
params.put("cmdSerial", Integer.valueOf(cmdSerial).toString());
|
HttpRequest.doPost(url, JSON.toJSONString(params), "utf-8", "");
|
|
CameraHeartTask.cameraCapTime.put(Integer.valueOf(cmdSerial), System.currentTimeMillis());
|
}
|
}
|
}
|