Skip to content

Commit

Permalink
pass check
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrecenti committed Jun 16, 2022
1 parent 07df7d7 commit 66ade43
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Imports:
fs,
usethis,
torchvision,
luz
luz,
R6,
rlang
URL: https://github.com/decryptr/captcha
BugReports: https://github.com/decryptr/captcha/issues
1 change: 1 addition & 0 deletions R/dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ available_captchas <- function() {
#' File to torch tensor
#'
#' @param x file path
#' @param input_dim resize image to dimension
#'
#' @export
captcha_transform_image <- function(x, input_dim = c(32L, 192L)) {
Expand Down
22 changes: 11 additions & 11 deletions R/generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @param p_implode probability to add imploding effect. Defaults to 20%.
#' @param p_oilpaint probability to add oilpaint effect. Defaults to 0.
#' @param p_noise probability to add random noise to image. Defaults to 40%.
#' @param p_pat probability to add LAT algorithm to image. Defaults to 0.
#' @param p_lat probability to add LAT algorithm to image. Defaults to 0.
#'
#' @return list containing two elements: imagemagick object and captcha
#' value.
Expand Down Expand Up @@ -63,7 +63,7 @@ captcha_generate <- function(write_disk = FALSE,
captcha_chars <- sample(chars, n_chars, replace = TRUE)
captcha_value <- paste(captcha_chars, collapse = "")

rand <- runif(n_rows * n_cols * 3, min = 0, max = .3)
rand <- stats::runif(n_rows * n_cols * 3, min = 0, max = .3)
background_cols <- grDevices::col2rgb(sample(grDevices::colors(), 1)) / 255
background_pix <- rep(background_cols, each = n_rows * n_cols)
m <- array(background_pix, dim = c(n_rows, n_cols, 3))
Expand All @@ -80,7 +80,7 @@ captcha_generate <- function(write_disk = FALSE,
dist_col <- sum((txt_col_rgb - background_cols)^2)
}

if (runif(1) < p_box) {
if (stats::runif(1) < p_box) {
# box color can't be too close to text color
box_color <- sample(grDevices::colors(), 1)
box_color_rgb <- grDevices::col2rgb(box_color) / 255
Expand All @@ -100,14 +100,14 @@ captcha_generate <- function(write_disk = FALSE,
size = sample(seq(size - 2, size + 2), 1),
gravity = sample(gravity, 1),
color = txt_col,
degrees = ifelse(runif(1) < p_rotate, sample(seq(-10, 10), 1), 0),
degrees = ifelse(stats::runif(1) < p_rotate, sample(seq(-10, 10), 1), 0),
weight = sample(seq(400, 800), 1),
kerning = sample(seq(-2, 10), 1),
font = sample(fonts, 1),
style = sample(magick::style_types(), 1),
decoration = ifelse(runif(1) < p_line, "LineThrough", "None"),
decoration = ifelse(stats::runif(1) < p_line, "LineThrough", "None"),
strokecolor = ifelse(
runif(1) < p_stroke,
stats::runif(1) < p_stroke,
sample(grDevices::colors(), 1),
"none"
),
Expand All @@ -118,18 +118,18 @@ captcha_generate <- function(write_disk = FALSE,



if (runif(1) < p_implode) {
m_text <- magick::image_implode(m_text, factor = runif(1, 0, .4))
if (stats::runif(1) < p_implode) {
m_text <- magick::image_implode(m_text, factor = stats::runif(1, 0, .4))
}
if (runif(1) < p_oilpaint) {
if (stats::runif(1) < p_oilpaint) {
m_text <- magick::image_oilpaint(m_text, radius = 1.5)
}
if (runif(1) < p_noise) {
if (stats::runif(1) < p_noise) {
## too much noise
# ntype <- sample(setdiff(magick::noise_types(), "Random"), 1)
m_text <- magick::image_noise(m_text, "Gaussian")
}
if (runif(1) < p_lat) {
if (stats::runif(1) < p_lat) {
lat_geo <- paste0(
sample(seq(0,10), 1), "x",
sample(seq(0,10), 1), "+",
Expand Down
2 changes: 1 addition & 1 deletion R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ captcha_load_model <- function(captcha) {
path <- captcha
} else {
tmp <- fs::file_temp("model", ext = "pt")
download.file(captcha_url, tmp)
utils::download.file(captcha_url, tmp)
path <- tmp
}

Expand Down
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
utils::globalVariables(unique(c("super")))

.onLoad <- function(libname, pkgname) {
options(captcha.print.rows = 25)
options(captcha.print.cols = 4)
Expand Down
2 changes: 1 addition & 1 deletion man/captcha_generate.Rd

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

2 changes: 2 additions & 0 deletions man/captcha_transform_image.Rd

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

0 comments on commit 66ade43

Please sign in to comment.