diff --git a/pom.xml b/pom.xml index 0ae5ca0..13abb4d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,3 @@ - 4.0.0 osm.surveyor @@ -20,8 +19,8 @@ - ReStamp - http://surveyor.mydns.jp/gitbucket/yuu/Restamp/wiki + ReStamp-gui + http://surveyor.mydns.jp/gitbucket/yuu/Restamp-gui/wiki @@ -41,8 +40,7 @@ osm.surveyor ReStamp - 3.2 - jar + 3.3 org.apache.commons @@ -173,4 +171,4 @@ - \ No newline at end of file + diff --git a/src/main/java/osm/surveyor/matchtime/AppParameters.java b/src/main/java/osm/surveyor/matchtime/AppParameters.java deleted file mode 100644 index e4ef115..0000000 --- a/src/main/java/osm/surveyor/matchtime/AppParameters.java +++ /dev/null @@ -1,102 +0,0 @@ -package osm.surveyor.matchtime; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -@SuppressWarnings("serial") -public class AppParameters extends Properties { - static final String FILE_PATH = "AdjustTime.ini"; - - // GPX: ファイル更新時刻 yyyy:MM:dd HH:mm:ss - public static String IMG_TIME = "IMG.TIME"; - - // 対象IMGフォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ) - public static String IMG_SOURCE_FOLDER = "IMG.SOURCE_FOLDER"; - - // 基準時刻画像(正確な撮影時刻が判明できる画像) - public static String IMG_BASE_FILE = "IMG.BASE_FILE"; - - // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ) - public static String IMG_OUTPUT_FOLDER = "IMG.OUTPUT_FOLDER"; - - // 出力OverwriteToSource: 入力ファイルに上書きする {ON | OFF} - public static String OUTPUT_OVERWRITE_TO_SOURCE= "IMG.OUTPUT_OVERWRITE_TO_SOURCE"; - - File file; - - public AppParameters() throws FileNotFoundException, IOException { - super(); - this.file = new File(FILE_PATH); - syncFile(); - } - - public AppParameters(Properties defaults) throws FileNotFoundException, IOException { - super(defaults); - this.file = new File(FILE_PATH); - syncFile(); - } - - public AppParameters(String iniFileName) throws FileNotFoundException, IOException { - super(); - this.file = new File(iniFileName); - syncFile(); - } - - private void syncFile() throws FileNotFoundException, IOException { - boolean update = false; - - if (this.file.exists()) { - // ファイルが存在すれば、その内容をロードする。 - this.load(new FileInputStream(file)); - } - else { - update = true; - } - - //------------------------------------------------ - // 対象フォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ) - String valueStr = this.getProperty(IMG_SOURCE_FOLDER); - if (valueStr == null) { - update = true; - this.setProperty(IMG_SOURCE_FOLDER, (new File(".")).getAbsolutePath()); - } - - //------------------------------------------------ - // 基準時刻画像(正確な撮影時刻が判明できる画像) - valueStr = this.getProperty(IMG_BASE_FILE); - if (valueStr == null) { - update = true; - this.setProperty(IMG_BASE_FILE, ""); - } - - //------------------------------------------------ - // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ) - valueStr = this.getProperty(IMG_OUTPUT_FOLDER); - if (valueStr == null) { - update = true; - this.setProperty(IMG_OUTPUT_FOLDER, (new File(".")).getAbsolutePath()); - } - - //------------------------------------------------ - // 出力: 入力ファイルに上書きする {ON | OFF} - valueStr = this.getProperty(OUTPUT_OVERWRITE_TO_SOURCE); - if (valueStr == null) { - update = true; - this.setProperty(OUTPUT_OVERWRITE_TO_SOURCE, String.valueOf(false)); - } - - if (update) { - // ・ファイルがなければ新たに作る - // ・項目が足りない時は書き足す。 - //this.store(new FileOutputStream(this.file), "defuilt settings"); - } - } - - public void store() throws FileNotFoundException, IOException { - this.store(new FileOutputStream(this.file), "by Restamp"); - } -} diff --git a/src/main/java/osm/surveyor/matchtime/Restamp.java b/src/main/java/osm/surveyor/matchtime/Restamp.java deleted file mode 100644 index d25f2e9..0000000 --- a/src/main/java/osm/surveyor/matchtime/Restamp.java +++ /dev/null @@ -1,277 +0,0 @@ -package osm.surveyor.matchtime; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.ResourceBundle; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.commons.imaging.ImageReadException; - -/** - * 動画から一定間隔で切り出したIMAGEファイルの更新日時を書き換える - * - * @author yuu - */ -public class Restamp extends Thread { - static public final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss z"; - - /** - * 実行中に発生したExceptionを保持する場所 - */ - public Exception ex = null; - - /** - * ログ設定プロパティファイルのファイル内容 - */ - protected static final String LOGGING_PROPERTIES_DATA - = "handlers=java.util.logging.ConsoleHandler\n" - + ".level=FINEST\n" - + "java.util.logging.ConsoleHandler.level=INFO\n" - + "java.util.logging.ConsoleHandler.formatter=osm.jp.gpx.YuuLogFormatter"; - - /** - * メイン - * 動画から一定間隔で切り出したIMAGEのファイル更新日時を書き換える - * - * ・画像ファイルの更新日付を書き換えます。(Exi情報は無視します) - * ※ 指定されたディレクトリ内のすべての'*.jpg'ファイルを処理の対象とします - * ・画像は連番形式(名前順に並べられること)の名称となっていること - * - * 1.予め、動画から画像を切り出す - * ソースファイル(mp4ファイル); 「-i 20160427_104154.mp4」 - * 出力先: 「-f image2 img/%06d.jpg」 imgフォルダに6桁の連番ファイルを差出力する - * 切り出し開始秒数→ 「-ss 0」 (ファイルの0秒から切り出し開始) - * 切り出し間隔; 「-r 30」 (1秒間隔=30fps間隔) - * ``` - * $ cd /home/yuu/Desktop/OSM/20180325_横浜新道 - * $ ffmpeg -ss 0 -i 20160427_104154.mp4 -f image2 -r 15 img/%06d.jpg - * ``` - * - * 2. ファイルの更新日付を書き換える - * ``` - * $ cd /home/yuu/Desktop/workspace/AdjustTime/importPicture/dist - * $ java -cp .:AdjustTime2.jar osm.jp.gpx.Restamp /home/yuu/Desktop/OSM/20180325_横浜新道/img 000033.jpg 2018-03-25_12:20:32 003600.jpg 2018-03-25_13:20:09 - * ``` - * - * exp) $ java -jar Restamp.jar argv[0] argv[1] argv[2] argv[3] argv[4] - * exp) $ java -jar Restamp.jar argv[0] argv[1] argv[2] argv[3] argv[4] argv[5] - * - * @param argv - * argv[0] = 画像ファイルが格納されているディレクトリ --> imgDir - * argv[1] = 時刻補正の基準とする画像ファイル --> baseFile1 - * argv[2] = 基準画像ファイルの精確な撮影日時 "yyyy-MM-dd HH:mm:ss z" --> baseTime1 - * argv[3] = 時刻補正の基準とする画像ファイル --> baseFile2 - * argv[4] = 基準画像ファイルの精確な撮影日時 "yyyy-MM-dd HH:mm:ss z" --> baseTime2 - * argv[5] = (option)変換済み画像ファイルの出力フォルダ.省略した場合は元画像を直接上書きする --> outputDir - * @throws ImageReadException - */ - public static void main(String[] argv) throws Exception - { - if (argv.length < 5) { - System.out.println("java osm.surveyor.matchtime.Restamp "); - System.out.println("java osm.surveyor.matchtime.Restamp "); - return; - } - - Path imgDir = Paths.get(argv[0]); - - Path outDir = imgDir; - if (argv.length >= 6) { - outDir = Paths.get(argv[5]); - } - - Path baseFile1 = Paths.get(imgDir.toString(), argv[1]); - - DateFormat df1 = new SimpleDateFormat(TIME_PATTERN); - Date baseTime1 = df1.parse(argv[2]); - Date baseTime2 = df1.parse(argv[4]); - - Path baseFile2 = Paths.get(imgDir.toString(), argv[3]); - - Restamp obj = new Restamp(); - if (obj.setUp(imgDir, baseFile1, baseTime1, baseFile2, baseTime2, outDir)) { - obj.start(); - try { - obj.join(); - } catch(InterruptedException end) {} - if (obj.ex != null) { - throw obj.ex; - } - } - } - - Path imgDir; - Path outDir; - Date baseTime1; - Date baseTime2; - Path baseFile1; - Path baseFile2; - public static ResourceBundle i18n = ResourceBundle.getBundle("i18n"); - - /** - * パラメータの設定とチェック - * @param imgDir - * @param baseFile1 - * @param baseTime1 - * @param baseFile2 - * @param baseTime2 - * @param outDir - * @return パラメータチェックに合格すればtrue - * @throws Exception - */ - public boolean setUp( - Path imgDir, - Path baseFile1, Date baseTime1, - Path baseFile2, Date baseTime2, - Path outDir) throws Exception { - this.imgDir = imgDir; - this.outDir = outDir; - this.baseTime1 = baseTime1; - this.baseTime2 = baseTime2; - this.baseFile1 = baseFile1; - this.baseFile2 = baseFile2; - - // のチェック - if (!Files.exists(imgDir)) { - // "[error] が存在しません。" - System.out.println(i18n.getString("msg.200")); - return false; - } - if (!Files.isDirectory(imgDir)) { - // "[error] がフォルダじゃない" - System.out.println(i18n.getString("msg.210")); - return false; - } - - // のチェック - if (Files.exists(outDir)) { - if (!Files.isDirectory(outDir)) { - // "[error] <出力先フォルダ>はフォルダじゃない" - System.out.println(i18n.getString("msg.270")); - return false; - } - } - else { - // "[error] は存在しません。" - try { - Files.createDirectories(outDir); - } - catch (IOException e) { - System.out.println(i18n.getString("msg.275")); - return false; - } - } - if (!Files.isWritable(outDir)) { - // "[error] <出力先フォルダ>には書き込みできません" - System.out.println(i18n.getString("msg.275")); - return false; - } - - // のチェック - if (!Files.exists(baseFile1)) { - // "[error] が存在しません。" - System.out.println(i18n.getString("msg.220")); - return false; - } - if (!Files.isRegularFile(baseFile1)) { - // "[error] がファイルじゃない" - System.out.println(i18n.getString("msg.230")); - return false; - } - - // のチェック - if (!Files.exists(baseFile2)) { - // "[error] が存在しません。" - System.out.println(i18n.getString("msg.240")); - return false; - } - if (!Files.isRegularFile(baseFile2)) { - // "[error] がファイルじゃない" - System.out.println(i18n.getString("msg.250")); - return false; - } - - return true; - } - - @Override - public void run() { - int bCount1 = 0; - int bCount2 = 0; - boolean base1 = false; - boolean base2 = false; - ArrayList jpgFiles = new ArrayList<>(); - - // 指定されたディレクトリ内のJPEGファイルすべてを対象とする - try (Stream files = Files.list(Paths.get(imgDir.toString()))){ - List sortedList = files.sorted(Comparator.naturalOrder()).collect(Collectors.toList()); - - for (Path p : sortedList) { - if (Files.exists(p) && Files.isRegularFile(p)) { - String filename = p.getFileName().toString(); - if (filename.toUpperCase().endsWith(".JPG")) { - jpgFiles.add(p); - bCount1 += (base1 ? 0 : 1); - bCount2 += (base2 ? 0 : 1); - if (p.getFileName().equals(baseFile1.getFileName())) { - base1 = true; - } - if (p.getFileName().equals(baseFile2.getFileName())) { - base2 = true; - } - } - } - } - if (!jpgFiles.isEmpty()) { - DateFormat df2 = new SimpleDateFormat(TIME_PATTERN); - - // imgDir内の画像ファイルを処理する - long span = this.baseTime2.getTime() - this.baseTime1.getTime(); - span = span / (bCount2 - bCount1); - int i = 0; - System.out.println("-------------------------------"); - System.out.println("Update last modified date time."); - for (Path jpgFile : jpgFiles) { - long deltaMsec = (i - (bCount1 -1)) * span; - i++; - Calendar cal = Calendar.getInstance(); - cal.setTime(this.baseTime1); - cal.add(Calendar.MILLISECOND, (int) deltaMsec); - System.out.println(String.format("\t%s --> %s", df2.format(cal.getTime()), jpgFile.getFileName())); - - //------------------------------------------ - // ファイルをコピーして更新日時を変更する - //------------------------------------------ - try { - Path outFile; - if (outDir.equals(imgDir)) { - outFile = jpgFile; - } - else { - outFile = Paths.get(outDir.toString(), jpgFile.toFile().getName()); - Files.copy(jpgFile, outFile); - } - outFile.toFile().setLastModified(cal.getTimeInMillis()); - } - catch (Exception e) { - System.out.println("[ERROR] Can not convert."+ e.toString()); - } - } - System.out.println("-------------------------------"); - } - } - catch(IOException e) { - e.printStackTrace(); - this.ex = new Exception(e); - } - } -} \ No newline at end of file diff --git a/src/main/java/osm/surveyor/util/Exif.java b/src/main/java/osm/surveyor/util/Exif.java deleted file mode 100644 index a7ac358..0000000 --- a/src/main/java/osm/surveyor/util/Exif.java +++ /dev/null @@ -1,80 +0,0 @@ -package osm.surveyor.util; - -import java.io.*; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; - -public class Exif extends Thread { - public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private static final String EXIF_DATE_TIME_FORMAT_STRING = "yyyy:MM:dd HH:mm:ss"; - - /** - * 対象は '*.JPG' のみ対象とする - * @return - * @param name - */ - public static boolean checkFile(String name) { - return ((name != null) && name.toUpperCase().endsWith(".JPG")); - } - - /** - * DateをEXIFの文字列に変換する。 - * 注意:EXiFの撮影時刻はUTC時間ではない - * @param localdate - * @return - */ - public static String toEXIFString(Date localdate) { - DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING); - return dfUTC.format(localdate); - } - - /** - * EXIFの文字列をDateに変換する。 - * 注意:EXiFの撮影時刻はUTC時間ではない - * @param timeStr - * @return - * @throws ParseException - */ - public static Date toEXIFDate(String timeStr) throws ParseException { - DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING); - //dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.parse(timeStr); - } - - public static String toUTCString(Date localdate) { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.format(localdate); - } - - public static Date toUTCDate(String timeStr) throws ParseException { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.parse(timeStr); - } - - static String getShortPathName(File dir, File iFile) { - String dirPath = dir.getAbsolutePath(); - String filePath = iFile.getAbsolutePath(); - if (filePath.startsWith(dirPath)) { - return filePath.substring(dirPath.length()+1); - } - else { - return filePath; - } - } - - /** - * JPEGファイルフィルター - * @author yuu - */ - class JpegFileFilter implements FilenameFilter { - @Override - public boolean accept(File dir, String name) { - return name.toUpperCase().matches(".*\\.JPG$"); - } - } -} \ No newline at end of file diff --git a/src/main/java/osm/surveyor/util/GeoDistance.java b/src/main/java/osm/surveyor/util/GeoDistance.java deleted file mode 100644 index 960794f..0000000 --- a/src/main/java/osm/surveyor/util/GeoDistance.java +++ /dev/null @@ -1,71 +0,0 @@ -package osm.surveyor.util; - -/** - * The MIT License (MIT) - * Copyright(C) 2007-2012 やまだらけ - * http://yamadarake.jp/trdi/report000001.html - * 「Cords.java」を改変 - * 2016-10-03 - * - * @author やまだらけ yama_darake@yahoo.co.jp - * - */ -public class GeoDistance { - - public static final double GRS80_A = 6378137.000; // 赤道半径(m) - public static final double GRS80_E2 = 0.00669438002301188; - public static final double GRS80_MNUM = 6335439.32708317; // - - public static final double WGS84_A = 6378137.000; - public static final double WGS84_E2 = 0.00669437999019758; - public static final double WGS84_MNUM = 6335439.32729246; - - /** - * 角度(180度)をラジアン(2π)に変換する - * @param deg - * @return - */ - public static double deg2rad(double deg){ - return deg * Math.PI / 180.0; - } - - /** - * 距離(m)を返す - * @param lat1 - * @param lng1 - * @param lat2 - * @param lng2 - * @return - */ - public static double calcDistHubeny(double lat1, double lng1, - double lat2, double lng2){ - double my = deg2rad((lat1 + lat2) / 2.0); // 平均緯度 - double dy = deg2rad(lat1 - lat2); // 2点間の緯度 - double dx = deg2rad(lng1 - lng2); // 2点間の経度 - - double sin = Math.sin(my); - double w = Math.sqrt(1.0 - GRS80_E2 * sin * sin); - double m = GRS80_MNUM / (w * w * w); - double n = GRS80_A / w; - - double dym = dy * m; - double dxncos = dx * n * Math.cos(my); - - return Math.sqrt(dym * dym + dxncos * dxncos); - } - - - public static void main(String[] args){ - System.out.println("Coords Test Program"); - double lat1, lng1, lat2, lng2; - - lat1 = Double.parseDouble(args[0]); - lng1 = Double.parseDouble(args[1]); - lat2 = Double.parseDouble(args[2]); - lng2 = Double.parseDouble(args[3]); - - double d = calcDistHubeny(lat1, lng1, lat2, lng2); - - System.out.println("Distance = " + d + " m"); - } -} \ No newline at end of file diff --git a/src/main/java/osm/surveyor/util/TimeComparator.java b/src/main/java/osm/surveyor/util/TimeComparator.java deleted file mode 100644 index c6997e0..0000000 --- a/src/main/java/osm/surveyor/util/TimeComparator.java +++ /dev/null @@ -1,21 +0,0 @@ -package osm.surveyor.util; - -import java.util.Comparator; -import java.util.Date; - -/** - * java.util.Date型をコレクションのKEYにした時に、時間順に並べ替える - * - */ -public class TimeComparator implements Comparator -{ - /** - * 日付順にソート - * @param arg0 - * @param arg1 - */ - @Override - public int compare(Date arg0, Date arg1) { - return arg0.compareTo(arg1); - } -} diff --git a/src/main/java/osm/surveyor/util/YuuLogFormatter.java b/src/main/java/osm/surveyor/util/YuuLogFormatter.java deleted file mode 100644 index f78bf16..0000000 --- a/src/main/java/osm/surveyor/util/YuuLogFormatter.java +++ /dev/null @@ -1,48 +0,0 @@ -package osm.surveyor.util; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -/** - * シンプルなサンプルログフォーマッタ - */ -public class YuuLogFormatter extends Formatter { - private final SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - - @Override - public String format(final LogRecord argLogRecord) { - final StringBuffer buf = new StringBuffer(); - - buf.append(sdFormat.format(new Date(argLogRecord.getMillis()))).append(" "); - - if (argLogRecord.getLevel() == Level.FINEST) { - buf.append("[FINEST]"); - } - else if (argLogRecord.getLevel() == Level.FINER) { - buf.append("[FINER]"); - } - else if (argLogRecord.getLevel() == Level.FINE) { - buf.append("[FINE]"); - } - else if (argLogRecord.getLevel() == Level.CONFIG) { - buf.append("[CONFIG]"); - } - else if (argLogRecord.getLevel() == Level.INFO) { - buf.append("[INFO]"); - } - else if (argLogRecord.getLevel() == Level.WARNING) { - buf.append("[WARN]"); - } - else if (argLogRecord.getLevel() == Level.SEVERE) { - buf.append("[SEVERE]"); - } - else { - buf.append(Integer.toString(argLogRecord.getLevel().intValue())).append(" "); - } - buf.append(" ").append(argLogRecord.getMessage()).append("\n"); - return buf.toString(); - } -} \ No newline at end of file