Re: Incorrect read angle reported

Hi there,


I am experiencing the same problem with version 6.0.0.0 (.NET). The barcodes are being read correctly, but getAngle() reports 0 where it should be 180. Every now and then it does report 180.

Using the same documents over and over again, I get the same results. Any advice?
Thanks!

So, when I was generating the barcode I was generating it as a PNG image. Changed that to BMP and it appears to work now 100%.


Hope that helps anyone with similar issues :slight_smile:
Hi Edgar,

Thank you for contacting support.
edgarecayce:
I am experiencing the same problem with version 6.0.0.0 (.NET). The barcodes are being read correctly, but getAngle() reports 0 where it should be 180. Every now and then it does report 180.
Please share sample barcode images, or source code. It will help us to reproduce the problem on our side. We'll take a closer look and guide you accordingly.

Below is
  1. code that generates barcode
  2. code that reads barcode

Keep in mind, I can recognize and read barcode text fine, only thing I can't do consistently is to determine whether the barcode has been rotated 180 degrees.

1.
// Instantiate barcode object
BarCodeBuilder barcode = new BarCodeBuilder();

//set barcode image size
barcode.AutoSize = false;
barcode.ImageHeight = 5;
barcode.ImageWidth = 100;

//Set the Code text for the barcode
barcode.CodeText = patientCaseId + "-" + patientId + "-" + formSerial.ToString() + "-" + currPage;
//Set the symbology type to Code39Standard
barcode.SymbologyType = Symbology.Code39Standard;
barcode.xDimension = 0.3f;

MemoryStream barcodeStream = new MemoryStream();

//barcode.Save(barcodeStream, BarCodeImageFormat.Bmp);
barcode.Save(barcodeStream, ImageFormat.Bmp);
byte[] barcodeBuffer = barcodeStream.GetBuffer();

builder.InsertImage(barcodeBuffer);
builder.Writeln();


2.)
using (var ms = new MemoryStream())
{
BarCodeReader reader;
uploadedFile.InputStream.CopyTo(ms);

//check if file is pdf
if (uploadedFile.ContentType == "application/pdf")
{
// create PDF document to obtain single pages
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(uploadedFile.FileName);
// for each single PDF page, obtain barcode and other information
for (var i = 1; i <= pdfDocument.Pages.Count; i++)
{
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(ms);
//flag to determine if page needs to be rotated 180 degrees
needToRotate180 = false;

// set page range for image extraction
pdfExtractor.StartPage = i;
pdfExtractor.EndPage = i;

// extract the images
pdfExtractor.ExtractImage();

// save image to stream
MemoryStream imageStream = new MemoryStream();
bool imageResult = pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;

//check if there was an image
if (imageResult)
reader = new BarCodeReader(imageStream, BarCodeReadType.Code39Standard);
string code = "";
while (imageResult && reader.Read())
{
float pageAngle = reader.GetAngle();
code = reader.GetCodeText();
if (pageAngle == 180.0)
{
needToRotate180 = true;
}
}
reader.Close();
.......

Hi,


Quick update, I have been playing around with the barcode settings and it appears, because I had set the barcode.AutoSize to false, at times the angle could not be detected, even though the reader was able to recognize the barcode CodeText. Setting the AutoSize to true so far seems to have fixed the issue, however I do want to reduce the height of the barcode if possible, while not foregoing the ability to use the getAngle() function properly. Any suggestions?

Thanks!

Hi Edgar,


Thank you for sharing this information. We’re working over your query and will get back to you soon.

Hi Edgar,


Thank you for being patient. Based on your sample code, you are generating a bar code without rotating it and then expecting a rotated bar code from a PDF file. Please share a sample code where you are adding a bar code image to a PDF file. It’ll be so nice of you if you can also share a problematic PDF file. It’ll help us to be more specific.

Secondly, please note that the bar code size depends upon the code text as well. You can adjust a specific bar code size by following the sample code here: http://www.aspose.com/docs/display/barcodenet/Generate+Barcode+Using+Custom+Width+Support

The GetOnlyBarCodeImage method will return you the minimum possible size and then you can use the GetCustomSizeBarCodeImage method to adjust its size. Please don’t truncate its original width or height otherwise you could face recognition failure problems.

I hope, It helps. Please do let me know in case of any confusion or questions.

"Based on your sample code, you are generating a bar code without rotating it and then expecting a rotated bar code from a PDF file."


Yes, that is correct. I want to be able to anticipate the scenario where a document with a barcode is printed and then scanned in upside down (rotated 180 degrees).


"The GetOnlyBarCodeImage method will return you the minimum possible size and then you can use the GetCustomSizeBarCodeImage method to adjust its size. Please don’t truncate its original width or height otherwise you could face recognition failure problems."

Sweet, I will try that out!
Thanks.

Hi Edgar,


Thank you for sharing the details. Normally, the read method auto detects the orientation of the barcode e.g. it’s quite possible to recognize a bar code having 90 degrees without setting orientation. In short, if the barcode is actually not rotated (0 degree) and you are scanning it at 180 degrees and it returns a correct code text along with 0 degree angle then it is a correct behavior.

Anyway, we recommend our customers use the realistic settings as its impact on the performance and quality. You can share the problematic files in the forum thread.

I hope, this helps.

Thanks for your response. However I am not sure I understand.


Say you have a barcode image inserted into a document without any rotation, you print the document and then scan it back, rotated at 180 degrees (upside down), you would see everything upside down when viewing it in PDF Viewer. Why wouldn’t getAngle() return 180?

Maybe I don’t exactly understand how barcodes work, but I presume you need to read them from left to right? If you have a barcode with 0 rotation, your print the page and then you rotate the page to be scanned 180, I think the angle for the barcode should also return 180, because now the barcode’s beginning would be on the right. Anything else doesn’t make sense to me.

Hi Edgar,

Thank you for these details.
edgarecayce:
Say you have a barcode image inserted into a document without any rotation, you print the document and then scan it back, rotated at 180 degrees (upside down), you would see everything upside down when viewing it in PDF Viewer. Why wouldn’t getAngle() return 180?
Well, you have inserted a barcode image in a PDF file at a zero degree angle. But during the print and scan process, it is now rotated because as you scanned back the PDF document at 180 degrees. In that case, it should return angle 180 degrees. Please correct me if I misunderstood anything.
It will be so nice of you if you can please share such problematic PDF document in this forum thread. We’ll take a closer look and guide you accordingly.