library(Rcpp)
cppFunction('void redir(){FILE* F=freopen("capture.txt","w+",stdout);}')
#devtools::install_github("bnosac/image", subdir = "image.darknet", build_vignettes = TRUE)
library(image.darknet)
yolo_tiny_voc <- image_darknet_model(type = 'detect', 
 model = 'tiny-yolo-voc.cfg', 
 weights = system.file(package='image.darknet', 'models', 'tiny-yolo-voc.weights'), 
 labels = system.file(package='image.darknet', 'include', 'darknet', 'data', 'voc.names'))
path<-"/home/rstudio/webpages/examples/yolo/video"

a<-c(dir(path=path,pattern="png"),dir(path=path,pattern="jpg"))

f<-function(x){

  fl<-paste(path,x,sep="/")

  pred <- image_darknet_detect(file =fl, 
                          object = yolo_tiny_voc,
                          threshold = 0.19)
  system(sprintf("mv predictions.png pred/%s",x))
  pred
}

redir(); 
d<-lapply(a, f)
library(dplyr)
library(tidyr)
d<-data.frame(txt=unlist(readLines("capture.txt")))
d %>% filter(!grepl("Boxes",txt))->d
d %>% filter(!grepl("pandoc",txt))->d
d %>% filter(!grepl("unnamed",txt))->d
d$isfile<-grepl("/home",d$txt)
d$txt<-gsub("/home/rstudio/webpages/examples/yolo/","",d$txt)
d$file<-ifelse(d$isfile,d$txt,NA)
d$object<-ifelse(!d$isfile,d$txt,NA)
tidyr::fill(d, "file") ->d
d<-na.omit(d)[,3:4]
d %>% separate(file, into=c("file","time"),sep=":")->d
d %>% separate(object, into=c("object","prob"),sep=":")->d
d %>% filter(!is.na(prob))->d
aqm::dt(d)

birds0001.png

birds0002.png

birds0003.png

birds0004.png

birds0005.png

birds0006.png

birds0007.png

birds0008.png