Skip to content

Commit 5d1ebfb

Browse files
committed
Fix getPerspectiveTransform. Version bump. Website update.
1 parent 11a6611 commit 5d1ebfb

File tree

138 files changed

+216
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+216
-187
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rvision
22
Type: Package
33
Title: Computer vision library for R
4-
Version: 0.4.2
4+
Version: 0.4.3
55
Date: 2021-02-19
66
Authors@R: c(
77
person("Simon", "Garnier", email = "garnier@njit.edu", role = c("aut", "cre"),
@@ -16,7 +16,7 @@ LazyData: TRUE
1616
NeedsCompilation: yes
1717
Imports:
1818
Rcpp (>= 1.0.1),
19-
ROpenCVLite (>= 0.3.412),
19+
ROpenCVLite (>= 4.50.0),
2020
methods,
2121
pbapply,
2222
stats,

R/transform.R

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -231,43 +231,6 @@ findTransformORB <- function(template, image, warp_mode = "affine", max_features
231231
# }
232232

233233

234-
#' @title Perspective Transform
235-
#'
236-
#' @description \code{getPerspectiveTransform} computes the matrix of a perspective
237-
#' transform from 4 pairs of corresponding points.
238-
#'
239-
#' @param from A 4x2 matrix indicating the location (x, y) of 4 points in the
240-
#' source image.
241-
#'
242-
#' @param to A 4x2 matrix indicating the location (x, y) of 4 points in the
243-
#' destination image. The order of the points must correspond to the order in
244-
#' \code{from}.
245-
#'
246-
#' @return A 3x3 matrix.
247-
#'
248-
#' @author Simon Garnier, \email{garnier@@njit.edu}
249-
#'
250-
#' @seealso \code{\link{warpPerspective}}
251-
#'
252-
#' @examples
253-
#' from <- matrix(c(1, 1, 2, 5, 6, 5, 5, 1), nrow = 4, byrow = TRUE)
254-
#' to <- matrix(c(1, 1, 1, 5, 5, 5, 5, 1), nrow = 4, byrow = TRUE)
255-
#' getPerspectiveTransform(from, to)
256-
#'
257-
#' @export
258-
getPerspectiveTransform <- function(from, to) {
259-
if (any(dim(from) != c(4, 2)) | any(dim(to) != c(4, 2)))
260-
stop("'from' and 'to' must be 4x2 matrices.")
261-
262-
from[, 1] <- from[, 1] - 1
263-
from[, 2] <- -from[, 2] + nrow(image)
264-
to[, 1] <- to[, 1] - 1
265-
to[, 2] <- -to[, 2] + nrow(image) - (nrow(image) - output_size[1])
266-
267-
`_getPerspectiveTransform`(from, to)
268-
}
269-
270-
271234
#' @title Image Rotation and Scaling
272235
#'
273236
#' @description \code{rotateScale} rotates (clockwise) and scales an image using
@@ -403,6 +366,51 @@ warpAffine <- function(image, warp_matrix, output_size = dim(image)[1:2],
403366
}
404367

405368

369+
#' @title Perspective Transform
370+
#'
371+
#' @description \code{getPerspectiveTransform} computes the matrix of a perspective
372+
#' transform from 4 pairs of corresponding points in a source and destination
373+
#' image.
374+
#'
375+
#' @param from A 4x2 matrix indicating the location (x, y) of 4 points in the
376+
#' source image.
377+
#'
378+
#' @param to A 4x2 matrix indicating the location (x, y) of 4 points in the
379+
#' destination image. The order of the points must correspond to the order in
380+
#' \code{from}.
381+
#'
382+
#' @param from_dim A vector which first two elements indicate the number of rows
383+
#' and columns of the source image.
384+
#'
385+
#' @param to_dim A vector which first two elements indicate the number of rows
386+
#' and columns of the destination image. If not specified, \code{from_dim} will
387+
#' be used as a default.
388+
#'
389+
#' @return A 3x3 matrix.
390+
#'
391+
#' @author Simon Garnier, \email{garnier@@njit.edu}
392+
#'
393+
#' @seealso \code{\link{warpPerspective}}
394+
#'
395+
#' @examples
396+
#' from <- matrix(c(1, 1, 2, 5, 6, 5, 5, 1), nrow = 4, byrow = TRUE)
397+
#' to <- matrix(c(1, 1, 1, 5, 5, 5, 5, 1), nrow = 4, byrow = TRUE)
398+
#' getPerspectiveTransform(from, to, c(1080, 1920), c(1080, 1920))
399+
#'
400+
#' @export
401+
getPerspectiveTransform <- function(from, to, from_dim, to_dim = from_dim) {
402+
if (any(dim(from) != c(4, 2)) | any(dim(to) != c(4, 2)))
403+
stop("'from' and 'to' must be 4x2 matrices.")
404+
405+
from[, 1] <- from[, 1] - 1
406+
from[, 2] <- -from[, 2] + from_dim[1]
407+
to[, 1] <- to[, 1] - 1
408+
to[, 2] <- -to[, 2] + from_dim[1] - (from_dim[1] - to_dim[1])
409+
410+
`_getPerspectiveTransform`(from, to)
411+
}
412+
413+
406414
#' @title Perspective Transformation
407415
#'
408416
#' @description \code{warpPerspective} applies a perspective transformation to

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/z1_install.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/z2_io.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/z3_basic.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/authors.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ articles:
55
z1_install: z1_install.html
66
z2_io: z2_io.html
77
z3_basic: z3_basic.html
8-
last_built: 2021-02-24T19:40Z
8+
last_built: 2021-02-24T20:41Z
99
urls:
1010
reference: https://swarm-lab.github.io/ROpenCVLite//reference
1111
article: https://swarm-lab.github.io/ROpenCVLite//articles

docs/reference/Image-class.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/LUT.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/Rvision.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/RvisionAck.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/Stream-class.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/Video-class.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/VideoWriter-class.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/absdiff.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/adaptiveThreshold.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/addWeighted.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/api.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/as.array.Rcpp_Image.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/bilateralFilter.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/bitdepth.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/blur.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/border.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/boxFilter.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/canny.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/changeBitDepth.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/changeColorSpace.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/click.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)