qr_scan_js_from_corners | R Documentation |
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.
qr_scan_js_from_corners( mgk, code_pts, lighten = FALSE, darken = TRUE, verbose = interactive() )
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 |
lighten |
Logical. Should under-exposed areas of the image be lightened to increase contrast? Useful for images in shadow. Default |
darken |
Logical. Should over-exposed areas of the image be darkened to increase contrast? Useful for images in bright light. Default |
verbose |
Logical. Should warnings print for potentially slow operations? |
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.
If decodable, a list with metadata about the identified QR code.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.