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 Read operation to detect barcodes


     Detect an code39 barcode with supplement.
     
     BarCodeReader reader;
     reader = new BarCodeReader("c:\\test.jpg",BarCodeReadType.Code39Standard);
     while(reader.read())
     {
         System.out.println("BarCode Type: "+reader.getReadType());
         System.out.println("BarCode CodeText: " + reader.getCodeText());
     }
     reader.close();
     

    • 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... 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

      • isLicensed

        public boolean isLicensed()

        Gets a value indicating whether recognition module is licensed.

        Returns:
        true if recognition module is licensed; otherwise, false.
      • getProcessorSettings

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

        public java.lang.String getFileName()
        Gets file name which was assigned by user
        Returns:
        The file name
      • 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 int 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(int 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.
      • getMedianSmoothingWindowSize

        public int getMedianSmoothingWindowSize()

        Gets the median smoothing window size. Typical values are 3 or 4. Default value is 3. Recognition hint MedianSmoothing must be set.

        Returns:
        The median smoothing window size. Typical values are 3 or 4. Default value is 3.
      • setMedianSmoothingWindowSize

        public void setMedianSmoothingWindowSize(int value)

        Sets the median smoothing window size. Typical values are 3 or 4. Default value is 3. Recognition hint MedianSmoothing must be set.

        Parameters:
        value - The median smoothing window size. Typical values are 3 or 4. Default value is 3.
      • getExpectedBarCodeCount

        public int getExpectedBarCodeCount()

        Expected barcodes to be found.The reader will stop reading the image once it found barcodes more than this value. Default value is int.MaxValue.

        Returns:
        Count of barcodes
      • setExpectedBarCodeCount

        public void setExpectedBarCodeCount(int value)

        Expected barcodes to be found.The reader will stop reading the image once it found barcodes more than this value. Default value is int.MaxValue.

        Parameters:
        value - Count of barcodes
      • 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 int getCustomerInformationInterpretingType()

        Gets 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

        public void close()

        Closes barcode reader.

      • read

        public boolean read()

        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.
      • getRecognitionMode

        public int getRecognitionMode()

        Gets or sets the recognition mode. This property allows to quickly set up and tune the processing speed and quality in a way which is the most appropriate for you needs. Default value is MaxPerformance.

        Returns:
        The recognition mode. Default value is MaxPerformance.
      • getRecognitionModeName

        public java.lang.String getRecognitionModeName()

        Gets the RecognitionMode's name

        Returns:
        RecognitionMode's name
      • setRecognitionMode

        public void setRecognitionMode(int value)

        Gets or sets the recognition mode. This property allows to quickly set up and tune the processing speed and quality in a way which is the most appropriate for you needs.

        Parameters:
        value - The recognition mode. Default value is MaxPerformance.
      • getOrientationHints

        public int getOrientationHints()

        Gets the orientation hints.

        Returns:
        The orientation hints. Default value is NoRotate.
      • getOrientationHintsName

        public java.lang.String getOrientationHintsName()

        Gets name of OrientationHints property

        Returns:
        name of OrientationHints property
      • setOrientationHints

        public void setOrientationHints(int value)

        Sets the orientation hints.

        Parameters:
        value - The orientation hints. Default value is NoRotate.
      • getManualHints

        public int getManualHints()

        Allows you to configure options of recognition accuracy and speed manually. You need to change the property "RecognitionMode" to "RecognitionMode.ManualHints". Default value is None.


         
         reader.setRecognitionMode(RecognitionMode.ManualHints);
         reader.setManualHints(ManualHint.InvertImage| ManualHint.IncorrectBarcodes);
         

        Returns:
        The manual hints. Default value is None.
      • getManualHintsName

        public java.lang.String getManualHintsName()

        Gets name of ManualHints property

        Returns:
        The name of ManualHints property
      • setManualHints

        public void setManualHints(int value)

        Allows you to configure options of recognition accuracy and speed manually. You need to change the property "RecognitionMode" to "RecognitionMode.ManualHints". Default value is None.


         
         reader.setRecognitionMode(RecognitionMode.ManualHints);
         reader.setManualHints(ManualHint.InvertImage| ManualHint.IncorrectBarcodes);
         

        Parameters:
        value - The manual hints. Default value is None.
      • getCodeText

        public java.lang.String getCodeText()

        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

        public java.lang.String getCodeText(java.nio.charset.Charset encoding)

        Gets the code text with encoding.

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

        public java.lang.String getCodeText(boolean includeCheckSum)
        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

        public java.lang.String getCheckSum()

        Gets the checksum for 1D barcodes.

        Returns:
        The checksum for 1D barcode.
      • getAngle

        public float getAngle()

        Gets the angle of the barcode (0-360). RecognitionHints.Orientation enum does not included into the calculation.

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

        public byte[] getCodeBytes()

        Gets the encoded code bytes.

        Returns:
        The code bytes of the barcode.
      • getMacroPdf417FileID

        public java.lang.String getMacroPdf417FileID()

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

        Returns:
        The file ID for MacroPdf417
      • getMacroPdf417SegmentID

        public int getMacroPdf417SegmentID()

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

        Returns:
        The segment ID of the barcode.
      • getMacroPdf417SegmentsCount

        public int getMacroPdf417SegmentsCount()

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

        Returns:
        The segments count.
      • getCode128DataPortions

        public Code128DataPortion[] getCode128DataPortions()
        Gets Code128DataPortion instance for recognized Code128 barcode
        Returns:
        The array of Code128DataPortion objects.
      • getQRStructuredAppendModeBarCodesQuantity

        public int getQRStructuredAppendModeBarCodesQuantity()

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

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

        public int getQRStructuredAppendModeBarCodeIndex()

        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

        public int getQRStructuredAppendModeParityData()

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

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

        public boolean getIsDeniable()

        Checks the deniable recognition. Such recognition might occur in max count mode decoding or use ManualHint.IncorrectBarcodes

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

        public BarCodeRegion getRegion()

        Gets the barcode region.

        Returns:
        The region of the recognized barcode.
      • getCodeType

        public SingleDecodeType getCodeType()

        Gets the barcode type.

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

        public java.lang.String getCodeTypeName()

        Gets the name of the barcode type.

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

        public float getRecognitionQuality()

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

        Returns:
        The recognition quality percent.
      • getAllPossibleBarCodes

        public com.aspose.barcode.barcoderecognition.PossibleBarCode[] getAllPossibleBarCodes()

        Gets all possible barcodes found. Only for 1D barcodes. Includes correct answer if the barcode recognized fine.

        Returns:
        The array of possible 1D barcodes. Includes correct answer if the barcode recognized fine.
      • getDetectEncoding

        public boolean getDetectEncoding()

        Gets flag to detect codetext encoding for unicode codesets.

        Returns:
        Returns detection flag
      • setDetectEncoding

        public void setDetectEncoding(boolean value)

        Sets flag to detect codetext encoding for unicode codesets.


          Detection text encoding on the fly if DetectEncoding is enabled
          
         InputStream is = new ByteArrayInputStream(new byte[...]);
         BarCodeBuilder bb = new BarCodeBuilder();
         bb.setCodeText("");
         bb.setSymbologyType(Symbology.QR);
         bb.setCodeTextEncoding(Encoding.UTF8);
         bb.save(is, BarCodeImageFormat.Png);
         BarCodeReader reader = new BarCodeReader(is, BarCodeReadType.QR);
         reader.setDetectEncoding(true);
         while(reader.read())
            System.out.println("BarCode CodeText: " + reader.GetCodeText());
         is.setPosition(0);
         BarCodeReader reader1 = new BarCodeReader(is, BarCodeReadType.QR);
         reader1.setDetectEncoding(false);
         while(reader1.read())
            System.out.println("BarCode CodeText: " + reader1.GetCodeText(Encoding.UTF8));
          

        Parameters:
        value - The flag to detect codetext encoding.
      • 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(BaseDecodeType type)

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

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

        protected void dispose(boolean disposing)

        Release resource

        Parameters:
        disposing - true to release both managed and unmanaged resources; false to release only unmanaged resources.
      • 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