no love for 1 bit or 8 bit tifs?

Jul 18, 2013 at 7:23 PM
just downloaded the project and tried the demos for wpf and commandline decoder with about a dozen 1 bit or 8 bit tifs. It did not read any of them but it did read a small VERY perfect bar code image in png format. I am currently using an old old version of lead tool barcode and it will read all of the files. I also tested the new spire reader, it worked but took between 15 and 30 seconds per page. WAY TOO SLOW.

This project is too highly rated for the results I am getting so there has to be something I can do. Do I have to change the format to 24 bit? Any suggestions?
Jul 18, 2013 at 7:57 PM
I don't like to be beat so the experimentation goes on. Since the images are all 3 of 9 barcodes I tried with all four combos of the 2 bool input parameters. No Joy.
      ZXing.OneD.Code39Reader reader39 = new ZXing.OneD.Code39Reader(true, false);

      Result result = reader39.decode(bitmap, hints);
next i tried this where the ImageToByte2 will yield me a byte array. No Joy ditto. I did notice in the RGBLuminanceSource.BitmapFormat enums there was nothing for 1 bit so can this software do 1 bit?
      int w = image.Width;
      int h = image.Height;

      byte[] bimage = ImageToByte2(image);

      BarcodeReader reader = new BarcodeReader();
      Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.Gray8);
Coordinator
Jul 18, 2013 at 8:34 PM
Please provide a sample image which doesn't work.
Jul 18, 2013 at 9:19 PM
how would i do that? could I email them to you in a zip?
Jul 19, 2013 at 5:40 PM
I found an online zxing test and it wouldn't read the bar codes either.
Jul 19, 2013 at 6:02 PM
maybe this wasn't proper but it was the only way i saw to easily get my test problem tifs to micjahn. I uploaded a file, noread-1bit-tifs.zip, to the patch upload.
Jul 20, 2013 at 2:18 PM
Edited Jul 20, 2013 at 2:21 PM
I give up. the following code is a mismash of multiple attempts and combinations to get this to work with the admittedly very low quality 1 bit tif images but that is what customers give to us. I didn't do the math but I must of run this in over 100 combinations with zero success. Sigh.

I used the freeimage package.

private Result decode(Uri uri, IDictionary<DecodeHintType, object> hints)
  {
     //Bitmap image;
     //Bitmap image0;

     //byte[] bimage = new byte[0];

     //int w = 0;
     //int h = 0;

     ////          byte[] bimage = ImageToByte2(image);

     //try
     //{

   //     image = (Bitmap) Bitmap.FromFile(uri.LocalPath);
// FIBITMAP fib1 = loadFIBITMAP(uri.LocalPath);
        //FIBITMAP fib2 = FreeImage.ConvertTo16Bits555(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertTo16Bits565(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertTo24Bits(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertTo32Bits(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertTo4Bits(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertTo8Bits(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertToGreyscale(fib1);
        //FIBITMAP fib3 = FreeImage.ConvertTo8Bits(fib1);
        //FIBITMAP fib2 = FreeImage.ConvertToGreyscale(fib3)
;
        //FIBITMAP fib2 = FreeImage.ConvertToStandardType(fib1, true);
        //FIBITMAP fib2 = FreeImage.ConvertToStandardType(fib1, false);

        // FIBITMAP fib2 = FreeImage.ConvertToType(fib1, FREE_IMAGE_TYPE.FIT_BITMAP,true);
        //FIBITMAP fib2 = FreeImage.ConvertToType(fib1, FREE_IMAGE_TYPE.FIT_BITMAP,false);

         //image0 = FreeImage.GetBitmap(fib2);
         //w = image0.Width;
         //h = image0.Height;

         //using (MemoryStream stream = new MemoryStream())
         //{
         //    FreeImage.SaveToStream(fib2,stream,FREE_IMAGE_FORMAT.FIF_PNG);
         //    stream.Close();

         //    bimage = stream.ToArray();
         //}


         //using (MemoryStream stream = new MemoryStream())
         //{
         //    image0.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
         //    stream.Close();

         //    bimage = stream.ToArray();
         //}


     //}
     //catch (Exception)
     //{
     //   throw new FileNotFoundException("Resource not found: " + uri);
     //}


     //LuminanceSource source;

     //if (config.Crop == null)
     //{
     //   source = new BitmapLuminanceSource(image);
     //}
     //else
     //{
     //   int[] crop = config.Crop;
     //   source = new BitmapLuminanceSource(image).crop(crop[0], crop[1], crop[2], crop[3]);
     //}

     // BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

     // if (config.DumpBlackPoint)
     //{
     //   dumpBlackPoint(uri, image, bitmap);
     //}
// Result result = new MultiFormatReader().decode(bitmap, hints);
    //  BarcodeReader reader = new BarcodeReader();
    //  Result result = reader.Decode(image);

// ZXing.OneD.Code39Reader reader39 = new ZXing.OneD.Code39Reader(true, true);
// ZXing.OneD.Code39Reader reader39 = new ZXing.OneD.Code39Reader(true, false);
// ZXing.OneD.Code39Reader reader39 = new ZXing.OneD.Code39Reader(false, true);
// ZXing.OneD.Code39Reader reader39 = new ZXing.OneD.Code39Reader(false, false);

// Result result = reader39.decode(bitmap, hints);
// BarcodeReader reader = new BarcodeReader();
      //bombed with the 32 bit
      //Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.ARGB32);
      //Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.BGR32);
      //Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.BGRA32);
      //Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.RGBA32);
   //   Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.RGB32);
      //bombed with 24 bit
    //  Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.BGR24);
    //  Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.RGB24);
      //did not bomb with 8 bit or grayscale but did not read either
     //  Result result = reader.Decode(bimage, w, h, RGBLuminanceSource.BitmapFormat.Gray8);

     //  if (result != null)
     //{
     //   if (config.Brief)
     //   {
     //      Console.Out.WriteLine(uri + ": Success");
     //   }
     //   else
     //   {
     //      ParsedResult parsedResult = ResultParser.parseResult(result);
     //      Console.Out.WriteLine(uri + " (format: " + result.BarcodeFormat + ", type: " +
     //                            parsedResult.Type + "):\nRaw result:\n" + result.Text + "\nParsed result:\n" +
     //                            parsedResult.DisplayResult);

     //      Console.Out.WriteLine("Found " + result.ResultPoints.Length + " result points.");
     //      for (int i = 0; i < result.ResultPoints.Length; i++)
     //      {
     //         ResultPoint rp = result.ResultPoints[i];
     //         Console.Out.WriteLine("  Point " + i + ": (" + rp.X + ',' + rp.Y + ')');
     //      }
     //   }
     //}
     //else
     //{
     //   Console.Out.WriteLine(uri + ": No barcode found");
     //}
     //return result;
  }


