| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.stylefeng.guns.modular.system.model.enums.ImageModelEnum; |
| | | import com.stylefeng.guns.modular.system.util.UUIDUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | /** |
| | | * 本地存储图片地址 |
| | | */ |
| | | @Value("${filePath}") |
| | | private static String filePath; |
| | | private static String filePath = "/home/file/image/"; |
| | | // private static String filePath = "d:/file/"; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static List<String> closedTopModel(String url){ |
| | | try { |
| | | String fileName = url.substring(url.lastIndexOf(".")); |
| | | URLConnection urlConnection = new URL(url).openConnection(); |
| | | urlConnection.connect(); |
| | | InputStream inputStream = urlConnection.getInputStream(); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath + UUIDUtil.getTimeStr() + fileName); |
| | | inputStream.close(); |
| | | return closedTopModel(file); |
| | | } catch (MalformedURLException e) { |
| | |
| | | */ |
| | | private static List<String> cameraFaultModel(String url){ |
| | | try { |
| | | String fileName = url.substring(url.lastIndexOf(".")); |
| | | URLConnection urlConnection = new URL(url).openConnection(); |
| | | urlConnection.connect(); |
| | | InputStream inputStream = urlConnection.getInputStream(); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath + UUIDUtil.getTimeStr() + fileName); |
| | | inputStream.close(); |
| | | return cameraFaultModel(file); |
| | | } catch (MalformedURLException e) { |
| | |
| | | */ |
| | | private static List<String> constructionWasteLoadModel(String url){ |
| | | try { |
| | | String fileName = url.substring(url.lastIndexOf(".")); |
| | | URLConnection urlConnection = new URL(url).openConnection(); |
| | | urlConnection.connect(); |
| | | InputStream inputStream = urlConnection.getInputStream(); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath); |
| | | File file = FileUtil.writeFromStream(inputStream, filePath + UUIDUtil.getTimeStr() + fileName); |
| | | inputStream.close(); |
| | | return constructionWasteLoadModel(file); |
| | | } catch (MalformedURLException e) { |
| | |
| | | |
| | | /** |
| | | * 1号模型四类标签分别是 |
| | | * Loaded Cargo - Unsealed装载-未关闭 |
| | | * Loaded Cargo - Unsealed 装载-未关闭 |
| | | * Empty Container - Sealed 空载-关闭 |
| | | * Empty Container - Unsealed空载-未关闭 |
| | | * Loaded Cargo - Sealed-装载-关闭 |
| | | * Empty Container - Unsealed 空载-未关闭 |
| | | * Loaded Cargo - Sealed 装载-关闭 |
| | | * ttt 未识别到货箱 |
| | | * 2号模型四类分别是:'blurred'(模糊), 'no_video'(无视频),'normalcy'(正常), 'splash_screen(花屏)' |
| | | * @param url |
| | | * @param modelEnum |
| | | * @return |
| | | */ |
| | | public static boolean modelCheck(String url, ImageModelEnum modelEnum){ |
| | | public static Map<String, Object> modelCheck(String url, ImageModelEnum modelEnum){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | switch (modelEnum){ |
| | | case TOP_SEAL: |
| | | List<String> list1 = closedTopModel(url); |
| | | map.put("r", JSON.toJSONString(list1)); |
| | | map.put("b", !(list1.contains("Loaded Cargo - Unsealed") || list1.contains("ttt"))); |
| | | //其中包含装载未关闭,视为异常 |
| | | return !list1.contains("Loaded Cargo - Unsealed"); |
| | | return map; |
| | | case CAMERA_FAULT: |
| | | List<String> list2 = cameraFaultModel(url); |
| | | map.put("r", JSON.toJSONString(list2)); |
| | | map.put("b", list2.contains("normalcy")); |
| | | //其中包含正常,视为正常 |
| | | return list2.contains("normalcy"); |
| | | return map; |
| | | case CONSTRUCTION_WASTE_LOAD: // TODO 待完善 |
| | | List<String> list3 = constructionWasteLoadModel(url); |
| | | map.put("r", JSON.toJSONString(list3)); |
| | | map.put("b", list3.contains("normalcy")); |
| | | //其中包含正常,视为正常 |
| | | return list3.contains("normalcy"); |
| | | return map; |
| | | } |
| | | return false; |
| | | return null; |
| | | } |
| | | |
| | | |