qr_scan_cpp: Scan an image file or 'magick' image object for QR codes with...

View source: R/Rcpp_helpers.R

qr_scan_cppR Documentation

Scan an image file or magick image object for QR codes with the C++ engine.

Description

This is a wrapper function to call the QR code scanner in the quirc C++ library. You can call this function on file paths, or preprocess files and call this function on the resulting magick objects.

Usage

qr_scan_cpp(
  image,
  flop = F,
  lighten = F,
  darken = T,
  debug = F,
  verbose = interactive()
)

Arguments

image

A path to a magick-readable file, e.g. jpg or png, or a magick object.

flop

Logical. Should image be mirrored L-R? Some generators produce QR codes like this.

lighten

Logical. Should under-exposed areas of the image be lightened to increase contrast? Useful for images in shadow. Default FALSE.

darken

Logical. Should over-exposed areas of the image be darkened to increase contrast? Useful for images in bright light. Default TRUE.

debug

Logical. Should additional metadata about decoded QR patterns be included? e.g. ECC level, version number, etc.

verbose

Logical. Should warnings print for potentially slow operations?

Details

This uses a double-while loop that progressively pushes mid-brightness pixels to pure black, and if that fails, progressively pushes mid-brightness pixels to pure white. This algorithm was developed for identifying QR codes on white printed sheets in outdoor images, in bright sun with or without shadows. To speed up scanning, you can use arguments lighten = F, darken = F which will skip any thresholding. If you use both lighten = T, darken = T, scanning may be quite slow until a decodable QR code is found. In those cases, a progress bar will attempt to be shown, if you have the progress package (https://github.com/r-lib/progress) available on your machine.

To BYO algorithm, you can use this function as a template. For example, image_morphology with (..., morphology = "Open", kernel = "Square:n") (varying n from 2 to 10) may repair corrupted QR blocks.

Value

A list of two dataframes, "values" and "points" describing any found QR codes.


brianwdavis/quadrangle documentation built on Feb. 27, 2023, 6:36 p.m.