1. ホーム
  2. Java

Javaでオリジナル写真を解析して位置情報を取得する(ソースコード付き、テスト済み、利用可)

2022-03-15 13:15:32
<パス

1. 前提条件

まず、お使いの画像がHDのオリジナル画像であることを確認してください。



次に、画像がアイフォン端末のものであるかどうかを確認します。



3つ目は、撮影時にGPSがオンになっているかを確認することです。



3つのうち1つが欠けている

2. コード環境

A: 必要な Jar パッケージ。
 <dependency>
            <groupId>com.drewnoakes</groupId>
            <artifactId>metadata-extractor</artifactId>
            <version>2.12.0</version>
 </dependency>


B:開発環境

1. maven to introduce jar packages
2.JDK 1.8
3.windows OS


C: コアコード

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;

import java.io.File;
import java.io.IOException;
Iterator; import java.util;

public class PictureTest {
    public static void readPic() {
        System.out.println("Start reading picture information... ");
        File jpegFile = new File("18.jpg");
        Metadata metadata;
        try {
            metadata = JpegMetadataReader.readMetadata(jpegFile);
            Iterator<Directory> it = metadata.getDirectories().iterator();
            while (it.hasNext()) {
                Directory exif = it.next();
                Iterator<Tag> tags = exif.getTags().iterator();
                while (tags.hasNext()) {
                    Tag tag = (Tag) tags.next();
                    System.out.println(tag);
                }
            }
            System.out.println("Image information reading complete! ");
        } catch (JpegProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


D:写真情報抽出の結果。

Start reading the image information...
[JPEG] Compression Type - Baseline
[JPEG] Data Precision - 8 bits
[JPEG] Image Height - 3456 pixels
[JPEG] Image Width - 4608 pixels
[JPEG] Number of Components - 3
[JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 2 horizons/2 vert
[JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
[Exif IFD0] Image Width - 4608 pixels
[Exif IFD0] Image Height - 3456 pixels
[Exif IFD0] Make - OnePlus
[Exif IFD0] Model - ONEPLUS A6010
[Exif IFD0] Orientation - Right side, top (Rotate 90 CW)
[Exif IFD0] X Resolution - 72 dots per inch
[Exif IFD0] Y Resolution - 72 dots per inch
[Exif IFD0] Resolution Unit - Inch
[Exif IFD0] Date/Time - 2019:09:03 10:41:29
[Exif IFD0] YCbCr Positioning - Center of pixel array
[Exif SubIFD] Exposure Time - 1/1445 sec
[Exif SubIFD] F-Number - f/1.7
[Exif SubIFD] Exposure Program - Program normal
[Exif SubIFD] ISO Speed Ratings - 100
[Exif SubIFD] Exif Version - 2.20
[Exif SubIFD] Date/Time Original - 2019:09:03 10:41:29
[Exif SubIFD] Date/Time Digitized - 2019:09:03 10:41:29
[Exif SubIFD] Components Configuration - YCbCr
[Exif SubIFD] Shutter Speed Value - 1/1444 sec
[Exif SubIFD] Aperture Value - f/1.7
[Exif SubIFD] Brightness Value - 3.9
[Exif SubIFD] Exposure Bias Value - 0 EV
[Exif SubIFD] Max Aperture Value - f/1.7
[Exif SubIFD] Metering Mode - Center weighted average
[Exif SubIFD] White Balance - Unknown
[Exif SubIFD] Flash - Flash did not fire, auto
[Exif SubIFD] Focal Length - 4.3 mm
[Exif SubIFD] Sub-Sec Time - 260556
[Exif SubIFD] Sub-Sec Time Original - 260556
[Exif SubIFD] Sub-Sec Time Digitized - 260556
[Exif SubIFD] FlashPix Version - 1.00
[Exif SubIFD] Color Space - sRGB
[Exif SubIFD] Exif Image Width - 4608 pixels
[Exif SubIFD] Exif Image Height - 3456 pixels
[Exif SubIFD] Sensing Method - (Not defined)
[Exif SubIFD] Scene Type - Directly photographed image
[Exif SubIFD] Exposure Mode - Auto exposure
[Exif SubIFD] White Balance Mode - Auto white balance
[Exif SubIFD] Focal Length 35 - 25 mm
[Exif SubIFD] Scene Capture Type - Standard
[Interoperability] Interoperability Index - Recommended Exif Interoperability Rules (ExifR98)
[Interoperability] Interoperability Version - 1.00
[GPS] GPS Latitude Ref - N
[GPS] GPS Latitude - 30° 18' 31.31"
[GPS] GPS Longitude Ref - E
[GPS] GPS Longitude - 120° 20' 36.31"
[GPS] GPS Altitude Ref - Sea level
[GPS] GPS Altitude - 0 metres
[GPS] GPS Time-Stamp - 02:41:28.000 UTC
[GPS] GPS Processing Method - CELLID
[GPS] GPS Date-Stamp - 2019:09:03
[Exif Thumbnail] Exif Image Width - 320 pixels
[Exif Thumbnail] Exif Image Height - 240 pixels
[Exif Thumbnail] Compression - JPEG (old-style)
[Exif Thumbnail] Orientation - Right side, top (Rotate 90 CW)
[Exif Thumbnail] X Resolution - 72 dots per inch
[Exif Thumbnail] Y Resolution - 72 dots per inch
[Exif Thumbnail] Resolution Unit - Inch
[Exif Thumbnail] Thumbnail Offset - 1104 bytes
[Exif Thumbnail] Thumbnail Length - 38449 bytes
[XMP] XMP Value Count - 5
[Huffman] Number of Tables - 4 Huffman tables
[File] File Name - 18.jpg
[File] File Size - 7027316 bytes
[File] File Modified Date - Tue Sep 03 10:55:39 +08:00 2019
Image information read complete!



意味ありげなメッセージのインターセプト

[GPS] GPS Latitude Ref - N                  
[GPS] GPS Latitude - 30° 18' 31.31" dimension
[GPS] GPS Longitude Ref - E
[GPS] GPS Longitude - 120° 20' 36.31" Longitude
[GPS] GPS Altitude Ref - Sea level
[GPS] GPS Altitude - 0 metres
[GPS] GPS Time-Stamp - 02:41:28.000 UTC Shooting Time
[GPS] GPS Processing Method - CELLID
[GPS] GPS Date-Stamp - 2019:09:03 Recording time

[Exif IFD0] Make - OnePlus Device Information
[Exif IFD0] Model - ONEPLUS A6010 Device Model


緯度・経度に基づいた検索結果。

元記事へのリンクとソースコードのダウンロード

元記事へのリンク: https://www.cnblogs.com/haha12/p/11451009.html



GPS位置情報検索リンク: http://www.gpsspg.com/maps.htm



緯度・経度フォーマットの変換リンク:http://www.minigps.net/fc.html



コードのダウンロードアドレスです。[送信元アドレス](https://download.csdn.net/download/qq_37040173/11654357) [送信元アドレス](https://download.csdn.net/download/qq_37040173/ 11654357)