|
|
|
@ -9,7 +9,13 @@ import com.alibaba.fastjson.JSONException; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.inspect.simulator.domain.Infrared.*; |
|
|
|
import com.inspect.simulator.domain.algorithm.in.AnalyseReqItem; |
|
|
|
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest; |
|
|
|
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem; |
|
|
|
import com.inspect.simulator.domain.algorithm.out.AnalyseResPoint; |
|
|
|
import com.inspect.simulator.domain.algorithm.out.AnalyseResult; |
|
|
|
import com.inspect.simulator.domain.basedata.BasedataEqpBookChannel; |
|
|
|
import com.inspect.simulator.hikVision.utils.AjaxResult; |
|
|
|
import com.inspect.simulator.hikVision.utils.StringUtils; |
|
|
|
@ -17,6 +23,7 @@ import com.inspect.simulator.hikVision.utils.jna.HikVisionUtils; |
|
|
|
import com.inspect.simulator.hikVision.utils.jna.HCNetSDK; |
|
|
|
import com.inspect.simulator.mapper.BasedataEqpBookChannelMapper; |
|
|
|
import com.inspect.simulator.service.HikVisionService; |
|
|
|
import com.inspect.simulator.utils.HttpClientUtils; |
|
|
|
import com.inspect.simulator.utils.sftp.SftpClient; |
|
|
|
import com.sun.jna.ptr.IntByReference; |
|
|
|
|
|
|
|
@ -31,6 +38,7 @@ import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -313,13 +321,13 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
int secondY = 640; |
|
|
|
int imgWidth = 640; |
|
|
|
int imgHeight = 512; |
|
|
|
if(infraPictureInfo.getCoordinates() != null && !infraPictureInfo.getCoordinates().isEmpty()) { |
|
|
|
if (infraPictureInfo.getCoordinates() != null && !infraPictureInfo.getCoordinates().isEmpty()) { |
|
|
|
firstX = infraPictureInfo.getCoordinates().get(0).getFirstX(); |
|
|
|
firstY = infraPictureInfo.getCoordinates().get(0).getFirstY(); |
|
|
|
secondX = infraPictureInfo.getCoordinates().get(0).getSecondX(); |
|
|
|
secondY = infraPictureInfo.getCoordinates().get(0).getSecondY(); |
|
|
|
imgWidth = infraPictureInfo.getImgHeight(); |
|
|
|
imgHeight = infraPictureInfo.getImgWidth(); |
|
|
|
imgHeight = infraPictureInfo.getImgWidth(); |
|
|
|
} |
|
|
|
|
|
|
|
String channelContent = firstX + "," + firstY + "," + secondX + "," + secondY + "," + imgWidth + "," + imgHeight; |
|
|
|
@ -1174,58 +1182,112 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult calculatePicture(InfraPictureInfo infraPictureInfo) { |
|
|
|
public ResponseEntity<String> irPicAnalyse(final String analyseRequestJson) { |
|
|
|
log.info("[INFRARED] irPicAnalyse: analyseRequestJson={}", analyseRequestJson); |
|
|
|
AnalyseRequest analyseRequest; |
|
|
|
try { |
|
|
|
analyseRequest = new Gson().fromJson(analyseRequestJson, AnalyseRequest.class); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("[INFRARED] irPicAnalyse: analyseRequestJson parse exception: {}", e.getMessage()); |
|
|
|
return ResponseEntity.ok().body("{\"code\":\"201\"}"); |
|
|
|
} |
|
|
|
log.info("[INFRARED] irPicAnalyse: analyseRequest={}", new Gson().toJson(analyseRequest)); |
|
|
|
|
|
|
|
|
|
|
|
List<AnalyseReqItem> analyseReqItemList = analyseRequest.getObjectList(); |
|
|
|
if(analyseReqItemList == null || analyseReqItemList.isEmpty()) { |
|
|
|
log.error("[INFRARED] irPicAnalyse: analyseReqItemList empty!"); |
|
|
|
return ResponseEntity.ok().body("{\"code\":\"202\"}"); |
|
|
|
} |
|
|
|
|
|
|
|
final AnalyseReqItem analyseReqItem = analyseReqItemList.get(0); |
|
|
|
final String[] typeList = analyseReqItem.getTypeList(); |
|
|
|
String algType = "unKnownType"; |
|
|
|
if(typeList != null && typeList.length != 0) { |
|
|
|
algType = typeList[0]; |
|
|
|
} |
|
|
|
final String feedBackHostIp = analyseRequest.getRequestHostIp(); |
|
|
|
final String feedBackPort = analyseRequest.getRequestHostPort(); |
|
|
|
final String feedbackUrl = feedBackHostIp + feedBackPort + "/picAnalyseRetNotify"; |
|
|
|
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}", feedbackUrl); |
|
|
|
|
|
|
|
AnalyseResult analyseResult = new AnalyseResult(); |
|
|
|
analyseResult.setRequestId(analyseRequest.getRequestId()); |
|
|
|
AnalyseResPoint analyseResPoint = new AnalyseResPoint(); |
|
|
|
analyseResPoint.setValue("0"); |
|
|
|
analyseResPoint.setConf("0.85"); |
|
|
|
analyseResPoint.setCode("2000"); |
|
|
|
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]); |
|
|
|
List<AnalyseResPoint> analyseResPoints = new ArrayList<>(); |
|
|
|
analyseResPoints.add(analyseResPoint); |
|
|
|
AnalyseResItem analyseResItem = new AnalyseResItem(); |
|
|
|
analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId()); |
|
|
|
analyseResItem.setAlgFactory(algType); |
|
|
|
analyseResItem.setResults(analyseResPoints); |
|
|
|
List<AnalyseResItem> analyseResItems = new ArrayList<>(); |
|
|
|
analyseResItems.add(analyseResItem); |
|
|
|
analyseResult.setResultList(analyseResItems); |
|
|
|
|
|
|
|
InfraredInfo infraredInfo = new InfraredInfo(); |
|
|
|
try { |
|
|
|
String imagePath = infraPictureInfo.getFilePath(); |
|
|
|
// String imagePath = "/images/ir_test.jpg"; |
|
|
|
InputStream inputStream = downloadFtp(imagePath); |
|
|
|
String protocol = hrFtpUrl.substring(0, 6); // "ftp://" |
|
|
|
String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/" |
|
|
|
String[] userAndHost = withoutProtocol.split("@"); |
|
|
|
if (userAndHost.length != 2) { |
|
|
|
throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符"); |
|
|
|
} |
|
|
|
String[] userPass = userAndHost[0].split(":"); |
|
|
|
String username = userPass[0]; |
|
|
|
String password = userPass[1]; |
|
|
|
String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/" |
|
|
|
String[] hostAndPort = hostPort.split(":"); |
|
|
|
String host = hostAndPort[0]; |
|
|
|
int port = Integer.parseInt(hostAndPort[1]); |
|
|
|
picFtp("/", inputStream, host, port, username, password); |
|
|
|
|
|
|
|
String imageName = Paths.get(imagePath).getFileName().toString(); |
|
|
|
String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]"; |
|
|
|
|
|
|
|
|
|
|
|
if (infraPictureInfo.getImgType() == 1) { |
|
|
|
byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath)); |
|
|
|
infraredInfo = readDataHw(imageBytes, infraPictureInfo.getCoordinates().get(0)); |
|
|
|
} else if (infraPictureInfo.getImgType() == 2) { |
|
|
|
|
|
|
|
// String s = ImageOverlaysIvs(infraPictureInfo.getCoordinates().get(0), infraredInfo); |
|
|
|
// infraredInfo.setOutPath(s); |
|
|
|
} else if (infraPictureInfo.getImgType() == 3) { |
|
|
|
//sdk版本调用x86_32 |
|
|
|
//float[][] imageTem = djService.getImageTem(coordinate.getFilePath()); |
|
|
|
|
|
|
|
//调用华软接口 |
|
|
|
float[][] imageTem = UploadFtpImage(hrUavUrl, null, ftpUrlName); |
|
|
|
if (imageTem != null && imageTem.length > 0 && imageTem[0].length > 0) { |
|
|
|
infraredInfo.setTemperatureMatrix(imageTem); |
|
|
|
String s = ImageOverlaysUav(infraPictureInfo, infraredInfo); |
|
|
|
infraredInfo.setOutPath(s); |
|
|
|
} else { |
|
|
|
return AjaxResult.error("温度解析错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
String analyseResultOutJson = JSONObject.toJSONString(analyseResult); |
|
|
|
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, analyseResultOutJson={}", feedbackUrl, analyseResultOutJson); |
|
|
|
String result = HttpClientUtils.sendPostAgain(feedbackUrl, analyseResultOutJson); |
|
|
|
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}", feedbackUrl, result); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return AjaxResult.error(); |
|
|
|
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, EXCEPTION: {}", feedbackUrl, e.getMessage()); |
|
|
|
} |
|
|
|
return AjaxResult.success(infraredInfo); |
|
|
|
|
|
|
|
return ResponseEntity.ok().body("{\"code\":\"200\"}"); |
|
|
|
// InfraredInfo infraredInfo = new InfraredInfo(); |
|
|
|
// try { |
|
|
|
// String imagePath = infraPictureInfo.getFilePath(); |
|
|
|
//// String imagePath = "/images/ir_test.jpg"; |
|
|
|
// InputStream inputStream = downloadFtp(imagePath); |
|
|
|
// String protocol = hrFtpUrl.substring(0, 6); // "ftp://" |
|
|
|
// String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/" |
|
|
|
// String[] userAndHost = withoutProtocol.split("@"); |
|
|
|
// if (userAndHost.length != 2) { |
|
|
|
// throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符"); |
|
|
|
// } |
|
|
|
// String[] userPass = userAndHost[0].split(":"); |
|
|
|
// String username = userPass[0]; |
|
|
|
// String password = userPass[1]; |
|
|
|
// String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/" |
|
|
|
// String[] hostAndPort = hostPort.split(":"); |
|
|
|
// String host = hostAndPort[0]; |
|
|
|
// int port = Integer.parseInt(hostAndPort[1]); |
|
|
|
// picFtp("/", inputStream, host, port, username, password); |
|
|
|
// |
|
|
|
// String imageName = Paths.get(imagePath).getFileName().toString(); |
|
|
|
// String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]"; |
|
|
|
// |
|
|
|
// |
|
|
|
// if (infraPictureInfo.getImgType() == 1) { |
|
|
|
// byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath)); |
|
|
|
// infraredInfo = readDataHw(imageBytes, infraPictureInfo.getCoordinates().get(0)); |
|
|
|
// } else if (infraPictureInfo.getImgType() == 2) { |
|
|
|
// |
|
|
|
//// String s = ImageOverlaysIvs(infraPictureInfo.getCoordinates().get(0), infraredInfo); |
|
|
|
//// infraredInfo.setOutPath(s); |
|
|
|
// } else if (infraPictureInfo.getImgType() == 3) { |
|
|
|
// //sdk版本调用x86_32 |
|
|
|
// //float[][] imageTem = djService.getImageTem(coordinate.getFilePath()); |
|
|
|
// |
|
|
|
// //调用华软接口 |
|
|
|
// float[][] imageTem = UploadFtpImage(hrUavUrl, null, ftpUrlName); |
|
|
|
// if (imageTem != null && imageTem.length > 0 && imageTem[0].length > 0) { |
|
|
|
// infraredInfo.setTemperatureMatrix(imageTem); |
|
|
|
// String s = ImageOverlaysUav(infraPictureInfo, infraredInfo); |
|
|
|
// infraredInfo.setOutPath(s); |
|
|
|
// } else { |
|
|
|
// return AjaxResult.error("温度解析错误!"); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } catch (Exception e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// return AjaxResult.error(); |
|
|
|
// } |
|
|
|
// return AjaxResult.success(infraredInfo); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|