add exif lib
This commit is contained in:
parent
94893e5240
commit
1468f0387c
@ -2,6 +2,9 @@
|
||||
conversion de données gpx
|
||||
conversion de données exif
|
||||
**/
|
||||
|
||||
// @ts-ignore
|
||||
import piexif, { IExif, IExifElement, TagValues } from 'piexif';
|
||||
import * as fs from 'node:fs';
|
||||
// @ts-ignore
|
||||
import path from "node:path";
|
||||
@ -22,7 +25,7 @@ let folders_list_txt: any = [
|
||||
// "6102537", "6102569", "6127433", "6133465", "6242729", "6329129", "6329177", "6329241", "6329305", "6329321", "6738633", "6738809", "6738953", "6752761",
|
||||
// "6752889",
|
||||
// "6752905",
|
||||
"6752921",
|
||||
// "6752921",
|
||||
"6752937",
|
||||
// "6752953", "6760985", "6761049", "6761289", "6794633", "7325929", "7326457", "7328265", "7330009", "7330025",
|
||||
// "7330041",
|
||||
@ -51,7 +54,7 @@ if (mini_arguments['gpx-input']) {
|
||||
}
|
||||
|
||||
|
||||
let dossier_photo: string = folder + "photo"
|
||||
let dossier_photo: string = folder + "test_photo_apply"
|
||||
let dossier_gpx_input: string = folder + "metadata_file"
|
||||
let path_gpx_input: string = dossier_gpx_input + "/" + sequence_name + "/" + file_gpx
|
||||
|
||||
@ -61,7 +64,6 @@ if (mini_arguments['gpx-input-path']) {
|
||||
|
||||
|
||||
let gpxData: any = {}
|
||||
let tableKartaviewTrace: any = []
|
||||
|
||||
|
||||
function makeGpxFromKartaview(tableKartaviewTrace: any) {
|
||||
@ -113,6 +115,8 @@ function reduceGpxPointsToInterval(sequence_name: any) {
|
||||
let interval = Math.round(gpxData[sequence_name].length / photos_count_in_sequence)
|
||||
let ii = 1;
|
||||
console.log('--------- sequence_name', sequence_name)
|
||||
console.log('--------- nombre de photos ', photos_count_in_sequence)
|
||||
console.log('--------- nombre de points gpx ', gpxData[sequence_name].length)
|
||||
console.log('--------- interval: prendre une donnée gps tous les ', interval, 'points de la trace de séquence')
|
||||
let jj = 0
|
||||
let photo_counter = 0
|
||||
@ -127,15 +131,27 @@ function reduceGpxPointsToInterval(sequence_name: any) {
|
||||
let lon = elem[1]
|
||||
let date = new Date(timestamp)
|
||||
let iso = date.toISOString()
|
||||
console.log('* point de trace n°', jj)
|
||||
console.log('* lat, lon', lat,lon)
|
||||
console.log('* date iso', iso)
|
||||
// console.log('* point de trace n°', jj)
|
||||
// console.log('* lat, lon', lat,lon)
|
||||
// console.log('* date iso', iso)
|
||||
ii = interval * 1
|
||||
photo_counter++
|
||||
|
||||
let exif = {};
|
||||
|
||||
exif[piexif.ExifIFD.DateTimeOriginal] = iso;
|
||||
|
||||
|
||||
|
||||
let file_photo_name = photo_folders_counter[sequence_name][photo_counter]
|
||||
console.log('file_photo_name to apply exif data', file_photo_name)
|
||||
console.log('file_photo_name to apply exif data', photo_counter, file_photo_name)
|
||||
if (file_photo_name) {
|
||||
// set exif data
|
||||
|
||||
// https://piexifjs.readthedocs.io/en/latest/functions.html#insert
|
||||
// piexif.insert(exifStr, jpegData)
|
||||
|
||||
}
|
||||
photo_counter++
|
||||
}
|
||||
|
||||
})
|
||||
@ -193,8 +209,6 @@ function openKartaviewTxtGPX(filepath: any, sequence_name: string) {
|
||||
|
||||
let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd())
|
||||
|
||||
let expandedFileList: any = []
|
||||
|
||||
/**
|
||||
* get a list of all files in a path
|
||||
* @param folderPath
|
||||
@ -204,31 +218,10 @@ async function getAllFilesInFolder(folderPath: string) {
|
||||
|
||||
console.log('reading folder ', folderPath)
|
||||
filesList = fs.readdirSync(folderPath);
|
||||
// console.log('readSubdirectories - files', folderPath, filesList.length)
|
||||
|
||||
// filesList.forEach((subDirOrFile:any) => {
|
||||
// const newFullPath = cwd + '/' + subDirOrFile
|
||||
//
|
||||
// if (fs.existsSync(newFullPath)) {
|
||||
// const s = fs.statSync(newFullPath)
|
||||
//
|
||||
// if (s.isFile()) {
|
||||
// expandedFileList.push(cwd + '/' + subDirOrFile)
|
||||
// console.log('add file', cwd + '/' + subDirOrFile)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
return filesList;
|
||||
|
||||
}
|
||||
|
||||
function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) {
|
||||
listOfFiles.forEach((elem: any) => {
|
||||
// find corresponding timestamp
|
||||
// add exif info
|
||||
// save file
|
||||
})
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, fileContent: any) {
|
||||
console.log('write file', fileName)
|
||||
@ -248,17 +241,9 @@ let photo_folders_counter: any = {}
|
||||
|
||||
function listPhotos(sequence_number: string) {
|
||||
let photo_folder = dossier_photo + '/' + sequence_number;
|
||||
|
||||
let gps_points = gpxData[sequence_number]
|
||||
// console.log('gps_points', gps_points)
|
||||
// pour réconcilier les données, on divise la trace en part égales du nombre de photos présentes dans la séquence.
|
||||
|
||||
getAllFilesInFolder(photo_folder)
|
||||
.then(listOfFiles => {
|
||||
|
||||
// console.log('listOfFiles', listOfFiles)
|
||||
photo_folders_counter[sequence_number] = listOfFiles
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -282,15 +267,9 @@ async function getGPXAndEnrichExifOfPhotosInFolder(sequence_number: string) {
|
||||
|
||||
}
|
||||
|
||||
console.log('dossiers à traiter: ', folders_list_txt.length)
|
||||
folders_list_txt.forEach((elem: string) => {
|
||||
getGPXAndEnrichExifOfPhotosInFolder(elem).then(r => {
|
||||
console.log('r', r)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* runs after all sequences have gotten their photo and gpx data
|
||||
*/
|
||||
function gather() {
|
||||
|
||||
|
||||
@ -303,3 +282,18 @@ function gather() {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
console.log('dossiers à traiter: ', folders_list_txt.length)
|
||||
folders_list_txt.forEach((elem: string) => {
|
||||
getGPXAndEnrichExifOfPhotosInFolder(elem).then(r => {
|
||||
console.log('r', r)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// run it all
|
||||
main()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user