How to
- crop/clip an image with a polygon as the boundary and then
- deskew the output using
imager
andmagick
package inR
?
library(imager)
library(sp)
plot(boats)
xy <- list(x = c(87.4790282019041, 58.2397610921502, 164.877088198312,
181.216678641998),
y = c(49.3995868510868, 131.957517513921,
158.616849290462, 69.1790910723909))
polygon(xy$x, xy$y, border = "red")
poly <- sp::Polygons(list(sp::Polygon(data.frame(xy))), "crop")
poly <- sp::SpatialPolygons(c(poly))
polyNames <- c("crop")
polydf <- sp::SpatialPolygonsDataFrame(poly, data.frame(1:length(polyNames), row.names=polyNames))