find_gcp_coords.RdFind the coordinates (longitude and latitude) of the ground control points (GCPs) in a given image.
find_gcp_coords(gcp, sf_obj)A data frame with the GCPs, including their image coordinates and corresponding geographic coordinates.
NOTE: There are two conventions on how to define pixel coordinates. In this
function (and more generally throughout crstools), the origin is defined as
the bottom left corner of the image, with x increasing to the right and y
increasing upwards. This is consistent with the convention used in many image
processing libraries. However, some libraries (like OpenCV and GDAL) define
the origin at the top left corner, with y increasing downwards. Be sure to
check which convention your image processing library uses when working with
pixel coordinates.
if (FALSE) { # rlang::is_installed("rnaturalearth") && rlang::is_interactive()
# load required packages
library(sf)
library(rnaturalearth)
# get the path to an example image included in the package and choose GCPs
img_path <- system.file("extdata/europe_map.jpeg",
package = "crstools"
)
# choose some points
gcp_europe <- choose_gcp(img_path)
# now get some more
gcp_europe <- choose_gcp(img_path, gcp = gcp_europe)
# create a map of europe to use to get the coordinates
world <- ne_countries(scale = "medium", returnclass = "sf")
# transform it to a suitable projection
world <- st_transform(world, crs = 4326)
# crop it to the extent of the image
europe <- st_crop(world, c(xmin = -25, ymin = 25, xmax = 45, ymax = 70))
# get the coordinates for these points
new_gcp_europe <- find_gcp_coords(gcp_europe, sf_obj = europe)
# data frame with the GCPs
print(new_gcp_europe)
}