qr_scan_js_from_corners: Scan an image within a restricted geometry context.

View source: R/qr_js.R

qr_scan_js_from_cornersR Documentation

Scan an image within a restricted geometry context.

Description

This function is usually only called by qr_scan, when a pattern is detected, but decoding it fails. It crops the original image to the neighborhood of pixels targeting the patterns, and re-scans only that region using the JS library. If your images are particularly high-resolution, this will resize them to 50%, which seems to increase the chances of recognition.

Usage

qr_scan_js_from_corners(
  mgk,
  code_pts,
  lighten = FALSE,
  darken = TRUE,
  verbose = interactive()
)

Arguments

mgk

A magick image object.

code_pts

A dataframe of columns x and y, with each row identifying a QR pattern corner, usually generated by qr_scan_cpp_magick.

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.

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

If decodable, a list with metadata about the identified QR code.


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