|
|
@@ -8,17 +8,14 @@ import com.yunfeiyun.agmp.common.framework.oss.cloud.OSSFactory;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -27,56 +24,57 @@ import java.util.Set;
|
|
|
public class CbdInsectIdentifyUtil {
|
|
|
private static Logger logger = LoggerFactory.getLogger(CbdInsectIdentifyUtil.class);
|
|
|
|
|
|
- private static BufferedImage identify(BufferedImage bufferedImage,List<JSONObject> points, Map<String,String> insectMap){
|
|
|
- Graphics2D g2d = bufferedImage.createGraphics();
|
|
|
- g2d.setColor(Color.red);
|
|
|
- for(JSONObject point : points){
|
|
|
- Set<String> keySet = point.keySet();
|
|
|
- for(String key : keySet){
|
|
|
- String typeText = insectMap.get(key);
|
|
|
- JSONArray pointArray = point.getJSONArray(key);
|
|
|
- int x = (int)Float.parseFloat(pointArray.getString(0));
|
|
|
- int y = (int)Float.parseFloat(pointArray.getString(1));
|
|
|
- int x2 = (int)Float.parseFloat(pointArray.getString(2));
|
|
|
- int y2 = (int)Float.parseFloat(pointArray.getString(3));
|
|
|
- g2d.setFont(new Font("黑体",0,35));
|
|
|
- if(StringUtils.isNotEmpty(typeText)){
|
|
|
- g2d.drawString(typeText,x,y-20);
|
|
|
- }else {
|
|
|
- g2d.drawString(key,x,y-20);
|
|
|
- }
|
|
|
- g2d.drawRect(x, y, x2-x, y2-y);
|
|
|
+ private static BufferedImage identify(BufferedImage bufferedImage, List<JSONObject> points, Map<String, String> insectMap) {
|
|
|
+ Graphics2D g2d = bufferedImage.createGraphics();
|
|
|
+ g2d.setColor(Color.red);
|
|
|
+ for (JSONObject point : points) {
|
|
|
+ Set<String> keySet = point.keySet();
|
|
|
+ for (String key : keySet) {
|
|
|
+ String typeText = insectMap.get(key);
|
|
|
+ JSONArray pointArray = point.getJSONArray(key);
|
|
|
+ int x = (int) Float.parseFloat(pointArray.getString(0));
|
|
|
+ int y = (int) Float.parseFloat(pointArray.getString(1));
|
|
|
+ int x2 = (int) Float.parseFloat(pointArray.getString(2));
|
|
|
+ int y2 = (int) Float.parseFloat(pointArray.getString(3));
|
|
|
+ g2d.setFont(new Font("黑体", 0, 35));
|
|
|
+ if (StringUtils.isNotEmpty(typeText)) {
|
|
|
+ g2d.drawString(typeText, x, y - 20);
|
|
|
+ } else {
|
|
|
+ g2d.drawString(key, x, y - 20);
|
|
|
}
|
|
|
+ g2d.drawRect(x, y, x2 - x, y2 - y);
|
|
|
}
|
|
|
- return bufferedImage;
|
|
|
+ }
|
|
|
+ return bufferedImage;
|
|
|
}
|
|
|
|
|
|
- public static BufferedImage identify(String ossPath,List<JSONObject> points,Map<String,String> insectMap) {
|
|
|
+ public static BufferedImage identify(String ossPath, List<JSONObject> points, Map<String, String> insectMap) {
|
|
|
try {
|
|
|
URL url = new URL(ossPath);
|
|
|
- return identify(ImageIO.read(url),points,insectMap) ;
|
|
|
- }catch (MalformedURLException e){
|
|
|
- logger.error("oss图片地址格式不正确,{}",e.getMessage());
|
|
|
- }catch (IOException e){
|
|
|
- logger.error("图片读取失败,{}",e.getMessage());
|
|
|
+ return identify(ImageIO.read(url), points, insectMap);
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ logger.error("oss图片地址格式不正确,{}", e.getMessage());
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("图片读取失败,{}", e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private static String identifyAndUpload(BufferedImage bufferedImage, ResConstants.BizType bizType, String fileName,List<JSONObject> points, Map<String,String> insectMap) throws IOException {
|
|
|
- BufferedImage result = identify(bufferedImage,points,insectMap);
|
|
|
+ private static String identifyAndUpload(BufferedImage bufferedImage, ResConstants.BizType bizType, String fileName, List<JSONObject> points, Map<String, String> insectMap, String tid) throws IOException {
|
|
|
+ BufferedImage result = identify(bufferedImage, points, insectMap);
|
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
- ImageIO.write(result,"JPEG",byteArrayOutputStream);
|
|
|
- return OSSFactory.build().uploadSuffix(byteArrayOutputStream.toByteArray(),"jpg",bizType.getPath(),fileName);
|
|
|
+ ImageIO.write(result, "JPEG", byteArrayOutputStream);
|
|
|
+ return OSSFactory.build().uploadSuffixAndTenant(byteArrayOutputStream.toByteArray(), "jpg", bizType.getPath(), fileName, tid);
|
|
|
}
|
|
|
- public static String identifyAndUpload(String ossPath, ResConstants.BizType bizType, String fileName,List<JSONObject> points, Map<String,String> insectMap){
|
|
|
+
|
|
|
+ public static String identifyAndUpload(String ossPath, ResConstants.BizType bizType, String fileName, List<JSONObject> points, Map<String, String> insectMap, String tid) {
|
|
|
try {
|
|
|
URL url = new URL(ossPath);
|
|
|
- return identifyAndUpload(ImageIO.read(url),bizType,fileName,points,insectMap) ;
|
|
|
- }catch (MalformedURLException e){
|
|
|
- logger.error("oss图片地址格式不正确,{}",e.getMessage());
|
|
|
- }catch (IOException e){
|
|
|
- logger.error("图片读取失败,{}",e.getMessage());
|
|
|
+ return identifyAndUpload(ImageIO.read(url), bizType, fileName, points, insectMap, tid);
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ logger.error("oss图片地址格式不正确,{}", e.getMessage());
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("图片读取失败,{}", e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|