
// QRDecoder.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Use the third-party "QR Decoder for ImageJ" plugin
   https://elliottslaughter.com/2011/07/qr-decoder-imagej
   to extract the text from a QR barcode.

   Utilizes TextWindow to access the output of the plugin.

   The plugin is installed in ImageJ in its plugins/ folder,
   *and* run.bat sets the "plugins.dir" flag:
      -Dplugins.dir="ImageJ/plugins"

   Usage:
     > compile QRDecoder.java
     > run QRDecoder
*/

import ij.*;
import ij.text.*;
import ij.plugin.*;


public class QRDecoder
{

  public static void main(String[] args)
  {
    ImagePlus imp = new ImagePlus("wikiQR.jpg");
    imp.show();

    IJ.run(imp, "QR Decoder", "error=FAILED");
       // Plugins --> QR Decoder

    TextWindow textWin = (TextWindow) WindowManager.getWindow("QR Code");

    String msg = textWin.getTextPanel().getText();
    System.out.println("Result: " + msg);

    IJ.wait(2000);    // give the user some time to view the results
    WindowManager.closeAllWindows();
  } /* main */

}  // end of QRDecoder class
