add exif lib

This commit is contained in:
Tykayn 2023-08-14 16:55:58 +02:00 committed by tykayn
parent 94893e5240
commit 1468f0387c

View File

@ -2,6 +2,9 @@
conversion de données gpx conversion de données gpx
conversion de données exif conversion de données exif
**/ **/
// @ts-ignore
import piexif, { IExif, IExifElement, TagValues } from 'piexif';
import * as fs from 'node:fs'; import * as fs from 'node:fs';
// @ts-ignore // @ts-ignore
import path from "node:path"; 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", // "6102537", "6102569", "6127433", "6133465", "6242729", "6329129", "6329177", "6329241", "6329305", "6329321", "6738633", "6738809", "6738953", "6752761",
// "6752889", // "6752889",
// "6752905", // "6752905",
"6752921", // "6752921",
"6752937", "6752937",
// "6752953", "6760985", "6761049", "6761289", "6794633", "7325929", "7326457", "7328265", "7330009", "7330025", // "6752953", "6760985", "6761049", "6761289", "6794633", "7325929", "7326457", "7328265", "7330009", "7330025",
// "7330041", // "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 dossier_gpx_input: string = folder + "metadata_file"
let path_gpx_input: string = dossier_gpx_input + "/" + sequence_name + "/" + file_gpx 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 gpxData: any = {}
let tableKartaviewTrace: any = []
function makeGpxFromKartaview(tableKartaviewTrace: any) { function makeGpxFromKartaview(tableKartaviewTrace: any) {
@ -113,29 +115,43 @@ function reduceGpxPointsToInterval(sequence_name: any) {
let interval = Math.round(gpxData[sequence_name].length / photos_count_in_sequence) let interval = Math.round(gpxData[sequence_name].length / photos_count_in_sequence)
let ii = 1; let ii = 1;
console.log('--------- sequence_name', sequence_name) 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') console.log('--------- interval: prendre une donnée gps tous les ', interval, 'points de la trace de séquence')
let jj=0 let jj = 0
let photo_counter = 0 let photo_counter = 0
gpxData[sequence_name].forEach((elem: any) => { gpxData[sequence_name].forEach((elem: any) => {
// only work on an interval of files to assign gps coordinates // only work on an interval of files to assign gps coordinates
jj++ jj++
ii-- ii--
if(ii<=0){ if (ii <= 0) {
// set the gps coordinates to the picture in sequence // set the gps coordinates to the picture in sequence
let timestamp = elem[6] * 1000 let timestamp = elem[6] * 1000
let lat = elem[0] let lat = elem[0]
let lon = elem[1] let lon = elem[1]
let date = new Date(timestamp) let date = new Date(timestamp)
let iso = date.toISOString() let iso = date.toISOString()
console.log('* point de trace n°', jj) // console.log('* point de trace n°', jj)
console.log('* lat, lon', lat,lon) // console.log('* lat, lon', lat,lon)
console.log('* date iso', iso) // console.log('* date iso', iso)
ii =interval*1 ii = interval * 1
photo_counter++
let exif = {};
exif[piexif.ExifIFD.DateTimeOriginal] = iso;
let file_photo_name = photo_folders_counter[sequence_name][photo_counter] 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++
} }
}) })
@ -183,7 +199,7 @@ function openKartaviewTxtGPX(filepath: any, sequence_name: string) {
writeFile('' + fileName + '_trace.gpx', content_gpx) writeFile('' + fileName + '_trace.gpx', content_gpx)
} }
if(Object.keys(gpxData).length === folders_list_txt.length){ if (Object.keys(gpxData).length === folders_list_txt.length) {
gather() gather()
} }
// console.log('gpx_content', gpx_content) // console.log('gpx_content', gpx_content)
@ -193,8 +209,6 @@ function openKartaviewTxtGPX(filepath: any, sequence_name: string) {
let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd())
let expandedFileList: any = []
/** /**
* get a list of all files in a path * get a list of all files in a path
* @param folderPath * @param folderPath
@ -204,31 +218,10 @@ async function getAllFilesInFolder(folderPath: string) {
console.log('reading folder ', folderPath) console.log('reading folder ', folderPath)
filesList = fs.readdirSync(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; 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) { function writeFile(fileName: string, fileContent: any) {
console.log('write file', fileName) console.log('write file', fileName)
@ -248,17 +241,9 @@ let photo_folders_counter: any = {}
function listPhotos(sequence_number: string) { function listPhotos(sequence_number: string) {
let photo_folder = dossier_photo + '/' + sequence_number; 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) getAllFilesInFolder(photo_folder)
.then(listOfFiles => { .then(listOfFiles => {
// console.log('listOfFiles', listOfFiles)
photo_folders_counter[sequence_number] = 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) => { * runs after all sequences have gotten their photo and gpx data
getGPXAndEnrichExifOfPhotosInFolder(elem).then(r => { */
console.log('r', r)
}
)
})
function gather() { 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()