From 1ea3a77382e81a0506d9d9a6ba9aed6be71ebd27 Mon Sep 17 00:00:00 2001 From: Simon Garnier Date: Mon, 16 Oct 2023 15:56:00 -0400 Subject: [PATCH] Various things, see description + Add mask to minMaxLoc + Update cap and writer properties utilities + Add invertFourcc function + Fix documentation --- NAMESPACE | 1 + R/VideoWriterClass.R | 46 +++++++++++--- R/draw.R | 2 +- R/generic.R | 7 ++- R/statistics.R | 25 ++++++-- docs/pkgdown.yml | 4 +- docs/reference/codec.html | 2 +- docs/reference/convexHull.html | 2 +- docs/reference/fitEllipse.html | 8 +-- docs/reference/fourcc.html | 13 ++-- docs/reference/index.html | 29 +++++---- docs/reference/minAreaRect.html | 8 +-- docs/reference/minMaxLoc.html | 12 +++- docs/reference/setProp.html | 5 +- docs/reference/setTo.html | 2 +- docs/reference/stream.html | 17 +++-- docs/reference/videoWriter.html | 4 +- docs/sitemap.xml | 3 + man/codec.Rd | 2 +- man/fourcc.Rd | 9 ++- man/invertFourcc.Rd | 30 +++++++++ man/minMaxLoc.Rd | 10 ++- man/setProp.Rd | 5 +- man/setTo.Rd | 2 +- man/videoWriter.Rd | 4 +- src/Capture.h | 4 +- src/Image.h | 2 +- src/VideoWriter.h | 63 +++++++++++++++++-- src/statistics.h | 14 ++++- src/utils.h | 106 ++++++++++++++++++++++++++++++-- src/visionModule.cpp | 7 ++- 31 files changed, 360 insertions(+), 88 deletions(-) create mode 100644 man/invertFourcc.Rd diff --git a/NAMESPACE b/NAMESPACE index b25ce1c5..258b3f12 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -165,6 +165,7 @@ export(inRange) export(inpaint) export(insertChannel) export(invert) +export(invertFourcc) export(isBlob) export(isImage) export(isQueue) diff --git a/R/VideoWriterClass.R b/R/VideoWriterClass.R index dab46edf..a78c8f87 100644 --- a/R/VideoWriterClass.R +++ b/R/VideoWriterClass.R @@ -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. #' @@ -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) } @@ -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") @@ -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) } \ No newline at end of file diff --git a/R/draw.R b/R/draw.R index e7fbfb20..6254c7a4 100644 --- a/R/draw.R +++ b/R/draw.R @@ -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 diff --git a/R/generic.R b/R/generic.R index a2058329..0c32abfb 100644 --- a/R/generic.R +++ b/R/generic.R @@ -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. #' @@ -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} #' diff --git a/R/statistics.R b/R/statistics.R index 8b5207e6..73d1bc06 100644 --- a/R/statistics.R +++ b/R/statistics.R @@ -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) } } diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3e94647e..57b9588e 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,4 +1,4 @@ -pandoc: 3.1.6 +pandoc: 3.1.8 pkgdown: 2.0.7 pkgdown_sha: ~ articles: @@ -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 diff --git a/docs/reference/codec.html b/docs/reference/codec.html index 2a675b05..e799fb1c 100644 --- a/docs/reference/codec.html +++ b/docs/reference/codec.html @@ -91,7 +91,7 @@

Value

A character string corresponding to the

-

FOURCC code of the codec.

+

FOURCC code of the codec.

See also

diff --git a/docs/reference/convexHull.html b/docs/reference/convexHull.html index 869052f0..24323edc 100644 --- a/docs/reference/convexHull.html +++ b/docs/reference/convexHull.html @@ -98,7 +98,7 @@

Author<

Examples

convexHull(rnorm(100), rnorm(100))
-#> [1] 18 27 42 50 95 51 52
+#> [1]  3 21 79 83 42 60 26 29
 
 
diff --git a/docs/reference/fitEllipse.html b/docs/reference/fitEllipse.html index 11aa0a99..0544c082 100644 --- a/docs/reference/fitEllipse.html +++ b/docs/reference/fitEllipse.html @@ -119,16 +119,16 @@

Author<

Examples

fitEllipse(rnorm(100), rnorm(100))
 #> $angle
-#> [1] 68.14399
+#> [1] 48.22406
 #> 
 #> $height
-#> [1] 4.426012
+#> [1] 4.085447
 #> 
 #> $width
-#> [1] 3.899822
+#> [1] 3.781842
 #> 
 #> $center
-#> [1] -0.00229378 -0.37228656
+#> [1] -0.5453361  0.2623618
 #> 
 
 
diff --git a/docs/reference/fourcc.html b/docs/reference/fourcc.html index 95a52b6b..792c2a82 100644 --- a/docs/reference/fourcc.html +++ b/docs/reference/fourcc.html @@ -1,6 +1,6 @@ -Codec Name to FOURCC Code — fourcc • RvisionCodec Name to FOURCC Code — fourcc • Rvision