weecology / NeonTreeEvaluation_package

R package for evaluating individual tree crown predictions against a diverse benchmark dataset
22 stars 7 forks source link

load ground truth from shp #8

Closed bw4sz closed 4 years ago

bw4sz commented 4 years ago

Have a shp reader file.

bw4sz commented 4 years ago
shapefile_to_annotation<-function(path, image_path){
  #Read shapefile
  shp<-sf::read_sf(path)

  #Extract bounds
  boxes<-lapply(shp$geometry,function(x) sf::st_bbox(x))
  boxes<-do.call(rbind,boxes)
  boxes<-as.data.frame(boxes)

  #grab label if present
  if ("label" %in% colnames(shp)){
    boxes$label<-shp$label
  } else {
    boxes$label<-"Tree"
  }

  boxes$plot_name<-stringr::str_match(image_path,"(\\w+)\\.")[,2]

  return(boxes)
}
bw4sz commented 4 years ago

add option to turn polygons into bounding boxes.