Posted by
Elliott Slaughter on
URL: http://imagej.273.s1.nabble.com/Announcing-QR-Decoder-for-ImageJ-tp3683501p3683503.html
On Fri, Aug 12, 2011 at 3:34 AM, Johannes Schindelin <
[hidden email]> wrote:
> Hi Elliott,
>
> On Sun, 31 Jul 2011, Elliott Slaughter wrote:
>
> > As a weekend project I built a QR decoder plugin for ImageJ. With the
> > help of the ZXing project <
http://code.google.com/p/zxing/>, this turned
> > out to be easier than I expected.
> >
> > I built the plugin with just QR barcodes in mind, but it would be easy
> > enough to support other formats as well, if there is demand for it.
> >
> > You can download the plugin here:
> >
> >
>
https://bitbucket.org/elliottslaughter/qr_decoder/downloads/qr_decoder_1.0.jar> >
> > You can obtain the source code for the plugin here:
> >
> >
https://bitbucket.org/elliottslaughter/qr_decoder>
> Nice. I made the following change so that the attached image can be
> decoded. In total, I made these changes:
>
> - support all image input types
> - abort in case of failure, rather than showing a failed result
> - as a consequence, I do not need the GenericDialog anymore.
>
Cool.
Would you mind explaining to me (as a relative macro noob) how to catch
these aborts in a macro such that I can use your version of the plugin on a
batch of images without stopping in the middle of the set of images because
one of them couldn't be read?
That is, mind writing a diff for this file? :-)
https://bitbucket.org/elliottslaughter/qr_decoder/src/9d4c0ddb4272/examplemacro.txtThanks.
-- snipsnap --
> diff -r 9d4c0ddb4272 src/QR_Decoder.java
> --- a/src/QR_Decoder.java Sun Jul 31 12:08:11 2011 -0700
> +++ b/src/QR_Decoder.java Fri Aug 12 03:32:16 2011 -0700
> @@ -1,6 +1,8 @@
> import ij.ImagePlus;
> +import ij.Macro;
> -import ij.gui.GenericDialog;
> import ij.plugin.filter.PlugInFilter;
> +import ij.process.ByteProcessor;
> import ij.process.ImageProcessor;
> import ij.text.TextWindow;
>
> @@ -43,32 +45,27 @@
> public class QR_Decoder implements PlugInFilter {
>
> public int setup(String arg, ImagePlus image) {
> - return DOES_8G | NO_CHANGES;
> + return DOES_ALL | NO_CHANGES;
> }
>
> public void run(ImageProcessor ip) {
> - GenericDialog gd = new GenericDialog("QR Decoder
> Settings");
> - gd.addStringField("Error Results In: ", "FAILED");
> - gd.showDialog();
> - if (gd.wasCanceled()) {
> - return;
> - }
> - String defaultResultText = gd.getNextString();
> -
> + if (!(ip instanceof ByteProcessor))
> + ip = ip.convertToByte(true);
> + else if (!ip.isDefaultLut())
> + ip = ip.convertToRGB().convertToByte(true);
> Reader reader = new QRCodeReader();
> BufferedImage myimg = ip.getBufferedImage();
> LuminanceSource source = new
> BufferedImageLuminanceSource(myimg);
> BinaryBitmap bitmap = new BinaryBitmap(new
> HybridBinarizer(source));
> - String resultText = defaultResultText;
> + String resultText = "FAILED";
> try {
> Hashtable<DecodeHintType, Object> hints = new
> Hashtable<DecodeHintType, Object>();
> hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
> Result result = reader.decode(bitmap, hints);
> resultText = result.getText();
> // On errors just return the default result.
> - } catch (NotFoundException e) {
> - } catch (ChecksumException e) {
> - } catch (FormatException e) {
> + } catch (Exception e) {
> + Macro.abort();
> }
>
> new TextWindow("QR Code", resultText, 12 *
> resultText.length(), 150);
--
Elliott Slaughter
"Don't worry about what anybody else is going to do. The best way to predict
the future is to invent it." - Alan Kay