Add Tag via R

72 views
Skip to first unread message

Lourens Swanepoel

unread,
Aug 24, 2023, 12:43:25 AM8/24/23
to camtrapR
Hi All,
I currently have images tagged by AI. But the AI added the tags to the EXIF data; as a UserComment.
If I extract this information via recordTable(additionalMetaTags = "EXIF:UserComment"), can I use CamtrapR to write it as a meta tag that Digicam can see?
Thanks for help.
Lourens

Jim Casaer

unread,
Aug 24, 2023, 3:57:08 AM8/24/23
to Lourens Swanepoel, camtrapR
Lourens,

What is the system you're using for the AI ?
Jim


Dr.ir. Jim Casaer

Senior Researcher
Research Group wildlife Management / OT  Faunabeheer en Exoten/ 
Research Institute for Nature and Forest / Instituut voor Natuur- en Bosonderzoek



Havenlaan 88 bus 73,
1000 Brussel

** 32 478 281 701 
orcid : 0000-0001-6788-5876




Op do 24 aug 2023 om 06:43 schreef Lourens Swanepoel <lourens.swan...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "camtrapR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camtrapr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/camtrapr/9ed827f3-2142-4fa0-b566-35444135e118n%40googlegroups.com.

Jürgen Niedballa

unread,
Sep 1, 2023, 2:32:46 AM9/1/23
to Jim Casaer, Lourens Swanepoel, camtrapR
Hello,
there is currently no built-in function in camtrapR to achieve this.
Since you can extract the UserComment with recordTable(), you can call Exiftool from R to write the content of usercomment to the HierarchicalSubject tag though (which digiKam reads).

Here's the rough idea (for assigning the value in the column UserComment of the record table to a tag "Species" in the HierarchicalSubject field in the image metadata:

species_tag <- paste("Species", rec$UserComment, sep = "|")
exif_call <- paste0('exiftool -hierarchicalsubject+="', species_tag, '" ', file.path(rec$Directory, rec$FileName))

system(exif_call)  # for one image
sapply(exif_call, system)   # for multiple images

system(paste('exiftool -HierarchicalSubject ', file.path(rec$Directory[1], rec$FileName[1])))  # for checking



It is quite clumsy and very slow since it calls exiftool for each image separately. Performance can be increased by parallelization (e.g. parSapply).


Alternatively, one can probably achieve the same with Exiftool for entire directories instead of files, either from the command line or within R using a system call.
One can copy values from one metadata tag to another (see e.g. here), but here we need to copy it as structured information (e.g. with a prefix "Species|" in HierarchicalSubject). I don't know how to do that in Exiftool and don't have code to share. The Exiftool forum (https://exiftool.org/forum/) might be a good place to find help on that though, and there were some similar questions in the past already. If there is a solution please share, then I can maybe add it to camtrapR in the future.

Either way, in digiKam one needs to click "Read metadata from file to database" to see the newly assigned tags.

Best regards,
Jürgen

Reply all
Reply to author
Forward
0 new messages