Barcode reader not reading barcode for some Tif files

Hi Team,
I am working on POC for one of our client. Aspart of the POC our requirement is to read barcode from the all the pages of a Tif file. I have downloaded the trial version of Aspose Barcode api to read barcodes from Tiff file. When i run the code I could see that barcode is not readable for few of Tif files (attached sampe, one is readable and non-readble).

Below is the code snippet i am using to read the barcode. Please check and let me know if I am missing any details.

\";

public static void main (String args[]) {
	try {
		int scount = 0;
		int fcount = 0;
		File file = new File(folderPath);
		File []filearray = file.listFiles();
		for (int i = 0; i < filearray.length; i ++) {
			File tifFile = filearray[i];
			System.out.println("File "+tifFile.getAbsolutePath());
			if(decodeBarCode(new File(tifFile.getAbsolutePath())))
				scount++;
			else
				fcount++;
		}
		System.out.println("Success Count " + scount);
		System.out.println("Failed Count " + fcount);
	} catch (Exception e) {
		e.printStackTrace();
	}
}


private static boolean decodeBarCode(File file) throws Exception {
	BarCodeReader reader = new BarCodeReader(file.getAbsolutePath(), DecodeType.CODE_128);
	reader.setQualitySettings(QualitySettings.getHighPerformance());
	BarCodeResult []result = reader.readBarCodes();
	for (int j = 0; j < result.length; j++) {
		System.out.println("CodeText: " + result[j].getCodeText());
		//System.out.println("Symbology type: " + result[j].getCodeType());
		// Get checksum value
		//System.out.println("Checksum:" + result[j].getExtended().getOneD().getCheckSum());
	}
	if(result.length == 0) 
		return false;
	else
		return true;
}

}barcodeissues.zip (7.1 KB)

@dharmareddy,

Thanks for the sample TIFF files.

Please notice, after an initial test, I am able to reproduce the issue as you mentioned by using your sample TIFF files. I have logged a ticket with an id “BARCODEJAVA-1323” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Hello Amjad.

When can i expect the feedback on the ticket. Based on your feedback I can update the status to my client.

The client is intrested in purchasing the licence based on the outcome of POC.

@dharmareddy,

Please spare us little time to thoroughly evaluate your issue before we could share an update or ETA on your issue.

Hello Amjad,

Any feedback recvied from Technical team on the scanning issue?

@dharmareddy,

We are sorry but there no update on it yet. I have logged your concerns with your ticket into our database. Once there is any new information available, we will update you.

Hi Team,

My ticket is showing as Blocked. Any reason for this?

Also I did some code changes, now I am able to read the barcode from all the TIF, I have run the code on 130 TIF files, of which the api is able to read the barcode from 128 files. When i verified the manually I could see that out 128 files there are 22 files for which the api failed to decode the barcode correctly, I mean the api decoded the incorrect barcode value.

for example, for the file…Fax00000e1f.TIF, the barcode in the TIF is 220327141128015. But the code extracted different value : 08032714112****Recognized by Aspose Barcode Reader evaluation version. Only Code39Standard can be recognized without restrictions. Please buy license to use Aspose Barcode Reader without watermarks. Code128 Code128
BarCode Checksum:
Code128SubType : 3 $$ Decoded Barcode Data : 08032714112802

Below is the code I am using:

