Introduction

Photograps acquired with

Analysis of the folders where photos are achived

library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(fs)
library(fst)

base_dir_main <- "/media/nfs/SpRiViFo/foto_rilievi"
base_dir_tmp <- "/home/piccolomatteo/Scrivania/foto_rilievi"
base_dir <- c(base_dir_main, base_dir_tmp)
#base_dir <- "/media/nfs/SpRiViFo/foto_rilievi/20180702/fc76_77"
# base_dir <- "E:/Foto rilievo"
# base_dir <- "C:/Users/ro/Pictures/Foto/ALBUM"
# base_dir <- "C:/Users/ro/Pictures/Foto/ALBUM/2016WeekVenturina_conOrlando"

# PhotoDir <- tibble(path0 = dir_ls(base_dir, rec=T, glob=c("*.jpg", "*.JPG")),
PhotoDir <- tibble(path0 = dir_ls(base_dir, rec=T, regexp = "jpg|JPG"),
                   path1 = path_rel(path_rel(path0, base_dir)),
                   folder = dirname(path1),
                   photoFile = basename(path1)
                   ) %>%
  filter(folder != "Rotelle") %>%
  rowid_to_column("ID")
## Warning in if (is.na(start)) {: la condizione la lunghezza > 1 e solo il
## promo elemento verrĂ  utilizzato
write_fst(PhotoDir, "PhotoDir.fst")

Extract EXIF data

library(stringr)

pp <- "/media/nfs/SpRiViFo/foto_rilievi/20180702/fc76_77/IMG_0038.JPG"
# pp <- " C:\\Users\\ro\\Pictures\\Foto\\ALBUM\\2017Natale\\Refrancoreimage1.JPG"

exiftool_cmd <- "exiftool"
# exiftool_cmd <- "C:\\Users\\ro\\Documents\\R\\win-library\\3.5\\exiftoolr\\exiftool\\win_exe\\exiftool"
if(system(paste(exiftool_cmd, "-ver")) == 127L) stop("'exiftool' command not found!")

read_exif0 <- function(photo.path, cmd=exiftool_cmd) system(paste(cmd, photo.path), intern = TRUE)

head(read_exif0(pp))
## [1] "ExifTool Version Number         : 10.10"                                            
## [2] "File Name                       : IMG_0038.JPG"                                     
## [3] "Directory                       : /media/nfs/SpRiViFo/foto_rilievi/20180702/fc76_77"
## [4] "File Size                       : 5.2 MB"                                           
## [5] "File Modification Date/Time     : 2018:07:02 09:40:52+02:00"                        
## [6] "File Access Date/Time           : 2018:10:13 00:57:42+02:00"
read_exif <- function(photo.path, cmd=exiftool_cmd) {
  x <- photo.path %>%
  # Warning: if path contains spaces 'exiftool' will search for each 'word'!
    paste(cmd, .) %>%
    system(intern = TRUE) %>%
    str_split(":", 2) %>%
    unlist %>%
    matrix(ncol = 2, byrow = T) 
  tibble(field = x[,1], value = x[,2]) %>%
  return
}


# I am afraid it will be long!!
t0 <- Sys.time()
cat(paste("In folder", base_dir, "there are", nrow(PhotoDir),"files.\n"))
## In folder /media/nfs/SpRiViFo/foto_rilievi there are 13143 files.
##  In folder /home/piccolomatteo/Scrivania/foto_rilievi there are 13143 files.
cat(paste("   Exif data acquisition started at:", t0, "\n"))
##    Exif data acquisition started at: 2018-10-13 13:26:29
ExifData <- PhotoDir %>%
  mutate(exif_df = map(path0, read_exif)) %>%
  select(ID, exif_df) %>%
  unnest
t1 <- Sys.time()
cat(paste("Exif acquisition ended at", t1,", elapsed time:", (t1 - t0)))
## Exif acquisition ended at 2018-10-13 13:55:38 , elapsed time: 29.1556640744209
write_fst(ExifData, "ExifData.fst")

Save to SQLite DataBase file

library(RSQLite)
con <- dbConnect(SQLite(), "PhotoExifDB.sqlite")
dbWriteTable(con, "PhotoDir", PhotoDir, overwrite = T)
dbWriteTable(con, "ExifData", ExifData, overwrite = T)
dbDisconnect(con)