Просмотр исходного кода

图片矫正功能和添加飞行的控制元素,速度、高度、方位角、旋转角

DESKTOP-2K9OVK9\siwei 5 дней назад
Родитель
Сommit
e909cf9a7a

+ 6 - 0
onemap-modules/onemap-analyse/pom.xml

@@ -142,6 +142,12 @@
             <artifactId>jakarta.activation-api</artifactId>
             <version>2.1.1</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.drewnoakes</groupId>
+            <artifactId>metadata-extractor</artifactId>
+            <version>2.18.0</version>
+        </dependency>
     </dependencies>
     <repositories>
         <repository>

+ 162 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/ImageRotationCorrector.java

@@ -0,0 +1,162 @@
+package com.onemap.analyse;
+
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import javax.imageio.ImageIO;
+
+public class ImageRotationCorrector {
+
+    public static BufferedImage correctImageOrientation(BufferedImage image, int orientation) {
+        switch (orientation) {
+            case 1:
+                return image; // 无需旋转
+            case 3:
+                return rotate180(image);
+            case 6:
+                return rotate90(image);
+            case 8:
+                return rotate270(image);
+            default:
+                return image; // 未知方向,保持原样
+        }
+    }
+
+    private static BufferedImage rotate90(BufferedImage image) {
+        int width = image.getWidth();
+        int height = image.getHeight();
+        BufferedImage rotated = new BufferedImage(height, width, image.getType());
+
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                rotated.setRGB(height - 1 - y, x, image.getRGB(x, y));
+            }
+        }
+
+        return rotated;
+    }
+
+    private static BufferedImage rotate180(BufferedImage image) {
+        int width = image.getWidth();
+        int height = image.getHeight();
+        BufferedImage rotated = new BufferedImage(width, height, image.getType());
+
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                rotated.setRGB(width - 1 - x, height - 1 - y, image.getRGB(x, y));
+            }
+        }
+
+        return rotated;
+    }
+
+    private static BufferedImage rotate270(BufferedImage image) {
+        int width = image.getWidth();
+        int height = image.getHeight();
+        BufferedImage rotated = new BufferedImage(height, width, image.getType());
+
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                rotated.setRGB(y, width - 1 - x, image.getRGB(x, y));
+            }
+        }
+
+        return rotated;
+    }
+
+    /**
+     * 旋转图像
+     *
+     * @param image   原始图像
+     * @param degrees 旋转角度(0-360)
+     * @return 旋转后的图像
+     */
+    public static BufferedImage rotateImage(BufferedImage image, double degrees) {
+        // 将角度转换为弧度
+        double radians = Math.toRadians(degrees);
+
+        // 计算旋转后的图像尺寸
+        double sin = Math.abs(Math.sin(radians));
+        double cos = Math.abs(Math.cos(radians));
+        int newWidth = (int) Math.round(image.getWidth() * cos + image.getHeight() * sin);
+        int newHeight = (int) Math.round(image.getWidth() * sin + image.getHeight() * cos);
+
+        // 创建新的BufferedImage
+        BufferedImage rotatedImage = new BufferedImage(newWidth, newHeight, image.getType());
+        Graphics2D g2d = rotatedImage.createGraphics();
+
+        // 设置旋转中心并旋转
+        AffineTransform transform = new AffineTransform();
+        transform.translate(newWidth / 2, newHeight / 2);
+        transform.rotate(radians);
+        transform.translate(-image.getWidth() / 2, -image.getHeight() / 2);
+
+        // 应用变换
+        g2d.setTransform(transform);
+        g2d.drawImage(image, 0, 0, null);
+        g2d.dispose();
+
+        return rotatedImage;
+    }
+
+    public static void main(String[] args) {
+        try {
+            File fileDir = new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\下");
+            File[] files = fileDir.listFiles();
+            for (File imageFile : files) {
+                String name = imageFile.getName();
+//                File imageFile = file;
+                BufferedImage image = ImageIO.read(imageFile);
+                // 获取EXIF方向信息
+                int orientation = ImageRotationReader.getImageOrientation(imageFile);
+                if (1 != orientation) {
+                    // 校正图像方向
+                    BufferedImage correctedImage = correctImageOrientation(image, orientation);
+
+                    // 旋转270度(逆时针90度)
+                    BufferedImage rotatedImage = rotateImage(correctedImage, 270);
+
+                    ImageIO.write(rotatedImage, "jpg", new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\上\\" + name));
+                } else {
+                    ImageIO.write(image, "jpg", new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\上\\" + name));
+                }
+            }
+            System.out.println("图像方向已校正并保存");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void main1(String[] args) {
+        try {
+            File fileDir = new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\下");
+            File[] files = fileDir.listFiles();
+            for (File file : files) {
+                File imageFile = new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\下\\240011204500004.JPG");
+                BufferedImage image = ImageIO.read(imageFile);
+            }
+
+
+            File imageFile = new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\下\\240011204500004.JPG");
+            BufferedImage image = ImageIO.read(imageFile);
+
+            // 获取EXIF方向信息
+            int orientation = ImageRotationReader.getImageOrientation(imageFile);
+
+            if (1 != orientation) {
+                // 校正图像方向
+                BufferedImage correctedImage = correctImageOrientation(image, orientation);
+                // 保存校正后的图像
+                ImageIO.write(correctedImage, "jpg", new File("D:\\02DATA\\三亚\\甲方数据\\飞行\\三亚无人机数据\\24001120450\\下\\corrected_photo.jpg"));
+
+            }
+
+
+            System.out.println("图像方向已校正并保存");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 41 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/gdbh/TGdbhFlightBatchDto.java

@@ -17,6 +17,15 @@ public class TGdbhFlightBatchDto {
     private List<TGdbhFlightDto> flightDtoList;
     private String fpf;
 
+    //速度
+    private String speed;
+    //方位角控制左右旋转的
+    private String heading;
+    //切斜角控制上下
+    private String tilt;
+    //高度
+    private String height;
+
     public String getId() {
         return id;
     }
@@ -64,4 +73,36 @@ public class TGdbhFlightBatchDto {
     public void setFpf(String fpf) {
         this.fpf = fpf;
     }
+
+    public String getSpeed() {
+        return speed;
+    }
+
+    public void setSpeed(String speed) {
+        this.speed = speed;
+    }
+
+    public String getHeading() {
+        return heading;
+    }
+
+    public void setHeading(String heading) {
+        this.heading = heading;
+    }
+
+    public String getTilt() {
+        return tilt;
+    }
+
+    public void setTilt(String tilt) {
+        this.tilt = tilt;
+    }
+
+    public String getHeight() {
+        return height;
+    }
+
+    public void setHeight(String height) {
+        this.height = height;
+    }
 }

+ 80 - 62
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/gdbh/impl/TGdbhGdServiceImpl.java

@@ -174,7 +174,7 @@ public class TGdbhGdServiceImpl implements ITGdbhGdService {
                 TGdbhFlightDto queryFlightDto = new TGdbhFlightDto();
                 queryFlightDto.setBatch(bathDto.getBatch());
                 List<TGdbhFlightDto> flightDtoList = tGdbhFlightMapper.selectList(queryFlightDto);
-                writeFpf(flightDtoList, uploadFilePath + fpfPath);
+                writeFpf(tGdbhFlightBatchDto, flightDtoList, uploadFilePath + fpfPath);
                 bathDto.setFpf(fpfPath);
                 bathDto.setFlightDtoList(flightDtoList);
             }
@@ -183,70 +183,88 @@ public class TGdbhGdServiceImpl implements ITGdbhGdService {
     }
 
 
-    private void writeFpf(List<TGdbhFlightDto> flightDtoList, String filePathString) {
+    private void writeFpf(TGdbhFlightBatchDto tGdbhFlightBatchDto, List<TGdbhFlightDto> flightDtoList, String filePathString) {
+        String speed = "10";
+        String heading = "0.000001";
+        String tilt = "0.100000000000000006";
+        if (null != tGdbhFlightBatchDto) {
+            if (StringUtils.isNotEmpty(tGdbhFlightBatchDto.getTilt())) {
+                tilt = tGdbhFlightBatchDto.getTilt();
+            }
+            if (StringUtils.isNotEmpty(tGdbhFlightBatchDto.getHeading())) {
+                heading = tGdbhFlightBatchDto.getHeading();
+            }
+            if (StringUtils.isNotEmpty(tGdbhFlightBatchDto.getSpeed())) {
+                speed = tGdbhFlightBatchDto.getSpeed();
+            }
+        }
         File filePath = new File(filePathString);
-        if (!filePath.exists()) {
-            try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
-                writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-                writer.newLine(); // 写入换行
-                writer.write("<SceneRoute xmlns=\"http://www.supermap.com.cn/ugc60\">");
-                writer.newLine(); // 写入换行
-                writer.write("<route name=\"飞行路线_1\" speed=\"10\" lineType=\"0\" showroutestop=\"True\" showrouteline=\"True\" altitudefree=\"False\" headingfree=\"False\" tiltfree=\"False\" flycircle=\"False\" alongline=\"False\">");
-                writer.newLine(); // 写入换行
-                writer.write("<style>");
-                writer.newLine(); // 写入换行
-                writer.write("<geostyle3d>");
-                writer.newLine(); // 写入换行
-                writer.write("<linecolor>RGBA(147,112,219,100)</linecolor>");
-                writer.newLine(); // 写入换行
-                writer.write("<linewidth>2</linewidth>");
-                writer.newLine(); // 写入换行
-                writer.write("<altitudeMode>Absolute</altitudeMode>");
-                writer.newLine(); // 写入换行
-                writer.write("<bottomAltitude>0.00</bottomAltitude>");
-                writer.newLine(); // 写入换行
-                writer.write("</geostyle3d>");
-                writer.newLine(); // 写入换行
-                writer.write("</style>");
-                writer.newLine(); // 写入换行
-                for (int i = 0; i < flightDtoList.size(); i++) {
-                    TGdbhFlightDto dto = flightDtoList.get(i);
-                    String fpf = "<routestop name=\"" + dto.getPhoto_name() + "\" speed=\"0\" excluded=\"False\" viewType=\"camera\">" +
-                            "<camera>" +
-                            "<longitude>" + dto.getLongitude() + "</longitude>" +
-                            "<latitude>" + dto.getLatitude() + "</latitude>" +
-                            "<altitude>" + dto.getHeight() + "</altitude>" +
-                            "<heading>0.000001</heading>" +
-                            "<tilt>0.100000000000000006</tilt>" +
-                            "<altitudeMode>Absolute</altitudeMode>" +
-                            "</camera>" +
-                            "<style>" +
-                            "<geostyle3d>" +
-                            "<icon/>" +
-                            "<markersize>4.8</markersize>" +
-                            "<markericonscale>1</markericonscale>" +
-                            "<markercolor>RGBA(255,255,255,255)</markercolor>" +
-                            "</geostyle3d>" +
-                            "</style>" +
-                            "<setting>" +
-                            "<turnTime>1.5</turnTime>" +
-                            "<turnSlowly>False</turnSlowly>" +
-                            "<stopPlayMode>StopPause</stopPlayMode>" +
-                            "<autoPlay>False</autoPlay>" +
-                            "<pauseTime>0</pauseTime>" +
-                            "<angularSpeed>1</angularSpeed>" +
-                            "</setting>" +
-                            "</routestop>";
-                    writer.write(fpf);
-                    writer.newLine(); // 写入换行
+        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
+            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+            writer.newLine(); // 写入换行
+            writer.write("<SceneRoute xmlns=\"http://www.supermap.com.cn/ugc60\">");
+            writer.newLine(); // 写入换行
+            writer.write("<route name=\"飞行路线_1\" speed=\"" + speed + "\" lineType=\"0\" showroutestop=\"True\" showrouteline=\"True\" altitudefree=\"False\" headingfree=\"False\" tiltfree=\"False\" flycircle=\"False\" alongline=\"False\">");
+            writer.newLine(); // 写入换行
+            writer.write("<style>");
+            writer.newLine(); // 写入换行
+            writer.write("<geostyle3d>");
+            writer.newLine(); // 写入换行
+            writer.write("<linecolor>RGBA(147,112,219,100)</linecolor>");
+            writer.newLine(); // 写入换行
+            writer.write("<linewidth>2</linewidth>");
+            writer.newLine(); // 写入换行
+            writer.write("<altitudeMode>Absolute</altitudeMode>");
+            writer.newLine(); // 写入换行
+            writer.write("<bottomAltitude>0.00</bottomAltitude>");
+            writer.newLine(); // 写入换行
+            writer.write("</geostyle3d>");
+            writer.newLine(); // 写入换行
+            writer.write("</style>");
+            writer.newLine(); // 写入换行
+            for (int i = 0; i < flightDtoList.size(); i++) {
+                TGdbhFlightDto dto = flightDtoList.get(i);
+                String height = dto.getHeight();
+                if (null != tGdbhFlightBatchDto) {
+                    if (StringUtils.isNotEmpty(tGdbhFlightBatchDto.getHeight())) {
+                        height = tGdbhFlightBatchDto.getHeight();
+                    }
                 }
-                writer.write("</route>");
-                writer.newLine(); // 写入换
-                writer.write("</SceneRoute>");
-                System.out.println("File written successfully!");
-            } catch (IOException e) {
-                System.err.println("Error writing file: " + e.getMessage());
+                String fpf = "<routestop name=\"" + dto.getPhoto_name() + "\" speed=\"0\" excluded=\"False\" viewType=\"camera\">" +
+                        "<camera>" +
+                        "<longitude>" + dto.getLongitude() + "</longitude>" +
+                        "<latitude>" + dto.getLatitude() + "</latitude>" +
+                        "<altitude>" + height + "</altitude>" +
+                        "<heading>" + heading + "</heading>" +
+                        "<tilt>" + tilt + "</tilt>" +
+                        "<altitudeMode>Absolute</altitudeMode>" +
+                        "</camera>" +
+                        "<style>" +
+                        "<geostyle3d>" +
+                        "<icon/>" +
+                        "<markersize>4.8</markersize>" +
+                        "<markericonscale>1</markericonscale>" +
+                        "<markercolor>RGBA(255,255,255,255)</markercolor>" +
+                        "</geostyle3d>" +
+                        "</style>" +
+                        "<setting>" +
+                        "<turnTime>1.5</turnTime>" +
+                        "<turnSlowly>False</turnSlowly>" +
+                        "<stopPlayMode>StopPause</stopPlayMode>" +
+                        "<autoPlay>False</autoPlay>" +
+                        "<pauseTime>0</pauseTime>" +
+                        "<angularSpeed>1</angularSpeed>" +
+                        "</setting>" +
+                        "</routestop>";
+                writer.write(fpf);
+                writer.newLine(); // 写入换行
             }
+            writer.write("</route>");
+            writer.newLine(); // 写入换
+            writer.write("</SceneRoute>");
+            System.out.println("File written successfully!");
+        } catch (IOException e) {
+            System.err.println("Error writing file: " + e.getMessage());
         }
     }