#install.packages("camtrapR", repos = "https://cloud.r-project.org")
library("camtrapR")Organising raw Camera Trap images in camtrapR
Introduction
camptrapR (Niedballa et al. 2016)provides a more automatised way of organising and managing camera trap images.
The package handles JPG images and video files.
You can find the relevant documentation for this package here: camtrapR
Running Code
Step 1
Install the package if not already installed, and then open it:
Step 2
camtrapR requires the software ExifTool to extract the metadata from images. On MacOS, it needs installation (please follow the instructions found in the package documentation). On Windows, ExifTool does not need installation every time you use camtrapR, but you need to have it installed on your computer.
Go to exiftool.org and download the stand-alone version for Windows. The download file is a .zip, which you need to unzip, rename the contained “exiftool(-k).exe” file to “exiftool.exe” # and place it in e.g., C:/Windows. Windows can find ExifTool if exiftool.exe is placed in a directory containing the Windows PATH variable (e.g. C:/Windows).
Make sure you also copy the folder “exiftool_files”.
Check if the system can find Exiftool (if the output is empty ““, the system can’t find Exiftool)
Sys.which("exiftool") exiftool
"C:\\WINDOWS\\exiftool.exe"
If you have limited installation privileges on your computer, please refer to camptrapR documentation.
Step 3
As explained during the module, you must record relevant metadata related to the cameras and their deployment, including:
Grid ID: if you are using a grid system
Study area ID: if you are deploying cameras across different study areas
Station (location) ID where you have placed the camera
Camera ID
Deployment ID: if you have deployed the camera >1 times
X/Y - Lat/Long of the camera
Any other covariates that are deemed important
camptrapR makes use of the above data, in particular the station ID, to create a folder structure that will allow an effective management of the CT images.
The following code is used to create the folder structure based on the unique station IDs, which is contained in a csv file.
In this tutorial I have used my own PATH directory, you will have to use your own PATH.
Remember in R you need to use forward slash format (“/”) for specifying file paths. Windows uses backward slash.
camtraps <- read.csv("Station.csv",
header = TRUE,
sep = ",",
stringsAsFactors = FALSE)Now, you can proceed to create the directory structure.
Firstly, create a folder called “rawImages” within your main directory, in this example, called “camTrap_example”.
wd_createStationDir <- "rawImages"Secondly, create individual folders for each value of the variable Station contained within the CSV mentioned above.
StationFolderCreate1 <- createStationFolders (
inDir = wd_createStationDir, stations = as.character(camtraps$Station), createinDir = TRUE)Now, the rawImages folder should have one folder per station ID. If there were multiple cameras at the same station, then subfolders would be added to each station ID folder.
Step 4
Now, you can copy all the image files (photos and videos) for an individual Station ID to the relevant folder.
Step 5
The last step is renaming the images so each file name contains information related to the station ID, camera ID (if more than one camera per station was used) and the date and time of the capture.
Station ID and camera ID are derived fromt he directory structure created earlier, whilt the date and time are taken from the image EXIF metadata. In addition the file will have an identifier (x) that is assigned to all images taken at the same station (and camera, if applicable) within one minute. This is to avoid identical names if images were taken in the same second or minute (if the camera does not record seconds).
StationID_Date_Time(x).jpg -> if there is only one camera per station
StationID_CameraID_Date_Time((x).jpg -> more than one camera per station
Firstly, identify the file path where the raw images can be found:
wd_images_raw <- "rawImages"Secondly, identify the destination for renamed images to be copied to. This will generate a mirrored directory structure, containing the renamed files.
wd_images_raw_renamed<-"raw_images_renamed"And lastly, proceed to rename the files.
renaming.table2 <- imageRename(inDir = wd_images_raw,
outDir = wd_images_raw_renamed,
hasCameraFolders = FALSE,
copyImages = TRUE)You will now find all the renamed files in a folder called raw_images_renamed.