public static boolean decodeBarCode(BufferedImage imageFile) {
		boolean decode = false;
		String barcodeValue = "";
		BarCodeReader reader = new BarCodeReader(imageFile,com.aspose.barcode.barcoderecognition.DecodeType.CODE_128);
		reader.getQualitySettings().getAllowComplexBackground();
		//reader.setQualitySettings(QualitySettings.getNormalQuality());
		reader.setQualitySettings(QualitySettings.getHighQualityDetection());
		reader.getQualitySettings().setMedianSmoothingWindowSize(6);
		reader.getBarcodeSettings().setChecksumValidation(ChecksumValidation.ON);
		reader.getQualitySettings().setAllowOneDWipedBarsRestoration(true);
		reader.getBarcodeSettings().setStripFNC(true);
		reader.getBarcodeSettings().setDetectEncoding(true);
		reader.getQualitySettings().setAllowMedianSmoothing(false);
		reader.getQualitySettings().setAllowComplexBackground(true);
		reader.getQualitySettings().setAllowInvertImage(true);
		reader.getQualitySettings().setAllowDetectScanGap(true);
		reader.getQualitySettings().setAllowWhiteSpotsRemoving(true);
		reader.getQualitySettings().setAllowRegularImage(true);
		reader.getQualitySettings().setAllowSaltAndPaperFiltering(true);
		reader.getQualitySettings().setAllowIncorrectBarcodes(false);
		BarCodeResult [] result = reader.readBarCodes();
		for (int j = 0; j < result.length; j++) {
			System.out.println("CodeType : "+result[j].getCodeText()+" "+result[j].getCodeTypeName()+" "+result[j].getCodeType());
			byte[] codebyte = result[j].getCodeBytes();
			for (int ibyte = 0; ibyte < codebyte.length; ibyte++) {
				//System.out.println(codebyte[ibyte]);
			}
			ChecksumValidation checksum[] = ChecksumValidation.values();
			for (int c = 0; c < checksum.length; c++) {
				//System.out.println(checksum[c]);
			}
			decode = true;
			Code128DataPortion[] code128DataPortions = result[j].getExtended().getCode128().getCode128DataPortions();
			for (Code128DataPortion code128DataPortion : code128DataPortions) {
				System.out.println("BarCode Checksum: " + result[j].getExtended().getOneD().getCheckSum());
				barcodeValue = code128DataPortion.getData();
				System.out.println("Code128SubType : " + code128DataPortion.getCode128SubType()+" $$ Decoded Barcode Data : " + code128DataPortion.getData());
				break;
			}
		}
		return decode;
	}

Could you please verify and let me know if any code changes needs to be done to get the correct barcode value.Fax00000e1f.zip (10.1 KB)

@dharmareddy,

Yes, your issue is blocked by an internal ticket. The internal ticket was logged regarding enhancements for reading barcodes in TIFF files. Once we sort out the internal ticket, your issue will be resolved accordingly.

Could you please zip and attach all 22 files, we will log these images with the ticket, so your issue should be accurately fixed and tested.

Hi Amjad,

Sorry I cannot send these files as they client confidential documents however I have attached sample TIF to previous conversation.

Also is there any way to validate the decoded bar values is correct or not without manually opening the file and comparing

How to check the barcode image height and width, any steps to modify the height and width using custom values?

@dharmareddy,

Please spare us time as once we will evaluate the module and include enhancements for reading barcodes in TIFF files, those values would be ok.

See and browse the documents under the sections/sub-sections for your complete reference.

I did not answer to my question, is there any way to get the barcode height, widht & aread in the image file?

could you please share a code sample for that?

@dharmareddy,

See the following sample code on how to get barcode region details from the Image file:
e.g.
Sample code:

                 String img = "f:\\files\\barcodeimage.tiff";

                 // Initialize barcode reader
                 com.aspose.barcode.barcoderecognition.BarCodeReader reader = new com.aspose.barcode.barcoderecognition.BarCodeReader(img,DecodeType.ALL_SUPPORTED_TYPES);
                 // Read all types of barcode
                 for (BarCodeResult result : reader.readBarCodes()) {
                     //read code text and symbology type
                     System.out.println("CodeText: " + result.getCodeText());
                     System.out.println("Symbology type: " + result.getCodeType());

                     //get height and width
                     System.out.println(result.getRegion().getRectangle().getHeight());
                     System.out.println(result.getRegion().getRectangle().getWidth());

                     //get points coordinates.
                     java.awt.Point[] point = result.getRegion().getPoints();
                     System.out.println("Top left coordinates: X = " + point[0].x + ", Y = " + point[0].y);
                     System.out.println("Bottom left coordinates: X = " + point[1].x + ", Y = " + point[1].y);
                     System.out.println("Bottom right coordinates: X = " + point[2].x + ", Y = " + point[2].y);
                     System.out.println("Top right coordinates: X = " + point[3].x + ", Y = " + point[3].y);
                 }

Hope, this helps a bit.

Hi Amjad,

I have tried the above sample, it is not working as expected for.

I have attached the sample TIF which we receive on daily basis. The TIF has 3 barcodes in it and I need to decode the value from the middle barcode.

Could you guide me on this?

Thanks for guiding.

@dharmareddy,

Please share sample code (runnable) and TIFF file to show the issue, we will check it soon.

PS. please zip the file(s) prior attaching here.

Here is the sample code and attached the TIF (3 barcode, left, right and middle). Tell me how to decode the value from middle barcode

