Search code examples
rrstudioqr-codedecoding

How can I read and decode an image with QR code in R programming?


How can I read and decode an image with QR code in R programming? I want to transform an image with QR code in text.

R has libraries for generating QR codes as 'package qrcode’ and ‘package qrencoder’. But I need one package or another way for decoding QR code from an image JPG or PNG or BMP or another.


Solution

  • The following image is a QR code of the url for this page (try it out)

    enter image description here

    To read it, as Wimpel points out, you can try the quadrangle package, which you can install with

    library(devtools)
    
    install_github("brianwdavis/quadrangle", INSTALL_opts = "--no-multiarch")
    

    To read the above image, we simply do:

    library(quadrangle)
    
    result <- qr_scan("https://i.sstatic.net/CrADg.png")$values$value
    

    And we can see the result is correct:

    result
    #> [1] "https://stackoverflow.com/questions/71592191/how-can-i-read-and-decode-an-image-with-qr-code-in-r-programming/71592356"