Jul 20, 2013 at 2:20 PM
this is the freeimage read file routine

public static FIBITMAP loadFIBITMAP(string FileName)
  {


      FIBITMAP FIB;

      FileName = FileName.ToUpper();
      string TOutFile = System.Text.RegularExpressions.Regex.Replace(FileName, ".TIFF", ".TIF");
      TOutFile = System.Text.RegularExpressions.Regex.Replace(FileName, ".JPEG", ".JPG");

      string FEXT = TOutFile.Substring(TOutFile.LastIndexOf(".") + 1);

      switch (FEXT)
      {
          case "TIF":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TIFF, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "JPG":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PNG":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "BMP":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_BMP, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "GIF":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_GIF, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "CUT":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_CUT, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "DDS":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_DDS, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "EXR":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_EXR, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "G3":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_FAXG3, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "HDR":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_HDR, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "ICO":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_ICO, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "IFF":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_IFF, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "J2K":
          case "J2C":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_J2K, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "JNG":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JNG, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "KOA":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_KOALA, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "LBM":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_LBM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "MNG":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_MNG, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PBM":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PBM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PBMRAW, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PCD":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PCD, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PCX":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PCX, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PFM":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PFM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PGM":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PGM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PGMRAW, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);

              break;
          case "PICT":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PICT, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PPM":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PPM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PPMRAW, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "PSD":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PSD, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "RAS":
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_RAS, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "RAW": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_RAW, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "SGI": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_SGI, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "TGA": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TARGA, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "WBMP": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_WBMP, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "XBM": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_XBM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          case "XPM": // mask listed as *.* weird
              FIB = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_XPM, FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
              break;
          default:
              FREE_IMAGE_FORMAT tf = new FREE_IMAGE_FORMAT();
              tf = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
              FIB = FreeImage.LoadEx(FileName, ref tf);
              break;
      }



      return FIB;

  }
Coordinator
Jul 20, 2013 at 6:35 PM
Please try the following code snippet. With it I could decode 9 of 10 of your images.
var barcodeReader = new BarcodeReader
   {
      TryHarder = true,
      PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.CODE_39},
      Options =
         {
            UseCode39ExtendedMode = false
         }
   };
var result = barcodeReader.Decode(bitmap);
The "TryHarder = true" option is important if you want to scan some kind of documents. Without it the scanner only tries to find a barcode in the middle of the image.
That's an optimization for smartphone apps. The barcodes are centered in such cases.
Another important option is "UseCode39ExtendedMode = false" because there is a small error in the library which leads to an exception while decoding.
Jul 20, 2013 at 11:21 PM
Edited Jul 21, 2013 at 12:40 PM
SIR the results of 9 out of 10 are COMPLETELY UNACCEPTABLE.

I demand 10 out of 10 and I GOT IT!!!!!

First I am referring the 4.0 dll and the BarcodeReader does not have the Options options.

With a little research this is what I did.

in the main routine I added these lines. Note the config.Hints was null so maybe this is a bug?
[Edit - looking at the code I see where config.Hints is initialized but past the point I added my line]

config.TryHarder = true;
config.Hints = new Dictionary<DecodeHintType, object>();
config.Hints.Add(DecodeHintType.USE_CODE_39_EXTENDED_MODE, false);

that is all it took to make the decode routine work as is.

feels good. THANK YOU!!!