Could not read barcode document with ocr

Hi Guys,
Need assistance
I used the code below to read barcode document,i managed to read only once
and the rest of time i cannot read the barcode using aspose ocr

is there any thing i missing from the code below?


//Set image output resolution
Resolution resolution = new Resolution(100);
JpegDevice device = new JpegDevice(resolution, 100);
// Save PDF to imagestream
device.Process(doc.Pages[1], stream);

//Save imagestream to temp folder
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
img.Save("\\ZAS-CMS-Dev01\ZASCMSTest\" + caseid + “\tempID.Jpeg”, System.Drawing.Imaging.ImageFormat.Jpeg);

//Load OMR recognition template
OmrTemplate omrtemplate = OmrTemplate.Load("\\ZAS-CMS-Dev01\ZASCMSTest\idnumber.amr");

//Load the converted image to read the data from
OmrImage omrimage = OmrImage.Load("\\ZAS-CMS-Dev01\ZASCMSTest\" + caseid + “\tempID.Jpeg”);

omrimage.AutoDetectResolution = false;

//Create an OCR Engine instance
OmrEngine engine = new OmrEngine(omrtemplate);

//Initiate the recognition process and parse the results to a results object
OmrProcessingResult omrresult = engine.ExtractData(new OmrImage[] { omrimage });

//Extract the results into a hashtable
Hashtable OMRHash = omrresult.PageData[0];

//Convert the Hashtable to a collection to processing of values
ICollection key = OMRHash.Keys;


if (key.Count < 1)
{
invalididmessage = “Sorry,the uploaded document cannot have more than one barcode.”;
string fileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\tempID.Jpeg”;
if (File.Exists(fileName))
{
System.IO.File.Delete(fileName);

}
string TempfileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\New Application\TemporaryIdnumber.pdf”;
if (File.Exists(TempfileName))
{
System.IO.File.Delete(TempfileName);

}
}
else
{
//Cycle through each OCR element detected
foreach (string k in key)
{
invalididmessage = “”;

if (OMRHash[k].ToString().Length > 0 && OMRHash[k].ToString().Length < 13)
{
invalididmessage = “Sorry,the uploaded document is not a South African ID copy.”;
string fileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\tempID.Jpeg”;
if (File.Exists(fileName))
{
System.IO.File.Delete(fileName);

}
string TempfileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\New Application\TemporaryIdnumber.pdf”;
if (File.Exists(TempfileName))
{
System.IO.File.Delete(TempfileName);

}

}
else if (OMRHash[k].ToString().Length == 0)
{
invalididmessage = “Sorry,the barcode on the id copy could not be read.Please make sure you scan properly your id copy.”;
string fileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\tempID.Jpeg”;
if (File.Exists(fileName))
{
System.IO.File.Delete(fileName);

}
string TempfileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\New Application\TemporaryIdnumber.pdf”;
if (File.Exists(TempfileName))
{
System.IO.File.Delete(TempfileName);

}

}
else if (String.IsNullOrEmpty(OMRHash[k].ToString()))
{

invalididmessage = “Please upload a readable id copy ,the scan document must be of good resolution.”;
string fileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\tempID.Jpeg”;
if (File.Exists(fileName))
{
System.IO.File.Delete(fileName);

}
string TempfileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\New Application\TemporaryIdnumber.pdf”;
if (File.Exists(TempfileName))
{
System.IO.File.Delete(TempfileName);

}

}
else
{

var id_num = dataContext.CMS_Consumer_Details.Where(n => n.Case_Unique_RefNo == caseid).FirstOrDefault();

if (id_num != null)
{
if (id_num.Consumer_IDNo != OMRHash[k].ToString() || id_num.Second_Consumer_IDNo != OMRHash[k].ToString())
{
invalididmessage = “Sorry,the I.D. number " + OMRHash[k].ToString() + " on the uploaded document does not match consumer(s) I.D. number in our record.”;
//delete the jpeg file

string fileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\tempID.Jpeg”;
if (File.Exists(fileName))
{
System.IO.File.Delete(fileName);

}
string TempfileName = “\\ZAS-CMS-Dev01\ZASCMSTest\” + caseid + “\New Application\TemporaryIdnumber.pdf”;
if (File.Exists(TempfileName))
{
System.IO.File.Delete(TempfileName);

}
}

}


}

}


Regards,

Steve

Hi Steve,

Thank you for your inquiry and sharing code.

This is to update you that we need the sample input files to evaluate the issue. Please forward us the sample input files, we will look into it and update you about our findings.

Hi ikram,
i have sent the files to your personal email

Regards,

Steve

Hi Steve,

Thank you for sharing samples. We have received your email. We will now investigate the issue and update you very soon about our findings.

Hi Steve,

This is to update you that we have investigated the issue at our end. It was found that the images retrieved from PDF files are not in the proper format. The images are tiled and rotated on different angles. Due to which Aspose.OMR is unable to recognize barcodes on the images. We are able to process a barcode after correcting the rotated angle of the image retrieved from PDF file. Screen shot is attached for your reference.

Hi Ikram,
Thanks for your quick response.
Would you please advice in my code above where to includes codes for correcting the rotation and which format should used ?


Regards,

Steve

Hi Steve,

Thank you for writing us back.

As shared in my last post that images retrieved from PDF files were not in the proper format. The images were tiled and rotated on different angles. Due to which Aspose OMR API was unable to recognize the barcode on the images. Aspose OMR APIs works with predefined template, means every time the scanned OMR sheet image should be exactly the same way as was used while developing the OMR template.

To recognize barcode in your scenario, Aspose.BarCode API will help you. Please go through the details on how Aspose.BarCode works.

Hope the above information helps. Feel free to contact us in case of any query or comments.