Skip to content

Commit

Permalink
Fix getPerspectiveTransform. Version bump. Website update.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmgarnier committed Feb 24, 2021
1 parent 11a6611 commit 5d1ebfb
Show file tree
Hide file tree
Showing 138 changed files with 216 additions and 187 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Rvision
Type: Package
Title: Computer vision library for R
Version: 0.4.2
Version: 0.4.3
Date: 2021-02-19
Authors@R: c(
person("Simon", "Garnier", email = "garnier@njit.edu", role = c("aut", "cre"),
Expand All @@ -16,7 +16,7 @@ LazyData: TRUE
NeedsCompilation: yes
Imports:
Rcpp (>= 1.0.1),
ROpenCVLite (>= 0.3.412),
ROpenCVLite (>= 4.50.0),
methods,
pbapply,
stats,
Expand Down
82 changes: 45 additions & 37 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,43 +231,6 @@ findTransformORB <- function(template, image, warp_mode = "affine", max_features
# }


#' @title Perspective Transform
#'
#' @description \code{getPerspectiveTransform} computes the matrix of a perspective
#' transform from 4 pairs of corresponding points.
#'
#' @param from A 4x2 matrix indicating the location (x, y) of 4 points in the
#' source image.
#'
#' @param to A 4x2 matrix indicating the location (x, y) of 4 points in the
#' destination image. The order of the points must correspond to the order in
#' \code{from}.
#'
#' @return A 3x3 matrix.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{warpPerspective}}
#'
#' @examples
#' from <- matrix(c(1, 1, 2, 5, 6, 5, 5, 1), nrow = 4, byrow = TRUE)
#' to <- matrix(c(1, 1, 1, 5, 5, 5, 5, 1), nrow = 4, byrow = TRUE)
#' getPerspectiveTransform(from, to)
#'
#' @export
getPerspectiveTransform <- function(from, to) {
if (any(dim(from) != c(4, 2)) | any(dim(to) != c(4, 2)))
stop("'from' and 'to' must be 4x2 matrices.")

from[, 1] <- from[, 1] - 1
from[, 2] <- -from[, 2] + nrow(image)
to[, 1] <- to[, 1] - 1
to[, 2] <- -to[, 2] + nrow(image) - (nrow(image) - output_size[1])

`_getPerspectiveTransform`(from, to)
}


#' @title Image Rotation and Scaling
#'
#' @description \code{rotateScale} rotates (clockwise) and scales an image using
Expand Down Expand Up @@ -403,6 +366,51 @@ warpAffine <- function(image, warp_matrix, output_size = dim(image)[1:2],
}


#' @title Perspective Transform
#'
#' @description \code{getPerspectiveTransform} computes the matrix of a perspective
#' transform from 4 pairs of corresponding points in a source and destination
#' image.
#'
#' @param from A 4x2 matrix indicating the location (x, y) of 4 points in the
#' source image.
#'
#' @param to A 4x2 matrix indicating the location (x, y) of 4 points in the
#' destination image. The order of the points must correspond to the order in
#' \code{from}.
#'
#' @param from_dim A vector which first two elements indicate the number of rows
#' and columns of the source image.
#'
#' @param to_dim A vector which first two elements indicate the number of rows
#' and columns of the destination image. If not specified, \code{from_dim} will
#' be used as a default.
#'
#' @return A 3x3 matrix.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{warpPerspective}}
#'
#' @examples
#' from <- matrix(c(1, 1, 2, 5, 6, 5, 5, 1), nrow = 4, byrow = TRUE)
#' to <- matrix(c(1, 1, 1, 5, 5, 5, 5, 1), nrow = 4, byrow = TRUE)
#' getPerspectiveTransform(from, to, c(1080, 1920), c(1080, 1920))
#'
#' @export
getPerspectiveTransform <- function(from, to, from_dim, to_dim = from_dim) {
if (any(dim(from) != c(4, 2)) | any(dim(to) != c(4, 2)))
stop("'from' and 'to' must be 4x2 matrices.")

from[, 1] <- from[, 1] - 1
from[, 2] <- -from[, 2] + from_dim[1]
to[, 1] <- to[, 1] - 1
to[, 2] <- -to[, 2] + from_dim[1] - (from_dim[1] - to_dim[1])

`_getPerspectiveTransform`(from, to)
}


#' @title Perspective Transformation
#'
#' @description \code{warpPerspective} applies a perspective transformation to
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/z1_install.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/z2_io.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/z3_basic.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ articles:
z1_install: z1_install.html
z2_io: z2_io.html
z3_basic: z3_basic.html
last_built: 2021-02-24T19:40Z
last_built: 2021-02-24T20:41Z
urls:
reference: https://swarm-lab.github.io/ROpenCVLite//reference
article: https://swarm-lab.github.io/ROpenCVLite//articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/Image-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/LUT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Rvision.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/RvisionAck.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Stream-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/Video-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/VideoWriter-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/absdiff.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/adaptiveThreshold.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/addWeighted.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/api.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/as.array.Rcpp_Image.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/bilateralFilter.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/bitdepth.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/blur.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/border.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/boxFilter.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/canny.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/changeBitDepth.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/changeColorSpace.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/click.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d1ebfb

Please sign in to comment.