Closed bw4sz closed 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)
}
add option to turn polygons into bounding boxes.
Have a shp reader file.