com.aspose.barcode.barcoderecognition

Class BarCodeReader

  • java.lang.Object
    • com.aspose.barcode.barcoderecognition.BarCodeReader


  • public class BarCodeReader
    extends java.lang.Object

    BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes


     Detect an code39 barcode with supplement.
     
         BarCodeReader reader = new BarCodeReader("test.jpg");
         for(BarCodeResult result : reader.readBarCodes(), DecodeType.CODE_39_STANDARD)
         {
              System.out.println("BarCode Type: " + result.getCodeTypeName());
              System.out.println("BarCode CodeText: " + result.getCodeText());
         }
     

    • Constructor Detail

      • BarCodeReader

        public BarCodeReader()

        Initializes a new instance of the BarCodeReader class with default values. Requires to set image setBitmapImage() before to call read() method.

      • BarCodeReader

        public BarCodeReader(java.awt.image.BufferedImage image)

        Initializes a new instance of the BarCodeReader class from an image.

        Parameters:
        image - A Bitmap instance containing the image
      • BarCodeReader

        public BarCodeReader(java.awt.image.BufferedImage image,
                             BaseDecodeType decodeType)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        image - The image.
        decodeType - Decode types.
      • BarCodeReader

        public BarCodeReader(java.awt.image.BufferedImage image,
                             BaseDecodeType... decodeTypes)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        image - The image.
        decodeTypes - Decode types.
      • BarCodeReader

        public BarCodeReader(java.awt.image.BufferedImage image,
                             java.awt.Rectangle area,
                             BaseDecodeType... decodeTypes)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        image - The image.
        area - The area for recognition.
        decodeTypes - Decode types.
      • BarCodeReader

        public BarCodeReader(java.awt.image.BufferedImage image,
                             java.awt.Rectangle[] areas,
                             BaseDecodeType type)
        Initializes a new instance of the BarCodeReader class.
        Parameters:
        image - The image to read.
        areas - The array of recognition areas.
        type - The decode type applicable for all the areas specified.
      • BarCodeReader

        public BarCodeReader(java.lang.String filename)

        Initializes a new instance of the BarCodeReader class from file.

        Parameters:
        filename - The filename.
      • BarCodeReader

        public BarCodeReader(java.lang.String filename,
                             BaseDecodeType type)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        filename - The filename.
        type - The BarCodeReadType.
      • BarCodeReader

        public BarCodeReader(java.lang.String filename,
                             BaseDecodeType... decodeTypes)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        filename - The filename.
        decodeTypes - Decode types.
      • BarCodeReader

        public BarCodeReader(java.io.InputStream stream)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        stream - The stream.
      • BarCodeReader

        public BarCodeReader(java.io.InputStream stream,
                             BaseDecodeType type)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        stream - The stream.
        type - The decode type.
      • BarCodeReader

        public BarCodeReader(java.io.InputStream stream,
                             BaseDecodeType... decodeTypes)

        Initializes a new instance of the BarCodeReader class.

        Parameters:
        stream - The stream.
        decodeTypes - Decode types.
    • Method Detail

      • getProcessorSettings

        public static ProcessorSettings getProcessorSettings()
        Gets a settings of using processor cores.
        Returns:
        settings of using processor cores.
      • getTimeout

        public int getTimeout()

        Gets the timeout of recognition process.

        Returns:
        The timeout.
      • setTimeout

        public void setTimeout(int value)

        Sets the timeout of recognition process.

        Parameters:
        value - The timeout.
      • getChecksumValidation

        public ChecksumValidation getChecksumValidation()

        Enable checksum validation during recognition for 1D barcodes.

        Default is treated as Yes for symbologies which must contain checksum, as No where checksum only possible.

        Checksum never used: Codabar

        Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN

        Checksum always used: Rest symbologies

        Returns:
        The checksum validation flag.
      • setChecksumValidation

        public void setChecksumValidation(ChecksumValidation value)
        Enable checksum validation during recognition for 1D barcodes. Default is treated as Yes for symbologies which must contain checksum, as No where checksum only possible. Checksum never used: Codabar Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN Checksum always used: Rest symbologies
        Parameters:
        value - The checksum validation flag.
      • setChecksumValidation

        @Deprecated
        public void setChecksumValidation(int value)
        Deprecated. 
        Enable checksum validation during recognition for 1D barcodes. Default is treated as Yes for symbologies which must contain checksum, as No where checksum only possible. Checksum never used: Codabar Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN Checksum always used: Rest symbologies
        Parameters:
        value - The checksum validation flag.
      • getStripFNC

        public boolean getStripFNC()

        Strip FNC1, FNC2, FNC3 characters from codetext. Default value is false.

      • setStripFNC

        public void setStripFNC(boolean value)

        Strip FNC1, FNC2, FNC3 characters from codetext. Default value is false.

      • getCustomerInformationInterpretingType

        public CustomerInformationInterpretingType getCustomerInformationInterpretingType()

        Gets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other.

      • setCustomerInformationInterpretingType

        public void setCustomerInformationInterpretingType(CustomerInformationInterpretingType value)

        Sets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other.

      • setCustomerInformationInterpretingType

        public void setCustomerInformationInterpretingType(int value)

        Sets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other.

      • close

        @Deprecated
        public void close()
        Deprecated. 

        Closes barcode reader.

      • abort

        public void abort()

        Function requests termination of current recognition session from other thread. Abort is unblockable method and returns control just after calling. The method should be used when recognition process is too long.

      • read

        @Deprecated
        public boolean read()
        Deprecated. This method is obsolete. Call BarCodeReader.ReadBarCodes() instead.

        Reads barcode from the image.


         Detect AllSupportedTypes
         
         BarCodeReader reader;
         reader = new BarCodeReader("c:\\test.jpg");
         while(reader.read())
         {
             System.out.println("BarCode Type: "+reader.getReadType());
             System.out.println("BarCode CodeText: " + reader.getCodeText());
         }
         reader.close();
         

        Returns:
        True if the next barcode was read successfully; false if there are no more nodes to read.
      • getFoundBarCodes

        public BarCodeResult[] getFoundBarCodes()

        Gets recognized BarCodeResults array


         This sample shows how to access to read with BarCodeReader barcodes
         
         BarCodeReader reader = new BarCodeReader("test.jpg");
         reader.readBarCodes();
         for(int i = 0; reader.getFoundCount() > i; ++i)
              System.out.println("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
         

        Value: The recognized BarCodeResults array
      • getFoundCount

        public int getFoundCount()

        Gets recognized barcodes count


         This sample shows how to access to read with BarCodeReader barcodes
         
         BarCodeReader reader = new BarCodeReader("test.jpg");
         reader.readBarCodes();
         for(int i = 0; reader.getFoundCount() > i; ++i)
               System.out.println("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
         

        Value: The recognized barcodes count
      • readBarCodes

        public BarCodeResult[] readBarCodes()

        Reads BarCodeResults from the image.


         This sample shows how to detect any barcode.
         
         BarCodeReader reader = new BarCodeReader("test.jpg");
         for (BarCodeResult result : reader.readBarCodes())
             System.out.println(("BarCode CodeText: " + result.getCodeText());
         BarCodeReader reader = new BarCodeReader("test.jpg");
         reader.readBarCodes();
         for(int i = 0; reader.getFoundCount() > i; ++i)
             System.out.println(("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
         

        Returns:
        Returns array of recognized BarCodeResults on the image. If nothing is recognized, zero array is returned.
      • getQualitySettings

        public final QualitySettings getQualitySettings()

        QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.


         This sample shows how to use QualitySettings with BarCodeReader
         
         BarCodeReader reader = new BarCodeReader("test.jpg");
         //set high performance mode
         reader.setQualitySettings(QualitySettings.getHighPerformance());
         for (BarCodeResult result : reader.readBarCodes())
            System.out.println(("BarCode CodeText: " + result.getCodeText());
        
         BarCodeReader reader = new BarCodeReader("test.jpg");
         //set high performance mode
         reader.setQualitySettings(QualitySettings.getHighPerformance());
         //set separate options
         reader.getQualitySettings().setAllowMedianSmoothing(true);
         reader.getQualitySettings().setMedianSmoothingWindowSize(5);
         for (BarCodeResult result : reader.readBarCodes())
            System.out.println("BarCode CodeText: " + result.getCodeText());
        
         BarCodeReader reader = new BarCodeReader("test.jpg");
         //default mode is NormalQuality
         //set separate options
         reader.getQualitySettings().setAllowMedianSmoothing(true);
         reader.getQualitySettings().setMedianSmoothingWindowSize(5);
         for(BarCodeResult result : reader.readBarCodes();
             System.out.println("BarCode CodeText: " + result.getCodeText());
         

        Value: QualitySettings to configure recognition quality and speed.
      • setQualitySettings

        public final void setQualitySettings(QualitySettings value)

        QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.


         This sample shows how to use QualitySettings with BarCodeReader
         
         BarCodeReader reader = new BarCodeReader("test.png");
          //set high performance mode
         reader.setQualitySettings(QualitySettings.getHighPerformance());
         while (reader.read())
         {
             System.out.println("BarCode CodeText: " + reader.getCodeText());
         }
        
         BarCodeReader reader = new BarCodeReader("test.png");
         //set high performance mode
         reader.setQualitySettings(QualitySettings.getHighPerformance());
         //set separate options
         reader.getQualitySettings().setAllowMedianSmoothing(true);
         reader.getQualitySettings().setMedianSmoothingWindowSize(5);
         while (reader.read())
         {
           System.out.println("BarCode CodeText: " + reader.getCodeText());
         }
        
         BarCodeReader reader = new BarCodeReader("test.png");
         //default mode is NormalQuality
         //set separate options
         reader.getQualitySettings().setAllowMedianSmoothing(true);
         reader.getQualitySettings().setMedianSmoothingWindowSize(5);
         while (reader.read())
         {
            System.out.println("BarCode CodeText: " + reader.getCodeText());
         }
         

        Value: QualitySettings to configure recognition quality and speed.
      • getCodeText

        @Deprecated
        public java.lang.String getCodeText()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].CodeText instead.

        Gets the code text. Text will not contain the checksum for 1D barcode types, which support the checksum. Please use GetCodeText(true) method to get result with checksum.

        Returns:
        The code text of the barcode.
      • getCodeText

        @Deprecated
        public java.lang.String getCodeText(java.nio.charset.Charset encoding)
        Deprecated. This method is obsolete. Call BarCodeReader.FoundBarCodes[].GetCodeText() instead.

        Gets the code text with encoding.

        Parameters:
        encoding - The encoding for codetext.
        Returns:
        A string containing recognized code text.
      • getCodeText

        @Deprecated
        public java.lang.String getCodeText(boolean includeCheckSum)
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].CodeText instead.
        Gets the code text. Allows to include checksum into result when includeCheckSum is true.
        Parameters:
        includeCheckSum - true to include CheckSum into result; false to return only CodeText.
        Returns:
        The code text of the barcode with CheckSum or not.
      • getCheckSum

        @Deprecated
        public java.lang.String getCheckSum()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.OneD.CheckSum instead.

        Gets the checksum for 1D barcodes.

        Returns:
        The checksum for 1D barcode.
      • getAngle

        @Deprecated
        public float getAngle()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Region.Angle instead.

        Gets the angle of the barcode (0-360).

        Returns:
        The angle for barcode (0-360).
      • getCodeBytes

        @Deprecated
        public byte[] getCodeBytes()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].CodeBytes instead.

        Gets the encoded code bytes.

        Returns:
        The code bytes of the barcode.
      • getMacroPdf417FileID

        @Deprecated
        public java.lang.String getMacroPdf417FileID()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.Pdf417.MacroPdf417FileID instead.

        Gets the file ID of the barcode, only available with MacroPdf417.

        Returns:
        The file ID for MacroPdf417
      • getMacroPdf417SegmentID

        @Deprecated
        public int getMacroPdf417SegmentID()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.Pdf417.MacroPdf417SegmentID instead.

        Gets the segment ID of the barcode,only available with MacroPdf417.

        Returns:
        The segment ID of the barcode.
      • getMacroPdf417SegmentsCount

        @Deprecated
        public int getMacroPdf417SegmentsCount()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.Pdf417.MacroPdf417SegmentsCount instead.

        Gets macro pdf417 barcode segments count. Default value is -1.

        Returns:
        The segments count.
      • getCode128DataPortions

        @Deprecated
        public Code128DataPortion[] getCode128DataPortions()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.Code128.Code128DataPortions instead.
        Gets Code128DataPortion instance for recognized Code128 barcode
        Returns:
        The array of Code128DataPortion objects.
      • getQRStructuredAppendModeBarCodesQuantity

        @Deprecated
        public int getQRStructuredAppendModeBarCodesQuantity()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.QR.QRStructuredAppendModeBarCodesQuantity instead.

        Gets the QR structured append mode barcodes quantity. Default value is -1.

        Returns:
        The quantity of the QR structured append mode barcode.
      • getQRStructuredAppendModeBarCodeIndex

        @Deprecated
        public int getQRStructuredAppendModeBarCodeIndex()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.QR.QRStructuredAppendModeBarCodeIndex instead.

        Gets the index of the QR structured append mode barcode. Index starts from 0. DEFAULT value is -1.

        Returns:
        The index of the QR structured append mode barcode.
      • getQRStructuredAppendModeParityData

        @Deprecated
        public int getQRStructuredAppendModeParityData()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Extended.QR.QRStructuredAppendModeParityData instead.

        Gets the QR structured append mode parity data. Default value is -1.

        Returns:
        The QR structured append mode parity data.
      • getIsDeniable

        @Deprecated
        public boolean getIsDeniable()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Confidence instead.

        Checks the deniable recognition. Such recognition might occur in QualitySettings.MAX_BARCODES mode decoding or use QualitySettings.ALLOW_INCORRECT_BARCODES

        Returns:
        True if the deniable recognition was read.
      • getRegion

        @Deprecated
        public BarCodeRegion getRegion()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].Region instead.

        Gets the barcode region.

        Returns:
        The region of the recognized barcode.
      • getCodeType

        @Deprecated
        public SingleDecodeType getCodeType()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].CodeType instead.

        Gets the barcode type.

        Returns:
        The type information of the recognized barcode.
      • getCodeTypeName

        @Deprecated
        public java.lang.String getCodeTypeName()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].CodeTypeName instead.

        Gets the name of the barcode type.

        Returns:
        The type name of the recognized barcode.
      • getRecognitionQuality

        @Deprecated
        public float getRecognitionQuality()
        Deprecated. This method is obsolete. Use BarCodeReader.FoundBarCodes[].ReadingQuality instead.

        Gets the recognition quality. Works for 1D and postal barcodes.

        Returns:
        The recognition quality percent.
      • getDetectEncoding

        public boolean getDetectEncoding()

        A flag which force engine to detect codetext encoding for Unicode codesets.


          This sample shows how to detect text encoding on the fly if DetectEncoding is enabled
          
         InputStream is = new ByteArrayInputStream(new byte[...]);
         BarCodeBuilder bb = new BarCodeBuilder())
         bb.setCodeText("�����");
         bb.setEncodeType(EncodeTypes.QR);
         bb.setCodeTextEncoding(Charset.forName("UTF-8"));
         bb.save(is, BarCodeImageFormat.PNG);
        
         reader = new BarCodeReader(is, BarCodeReadType.QR);
         reader.setDetectEncoding(true);
         for(BarCodeResult result : reader.readBarCodes())
           System.out.println("BarCode CodeText: " + result.getCodeText());
        
         is.setPosition(0);
         reader = new BarCodeReader(is, BarCodeReadType.QR);
         reader.setDetectEncoding(false);
         for(BarCodeResult result : reader.readBarCodes())
           System.out.println("BarCode CodeText: " + result.getCodeText());
          

      • setDetectEncoding

        public void setDetectEncoding(boolean value)

        A flag which force engine to detect codetext encoding for Unicode codesets.


          This sample shows how to detect text encoding on the fly if DetectEncoding is enabled
          
         InputStream is = new ByteArrayInputStream(new byte[...]);
         BarCodeBuilder bb = new BarCodeBuilder())
         bb.setCodeText("�����");
         bb.setEncodeType(EncodeTypes.QR);
         bb.setCodeTextEncoding(Charset.forName("UTF-8"));
         bb.save(is, BarCodeImageFormat.PNG);
        
         reader = new BarCodeReader(is, BarCodeReadType.QR);
         reader.setDetectEncoding(true);
         for(BarCodeResult result : reader.readBarCodes())
           System.out.println("BarCode CodeText: " + result.getCodeText());
        
         is.setPosition(0);
         reader = new BarCodeReader(is, BarCodeReadType.QR);
         reader.setDetectEncoding(false);
         for(BarCodeResult result : reader.readBarCodes())
           System.out.println("BarCode CodeText: " + result.getCodeText());
          

      • setBarCodeImage

        public final void setBarCodeImage(java.awt.image.BufferedImage value,
                                          java.awt.Rectangle[] areas)

        Sets bitmap image and areas for recognition. Must be called before Read() method.

        Parameters:
        value - The bitmap image for recognition.
        areas - areas list for recognition
      • setBarCodeImage

        public final void setBarCodeImage(java.awt.image.BufferedImage value,
                                          java.awt.Rectangle area)

        Sets bitmap image and area for recognition. Must be called before Read() method.

        Parameters:
        value - The bitmap image for recognition.
        area - area for recognition
      • setBarCodeImage

        public final void setBarCodeImage(java.io.InputStream stream)

        Sets image stream for recognition. Must be called before Read() method.

        Parameters:
        stream - The image stream for recogniton.
      • setBarCodeImage

        public void setBarCodeImage(java.awt.image.BufferedImage value)

        Sets bitmap image for recognition. Must be called before Read() method.

        Parameters:
        value - The bitmap image for recognition.
      • setBarCodeImage

        public void setBarCodeImage(java.lang.String filename)

        Sets image file for recogniton. Must be called before Read() method.

        Parameters:
        filename - The image file for recogniton.
      • setBarCodeReadType

        public void setBarCodeReadType(SingleDecodeType... barcodeTypes)

        Sets SingleDecodeType type array for recognition. Must be called before Read() method.

        Parameters:
        barcodeTypes - The SingleDecodeType type array to read.
      • setBarCodeReadType

        public void setBarCodeReadType(BaseDecodeType type)

        Sets BarCodeReadType for recognition. Must be called before Read() method.

        Parameters:
        type - The type of barcode to read.
      • dispose

        public void dispose()
      • exportToXml

        public boolean exportToXml(java.lang.String xmlFile)

        Exports BarCode properties to the xml-file specified

        Parameters:
        xmlFile - The name for the file
        Returns:
        Whether or not export completed successfully.

        Returns <b>True</b> in case of success; <b>False</b> Otherwise

      • importFromXml

        public static BarCodeReader importFromXml(java.lang.String xmlFile)

        Imports BarCode properties from the xml-file specified and applies them to the current BarCodeBuilder instance.

        Parameters:
        xmlFile - The name for the file
        Returns:
        Returns <b>True</b> in case of success;

        <b>False</b> Otherwise