Exemplo n.º 1
0
        private void readFileOnThread()
        {
            BarcodeReader reader = null;
            try
            {
                reader = new BarcodeReader();
                if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
                // configure directions
                reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
                //configure types
                reader.Code128 = true; reader.Code39 = true;
                // Configure events
                reader.BarcodeFoundEvent += new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFoundThread);
                // Read
                while (true)
                {
                    string fileName;
                    // Obtain next file name
                    lock (_lockObject)
                    {
                        if (filesScanned >= filesToScan.Length)
                            break;
                        fileName = filesToScan[filesScanned];
                        filesScanned++;
                    }
                    //  Read images from file
                    try
                    {
#if false
                       reader.Read(fileName);     // Read all pages
#else
                        reader.Read(fileName, 1);  // Read only page 1
#endif
                    }
                    catch (Exception ex)
                    {
                        string s = txtRslt.Text + ">>>>>>>> ERROR processing '" + fileName + "'" +
                            Environment.NewLine + ex.Message + Environment.NewLine;
                        lock (_lockObject)
                        {
                            SetControlPropertyThreadSafe(txtRslt, "Text", s);
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string s = txtRslt.Text + ">>>>>>>> ERROR processing '" + Environment.NewLine + ex.Message + Environment.NewLine;
                lock (_lockObject)
                {
                    SetControlPropertyThreadSafe(txtRslt, "Text", s);
                    System.Windows.Forms.Application.DoEvents();
                }
            }
            finally
            {
                if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
            }
        }
Exemplo n.º 2
0
 internal string readQR(string fileName, int page)
 {
     BarcodeReader reader = null;
     try
     {
         reader = new BarcodeReader();
         if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         //configure types
         reader.QR = true;
         Barcode[] barcodes = reader.Read(fileName, page);
         mBarcodes = sortBarcode(barcodes);
         string s = ""; int cnt = 0;
         foreach (Barcode bc in mBarcodes)
         { cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) { s = "NO BARCODES"; }
         return s;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
     finally
     {
         if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
     }
 }
Exemplo n.º 3
0
 internal string readFromStream(string fileName)
 {
     BarcodeReader reader = null;
     try
     {
         reader = new BarcodeReader();
         if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         //configure types
         reader.Code128 = true; reader.Code39 = true;
         string s = "";
         using (MemoryStream ms = Utility.FileToStream(fileName))
         {
             Barcode[] barcodes = reader.Read(ms);
              int cnt = 0;
             foreach (Barcode bc in barcodes)
             { cnt++; AddBarcode(ref s, cnt, bc); }
             if (cnt == 0) { s = s + "NO BARCODES"; }
         }
         s = s + Environment.NewLine;
         return s;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
     finally
     {
         if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
     }
 }
Exemplo n.º 4
0
 internal string readWithEvents(string fileName)
 {
     BarcodeReader reader = null;
     try
     {
         reader = new BarcodeReader();
         if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         //configure types
         reader.Code128 = true; reader.Code39 = true;
         // Configure events
         reader.BarcodeFoundEvent += new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFound);
         // Read
         reader.Read(fileName);
         if ((txtRslt.Text == "")) { txtRslt.Text = "NO BARCODES"; }
         return "";  //  txtRslt.Text is already updated;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
     finally
     {
         if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
     }
 }
Exemplo n.º 5
0
 internal string readWithZones(string fileName, int page)
 {
     BarcodeReader reader = null;
     try
     {
         reader = new BarcodeReader();
         if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         //configure types
         reader.Code128 = true; reader.Code39 = true;
         ImageIO io = new ImageIO();
         ImageInfo info = io.Info(fileName, page);
         string s = "======= Barcode in ZONE (upper half of the image) ===========" + Environment.NewLine;
         // Set zone to top half of the image
         reader.Zone = new Rectangle(0, 0, info.Width, info.Height / 2);
         Barcode[] barcodes = reader.Read(fileName, page);
         int cnt = 0;
         foreach (Barcode bc in barcodes)
         { cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) { s = s + "NO BARCODES"; }
         s = s + Environment.NewLine;
         s = s + "======= Barcode in IMAGE ===========" + Environment.NewLine;
         // Disable zone
         reader.Zone = new Rectangle();
         barcodes = reader.Read(fileName, page);
         cnt = 0;
         foreach (Barcode bc in barcodes)
         { cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) { s = s + "NO BARCODES"; }
         return s;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
     finally
     {
         if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
     }
 }
Exemplo n.º 6
0
        public IEnumerable <RecognitionResult> Recognize(IImage bitmap, ZoneConfiguration config)
        {
            string text;

            try
            {
                var bmp      = bitmap.ToGray().ToBitmap();
                var barcodes = barcodeReader.Read(bmp);
                text = barcodes.FirstOrDefault()?.Text;
            }
            catch
            {
                text = null;
            }

            yield return(new RecognitionResult(text, 1D));
        }
Exemplo n.º 7
0
        public void ReadBarcode(string fileName, int page, string workingDate)
        {
            List <BarcodeModel> barcodemodelList = new List <BarcodeModel>();
            string workerId = "";

            try
            {
                BarcodeReader reader = new BarcodeReader();
                reader.Pdf417 = true;
                // reader.DataMatrix = true;
                // reader.QR = true;
                Inlite.ClearImageNet.Barcode[] barcodes = reader.Read(fileName, page);
                // Process results

                foreach (Inlite.ClearImageNet.Barcode bc in barcodes)
                {
                    string[] smv = bc.Text.ToString().Split(',');
                    if (smv.Length < 2)
                    {
                        workerId = smv[0];
                        if (workerId.Length == 5)
                        {
                            workerId = '0' + workerId;
                        }
                        else if (workerId.Length == 4)
                        {
                            workerId = "00" + workerId;
                        }
                    }
                    else
                    {
                        BarcodeModel barcode = new BarcodeModel();
                        barcode.BarcodeNumber       = System.Int32.Parse(smv[0]);
                        barcode.StandardMinuteValue = float.Parse(smv[1]);
                        barcodemodelList.Add(barcode);
                    }
                }   // do other processing
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            DataSaveToDatabase(barcodemodelList, workerId, workingDate);
        }
Exemplo n.º 8
0
        public static Tuple <string, Rectangle>[] DecodeQR(Bitmap input)
        {
            BarcodeReader reader = new BarcodeReader();

            reader.QR = true;
            Barcode[] barcodes = reader.Read(input);
            Tuple <string, Rectangle>[] output = new Tuple <string, Rectangle> [barcodes.Length];
            int i = 0;

            foreach (Barcode bc in barcodes)
            {
                Rectangle QrLocation = bc.Rectangle;
                output[i] = new Tuple <string, Rectangle>(bc.Text, QrLocation);
                i++;
            }
            if (output.Length == 0)
            {
                return(null);
            }
            return(output);
        }
Exemplo n.º 9
0
        void ReadBarcodes1D(string fileName, int page)
        {
            BarcodeReader reader = null;

            try
            {
                reader        = new BarcodeReader();              // Create and configure reader
                reader.Code39 = true; reader.Code128 = true;
                Barcode[] barcodes = reader.Read(fileName, page); // Read barcodes
                foreach (Barcode barcode in barcodes)             // Process results
                {
                    Console.WriteLine("Barcode type: " + barcode.Type.ToString() + "  Text: " + Environment.NewLine + barcode.Text);
                }
            }
            catch (Exception ex)
            { Console.WriteLine("Exception: " + ex.ToString()); }
            finally
            { if (reader != null)
              {
                  reader.Dispose();
              }
            }                                          // ClearImage 9 and latter.  Free image memory.
        }
Exemplo n.º 10
0
 internal string readDriverLicense(string fileName, int page)
 {
     BarcodeReader reader = null;
     try
     {
         reader = new BarcodeReader();
         if (tbrCode != 0) reader.TbrCode = tbrCode;// ClearImage V9 and later. Otherwise use:  reader.Read(tbrCode.ToString(), 456780);
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         //configure types
         reader.DrvLicID = true;
         Barcode[] barcodes = reader.Read(fileName, page);
         string s = ""; int cnt = 0;
         foreach (Barcode bc in barcodes)
         {
             cnt++;
             if (bc.Type == BarcodeType.Pdf417)
             {
                 // Decode and display AAMVA data as XML
                 string aamva = bc.Decode(BarcodeDecoding.aamva);
                 if (aamva != "")
                     s = s + "Driver License / ID Data: " + Environment.NewLine + aamva + Environment.NewLine;
             }
             AddBarcode(ref s, cnt, bc);
         }
         if (cnt == 0) { s = "NO BARCODES"; }
         return s;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
     finally
     {
         if (reader != null) reader.Dispose();  // ClearImage V9 and later.  Immediately free memory
     }
 }
Exemplo n.º 11
0
 public string Read1DPro_Stream(string fileName)
 {
     MemoryStream ms = Utility.FileToStream(fileName);
     BarcodeReader reader = new BarcodeReader();
     // Configure events
     //    reader.BarcodeFoundEvent += new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFound);
     // configure directions
     reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
     //configure types
     reader.Auto1D = true;
     Barcode[] barcodes = reader.Read(ms);
     string s = ""; int cnt = 0;
     foreach (Barcode bc in barcodes)
      { cnt++; AddBarcode(ref s, cnt, bc); }
     if (cnt == 0) { s = s + "NO BARCODES"; }
     s = s + Environment.NewLine;
     return s;
 }
Exemplo n.º 12
0
 public string Read1DPro_File_WithEvents(string fileName)
 {
     BarcodeReader reader = new BarcodeReader();
         // configure directions
         reader.Horizontal = true;
         reader.Vertical = false; reader.Diagonal = false;
         //configure types
         reader.Auto1D = true;
             // Configure events
         reader.BarcodeFoundEvent += new BarcodeReader.BarcodeFoundEventHandler (_OnBarcodeFound);
             // Read
         reader.Read (fileName);
         if ((txtRslt.Text == "")) { txtRslt.Text = "NO BARCODES"; }
         return txtRslt.Text;
 }
Exemplo n.º 13
0
 public string Read1DPro_File(string fileName)
 {
     BarcodeReader reader = new BarcodeReader();
     // configure directions
     reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
     //configure types
     reader.Code39 = true;
     reader.Code128= true;
     // Read Code39 and Code128 barcodes in file
     Barcode[] barcodes = reader.Read(fileName);
     string s = "";int cnt = 0;
     foreach (Barcode bc in barcodes)
        { cnt++; AddBarcode(ref s, cnt, bc); }
     if (cnt == 0) { s = s + "NO BARCODES"; }
     s = s + Environment.NewLine;
     return s;
 }
Exemplo n.º 14
0
 private void Read1DPro_OnThread()
 {
     BarcodeReader reader = new BarcodeReader();
     #if false
      // configure directions
      reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
      //configure types
      reader.Auto1D = true;
     #else
      // configure directions
      reader.Horizontal = true;
      //configure types
      reader.Code39 = true;
     #endif
      // Configure events
      reader.BarcodeFoundEvent += new BarcodeReader.BarcodeFoundEventHandler(_OnBarcodeFoundThread);
      // Read
      while (true)
      {
      string fileName;
         // Obtain next file name
      lock (_lockObject)
      {
          if (filesScanned >= filesToScan.Length)
              break;
          fileName = filesToScan[filesScanned];
          filesScanned++;
      }
         //  Read images from file
      try
      {
     #if false
          reader.Read(fileName);     // Read all pages
     #else
          reader.Read(fileName, 1);  // Read only page 1
     #endif
      }
      catch (Exception ex)
      {
          string s = txtRslt.Text + ">>>>>>>> ERROR processing '" + fileName + "'" +
              Environment.NewLine + ex.Message + Environment.NewLine;
          lock (_lockObject)
              {SetControlPropertyThreadSafe (txtRslt, "Text", s);
              System.Windows.Forms.Application.DoEvents();
             }
      }
      }
 }
Exemplo n.º 15
0
        public string ReadQR_Page(Bitmap btPic)
        {
            BarcodeReader reader = new BarcodeReader();
                // for faster reading specify only required direction
                reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
                // specify type
                reader.QR = true;

                string s = "";

                using (MemoryStream stream = new MemoryStream())
                {
                    btPic.Save(stream, ImageFormat.Bmp);
                    stream.Position = 0;

                    Barcode[] barcodes = reader.Read(stream);
                     int cnt = 0;
                    foreach (Barcode bc in barcodes)
                    { cnt++; AddBarcode(ref s, cnt, bc); }
                    if (cnt == 0)
                    {
                        s = "NO BARCODES";
                    }
                }
                return  s;
        }
Exemplo n.º 16
0
 public string ReadPdf417_Page(string fileName, int page)
 {
     BarcodeReader reader = new BarcodeReader();
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         // specify type
         reader.Pdf417 = true;
         Barcode[] barcodes = reader.Read (fileName, page);
         string s = "";  int cnt = 0;
         foreach (Barcode bc in barcodes)
             {cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) 		{ s = "NO BARCODES"; 	}
         return  s;
 }
Exemplo n.º 17
0
 public string ReadDrvLic_Page(string fileName, int page)
 {
     BarcodeReader reader = new BarcodeReader();
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
         // specify type
         reader.DrvLicID = true;
         Barcode[] barcodes = reader.Read(fileName, page);
         string s = ""; int cnt = 0;
         foreach (Barcode bc in barcodes)
         { cnt++;
             if (bc.Type == BarcodeType.Pdf417)
             {
                 // Decode and display AAMVA data as XML
                 string aamva = bc.Decode(BarcodeDecoding.aamva);
                 if (aamva != "")
                     s = s + "Driver License / ID Data: " + Environment.NewLine + aamva + Environment.NewLine;
             }
             AddBarcode(ref s, cnt, bc);
             }
         if (cnt == 0) { s = "NO BARCODES"; }
         return s;
 }
Exemplo n.º 18
0
 public string Read1DPro_Page_Zones(string fileName, int page)
 {
     string s = "";
         BarcodeReader reader = new BarcodeReader();
         // for faster reading specify only required direction
         reader.Horizontal = true; reader.Vertical = true; reader.Diagonal = true;
     #if false
         // For faster processing specify expected types
         reader.Code128 = true;
         reader.Code39 = true;
     #else
         // Read all most popular barcode types
         reader.Auto1D = true;
     #endif
         ImageIO io = new ImageIO();
         ImageInfo info = io.Info(fileName, page);
         s = s + "======= Barcode in ZONE (upper half of the image) ===========" + Environment.NewLine;
         // Set zone to top half of the image
         reader.Zone = new Rectangle (0,0,info.Width, info.Height/2);
         Barcode[] barcodes = reader.Read (fileName, page);
         int cnt = 0;
         foreach (Barcode bc in barcodes)
             {cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) 		{ s = s + "NO BARCODES"; 	}
         s = s +  Environment.NewLine;
         s = s + "======= Barcode in IMAGE ===========" + Environment.NewLine;
         // Disable zone
         reader.Zone = new Rectangle ();
         barcodes = reader.Read (fileName, page);
         cnt = 0;
         foreach (Barcode bc in barcodes)
             {cnt++; AddBarcode(ref s, cnt, bc); }
         if (cnt == 0) 		{ s = s + "NO BARCODES"; 	}
         return  s;
 }
Exemplo n.º 19
0
        public ProcessedDataEntry ProcessSheet(ConfigurationBase configuration, Mat sheet, Action <RectangleF, bool> OnOptionProcessed = null, string originalSheetPath = "")
        {
            OBRConfiguration obrConfiguration = (OBRConfiguration)configuration;

            RectangleF barcodeRegion = obrConfiguration.GetConfigArea.ConfigRect;

            // Configure reader
            //CiServer ciServer = Server.GetThreadServer();
            //CiBarcodePro barcodeReader = ciServer.CreateBarcodePro();
            barcodeReader.Auto1D = obrConfiguration.AutoDetect1DBarcode; // Enable automatic detection of barcode type (Slower processing)
            if (!obrConfiguration.AutoDetect1DBarcode)
            {                                                            // Select barcode types to read
                barcodeReader.Code128 = obrConfiguration.Code128;
                barcodeReader.Code93  = obrConfiguration.Code93;
                barcodeReader.Code39  = obrConfiguration.Code39;
            }
            if (obrConfiguration.CheckAll) // Limit barcode search direction (Faster processing)
            {
                barcodeReader.Horizontal = true;
                barcodeReader.Vertical   = true;
                barcodeReader.Diagonal   = true;
            }
            else
            {
                barcodeReader.Horizontal = obrConfiguration.CheckHorizontal;
                barcodeReader.Vertical   = obrConfiguration.CheckVertical;
                barcodeReader.Diagonal   = obrConfiguration.CheckDiagonal;
            }
            //barcodeReader.Algorithm = obrConfiguration.AlgorithmPreference;

            string output = "-";

            Barcode[] barcodes = null;
            using (Bitmap region = sheet.Bitmap.Clone(barcodeRegion, System.Drawing.Imaging.PixelFormat.Format8bppIndexed))
            {
                try
                {
                    barcodes = barcodeReader.Read(region);   // Read barcodes
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: " + ex.ToString());
                }
                finally
                {
                    if (barcodeReader != null)
                    {
                        barcodeReader.Dispose();
                    }
                }  //Free image memory.
                if (barcodes.Length == 0 && obrConfiguration.SearchFullIfNull)
                {
                    using (Mat orignalSheet = CvInvoke.Imread(originalSheetPath))
                    {
                        barcodes = barcodeReader.Read(orignalSheet.Bitmap);   // Read barcodes
                    }
                }
                output = barcodes.Length > 0 ? barcodes[0].Text : "-";
            }

            return(new ProcessedDataEntry(configuration.Title, output.ToCharArray(), new ProcessedDataType[] { ProcessedDataType.NORMAL }, new byte[0, 0], barcodes));
        }