private static void decodePage(File file) throws Exception {
		String barcodeValue = "";
		BarCodeReader reader = new BarCodeReader(file.getAbsolutePath(), DecodeType.CODE_128);
		reader.getQualitySettings().getAllowComplexBackground();
		reader.setQualitySettings(QualitySettings.getHighQualityDetection());
		reader.getQualitySettings().setMedianSmoothingWindowSize(6);
		reader.getBarcodeSettings().setChecksumValidation(ChecksumValidation.ON);
		reader.getQualitySettings().setAllowOneDWipedBarsRestoration(true);
		reader.getBarcodeSettings().setStripFNC(true);
		reader.getBarcodeSettings().setDetectEncoding(true);
		reader.getQualitySettings().setAllowMedianSmoothing(false);
		reader.getQualitySettings().setAllowComplexBackground(true);
		reader.getQualitySettings().setAllowInvertImage(true);
		reader.getQualitySettings().setAllowDetectScanGap(true);
		reader.getQualitySettings().setAllowWhiteSpotsRemoving(true);
		reader.getQualitySettings().setAllowRegularImage(true);
		reader.getQualitySettings().setAllowSaltAndPaperFiltering(true);
		BarCodeResult [] result = reader.readBarCodes();
		System.out.println("Found BarCode : "+reader.getFoundCount());
		for (int j = 0; j < result.length; j++) {
			System.out.println(result[j].getConfidence());
			
			System.out.println(result[j].getRegion().getRectangle().getHeight());
            System.out.println(result[j].getRegion().getRectangle().getWidth());
            
            System.out.println(result[j].getRegion().getAngle());
            
            System.out.println(result[j].getRegion().getQuadrangle().getLeftBottom());
            System.out.println(result[j].getRegion().getQuadrangle().getRightBottom());
            System.out.println(result[j].getRegion().getQuadrangle().getLeftTop());
            System.out.println(result[j].getRegion().getQuadrangle().getRightTop());

            //get points coordinates.
            java.awt.Point[] point = result[j].getRegion().getPoints();
            System.out.println("Top left coordinates: X = " + point[0].x + ", Y = " + point[0].y);
            System.out.println("Bottom left coordinates: X = " + point[1].x + ", Y = " + point[1].y);
            System.out.println("Bottom right coordinates: X = " + point[2].x + ", Y = " + point[2].y);
            System.out.println("Top right coordinates: X = " + point[3].x + ", Y = " + point[3].y);
            
            Code128DataPortion[] code128DataPortions = result[j].getExtended().getCode128().getCode128DataPortions();
            for (Code128DataPortion code128DataPortion : code128DataPortions) {
            	barcodeValue = code128DataPortion.getData();
            	//System.out.println("Code128SubType : " + code128DataPortion.getCode128SubType()+" $$ Decoded Barcode Data : " + code128DataPortion.getData());
    			break;
            }
        }
		System.out.println("File....."+file.getAbsolutePath()+" Barcode Value = "+barcodeValue);
		//System.out.println("File....."+file.getAbsolutePath()+" Barcode Value = "+barcodeValue+" -- "+validBarcode(barcodeValue,file.getName()));
	}

sample.zip (21.0 KB)

@dharmareddy,

Thanks for the TIFF file.

I did evaluate using your TIF image, I got 1 barcode is read by Aspose.BarCode for Java API so it gives the region/area data for it. Does the API read only the left barcode or middle one, please confirm? The code text might not be correct, the API has an issue reading barcode from TIFF images (we already logged a ticket for it into our database). I guess unless the logged issue is sorted out to trace all the barcodes from the TIFF image, this cannot be evaluated precisely. Anyways, we will look into it and get back to you soon.

@dharmareddy,

We suggest you to try the following sample code and use PNG image type instead of TIFF format. Also, see the sample where you can specify the area for middle barcode coordinates:
e.g.
Sample code:

String fileName = "sample.png";
BufferedImage image = ImageIO.read(new File(fileName));
 Rectangle[] areas = new Rectangle[]{new Rectangle(520,30, 240, 90)};  // The coordinates of the middle barcode area
 BarCodeReader reader = new BarCodeReader(image, areas, DecodeType.ALL_SUPPORTED_TYPES);
 BarCodeResult[] result = reader.readBarCodes();
 Assert.assertTrue(result.length > 0);

Please note, some tiff files cannot be read by Java standard facilities. You could try to read this file by using some third-party tool and if you are succeeded, you may supply that BufferedImage object to constructor. Alternatively, you can use PNG image type to avoid unreadability issue while extracting barcodes. We have also planned to add a constructor to BarCodeReader which will improve the implementation of reading of the images for such cases (a ticket is logged with an id “BARCODEJAVA-1332”).