Skip to content

Commit

Permalink
Merge pull request #92 from swarm-lab/develop
Browse files Browse the repository at this point in the history
Various things, see description
  • Loading branch information
sjmgarnier authored Oct 16, 2023
2 parents 6b684bb + 1ea3a77 commit c991a27
Show file tree
Hide file tree
Showing 31 changed files with 360 additions and 88 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export(inRange)
export(inpaint)
export(insertChannel)
export(invert)
export(invertFourcc)
export(isBlob)
export(isImage)
export(isQueue)
Expand Down
46 changes: 39 additions & 7 deletions R/VideoWriterClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#'
#' @param fourcc A 4-character string corresponding to the fourcc code of the
#' codec to be used. A list of fourcc codes can be obtained at this archived
#' page of the fourcc site
#' \href{https://web.archive.org/web/20220316062600/http://www.fourcc.org/codecs.php}{http://www.fourcc.org/codecs.php}.
#' page of the fourcc site \href{https://www.fourcc.org/codecs.php}{https://www.fourcc.org/codecs.php}.
#' Alternatively, the integer value corresponding to a fourcc code.
#'
#' @param fps A numeric value corresponding to the framerate of the output video.
#'
Expand Down Expand Up @@ -102,6 +102,9 @@
#' @export
videoWriter <- function(outputFile, fourcc, fps, height, width, isColor = TRUE,
api = "ANY") {
if (is.numeric(fourcc))
fourcc <- as.integer(fourcc)

new(VideoWriter, outputFile = outputFile, fourcc = fourcc, fps = fps,
height = height, width = width, isColor = isColor, api = api)
}
Expand Down Expand Up @@ -352,20 +355,19 @@ writerOuput <- function(x) {

#' @title Codec Name to FOURCC Code
#'
#' @description \code{fource} translates the 4-character name of a video codec
#' into its corresponding \href{https://web.archive.org/web/20220316062600/http://www.fourcc.org/codecs.php}{FOURCC} code.
#' @description \code{fourcc} translates the 4-character name of a video codec
#' into its corresponding \href{https://www.fourcc.org/codecs.php}{FOURCC} code.
#'
#' @param x A 4-element character chain corresponding to the name of a valid
#' video codec. A list of valid codec names can be found at this archived
#' page of the fourcc site
#' \href{https://web.archive.org/web/20220316062600/http://www.fourcc.org/codecs.php}{http://www.fourcc.org/codecs.php}.
#' page of the fourcc site \href{https://www.fourcc.org/codecs.php}{https://www.fourcc.org/codecs.php}.
#'
#' @return An integer value corresponding to the FOURCC code of the video codec.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{VideoWriter}}, \code{\link{videoWriter}},
#' \code{\link{codec}}
#' \code{\link{codec}}, \code{\link{invertFourcc}}
#'
#' @examples
#' fourcc("xvid")
Expand All @@ -381,4 +383,34 @@ fourcc <- function(x) {
str <- strsplit(x, "")[[1]]

`_fourcc`(str[1], str[2], str[3], str[4])
}


#' @title FOURCC Code to Codec Name
#'
#' @description \code{invertFourcc} translates a
#' \href{https://www.fourcc.org/codecs.php}{FOURCC} code into the 4-character
#' name of the corresponding video codec.
#'
#' @param x A integer.
#'
#' @return A 4-character strings corresponding to the video codec.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{VideoWriter}}, \code{\link{videoWriter}},
#' \code{\link{codec}}, \code{\link{fourcc}}
#'
#' @examples
#' invertFourcc(1684633208)
#'
#' @export
invertFourcc <- function(x) {
if (is.numeric(x))
x <- as.integer(x)

if (!is.integer(x))
stop("x must be an integer number.")

`_invertFourcc`(x)
}
2 changes: 1 addition & 1 deletion R/draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ inpaint <- function(image, mask, radius = 5, method = "NS", target = "new", in_p
#' @param image An \code{\link{Image}} object.
#'
#' @param mask An 8U, single-channel \code{\link{Image}} object. The region to
#' be colored should be white.
#' be colored should be non-zero.
#'
#' @param color A value or vector of any kind of R color specification compatible
#' with \code{\link{col2bgr}} representing the color of each rectangle's outline
Expand Down
7 changes: 4 additions & 3 deletions R/generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ release <- function(x) UseMethod("release")
#' \item{\code{FRAME_WIDTH}: Width in pixels of the frames in the video stream.}
#' \item{\code{FRAME_HEIGHT}: Height in pixels of the frames in the video stream.}
#' \item{\code{FPS}: Frame rate in frames per second.}
#' \item{\code{FOURCC}: 4-character \href{https://web.archive.org/web/20220316062600/http://www.fourcc.org/codecs.php}{FOURCC} code of the codec}
#' \item{\code{FOURCC}: 4-character \href{https://www.fourcc.org/codecs.php}{FOURCC}
#' code of the codec}
#' \item{\code{FRAME_COUNT}: Number of frames in the video file.}
#' }
#'
#' Setting stream properties depends on a lot of things, mainly your
#' operating system, the camera drivers installed on your coputer and the
#' operating system, the camera drivers installed on your computer and the
#' camera itself. As a consequence, setting stream values might not work at all
#' with your installation.
#'
Expand Down Expand Up @@ -172,7 +173,7 @@ getProp <- function(x, property) UseMethod("getProp")
#' \code{\link{VideoWriter}} object.
#'
#' @return A character string corresponding to the
#' \href{https://web.archive.org/web/20220316062600/http://www.fourcc.org/codecs.php}{FOURCC} code of the codec.
#' \href{https://www.fourcc.org/codecs.php}{FOURCC} code of the codec.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
Expand Down
25 changes: 21 additions & 4 deletions R/statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,42 @@ mean.list <- function(x, target = "new", ...) {
#'
#' @param x An \code{\link{Image}} object.
#'
#' @param mask A single-channel (GRAY) 8-bit (8U) \code{\link{Image}} object
#' with the same dimensions as \code{x}. This can be used to mask out pixels
#' that should not be considered when calculating the minima and maxima (pixels
#' set to 0 in the mask will be ignored during the calculation).
#'
#' @return A matrix (or a list of matrices for multi-channels images).
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{Image}}, \code{\link{min.Rcpp_Image}}, \code{\link{max.Rcpp_Image}}.
#' @seealso \code{\link{Image}}, \code{\link{min.Rcpp_Image}},
#' \code{\link{max.Rcpp_Image}}.
#'
#' @examples
#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
#' minMaxLoc(balloon)
#'
#' @export
minMaxLoc <- function(x) {
minMaxLoc <- function(x, mask = NULL) {
if (!isImage(x))
stop("This is not an Image object.")

if (missing(mask)) {
mask <- ones(nrow(x), ncol(x), 1)
mask %i*% 255
}

if (!isImage(mask))
stop("mask is not an 'Image' object.")

if (mask$depth() != "8U" | mask$nchan() != 1)
stop("mask is not an 8U single-channel 'Image' object")

if (x$nchan() == 1) {
`_minMaxLoc`(x)
`_minMaxLoc`(x, mask)
} else {
lapply(split(x), `_minMaxLoc`)
lapply(split(x), `_minMaxLoc`, mask = mask)
}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandoc: 3.1.6
pandoc: 3.1.8
pkgdown: 2.0.7
pkgdown_sha: ~
articles:
Expand All @@ -9,7 +9,7 @@ articles:
z5_gpu: z5_gpu.html
z6_queue: z6_queue.html
z7_stack: z7_stack.html
last_built: 2023-08-09T18:21Z
last_built: 2023-10-16T19:54Z
urls:
reference: https://swarm-lab.github.io/Rvision/reference
article: https://swarm-lab.github.io/Rvision/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/codec.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/convexHull.html

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

8 changes: 4 additions & 4 deletions docs/reference/fitEllipse.html

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

13 changes: 6 additions & 7 deletions docs/reference/fourcc.html

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

Loading

0 comments on commit c991a27

Please sign in to comment.