Hello I've created a sample set of images that have loyalty cards on them, I've used the Line Item Lookup API to create a CommodityTrainer...How do I integrate this commodity trainer into my project? I am creating a project that uses the Receipt Capture SDK to extract data from receipts, id like to integrate the CommodityTrainer to find loyalty cards from a specific vendor.

asked 24 Aug '16, 17:07

persaudJon's gravatar image



I hope it will help:

// Part 1 - Sample code to create the Commodity Trainer (that you have already done in your project):
String folderName = "CommodityTrainer";
String pathToData = outputPath + folderName + "\\";
// Create folder for Commodity Trainer data:
if( !Directory.Exists( pathToData ) ) Directory.CreateDirectory( pathToData );
// set RC_Usa country
int country = 1; 
// Create trainer:
ReceiptCapture.ICommodityTrainer commodityTrainer = _engine.OpenCommodityTrainer( pathToData, country );
// Create info for trainer
ReceiptCapture.ICommodityInfo commodityInfo = commodityTrainer.CreateCommodityInfo( "Cheaps", "SkuPringles", "coupon" );
// Add image which is corresponded to added commodity info:
commodityTrainer.AddImageFile( commodityInfo, filePath );
// Create etalon with new data (save new added file and info)
commodityTrainer.CreateEtalon( pathToData );

// Part 2 - Sample code to use the Commodity Trainer:
String pathToEtalon = pathToData;
// Open commodity etalon
ReceiptCapture.ICommodityEtalon commodityEtalon = _engine.OpenCommodityEtalon( pathToEtalon );
ReceiptCapture.ReceiptSynthesisParams receiptSynthesisParams = _engine.CreateReceiptSynthesisParams();
// Set commodity etalon in processing parameters
receiptSynthesisParams.SetCommodityEtalon( commodityEtalon );

String imageFilePath = filePath ;
 // Add image to document
receiptRecognizer.AddImageFile( filePath, null );
// Process
receiptRecognizer.Process( receiptSynthesisParams );
// See classified line items results:
ReceiptCapture.IReceiptClassifiedLineItems receiptClassifiedLineItems = receiptRecognizer.Receipts[0].ReceiptClassifiedLineItems;
int classifiedReceiptsCount = receiptClassifiedLineItems.Count;
for( int i = 0; i < classifiedReceiptsCount; ++i ) {
    ReceiptCapture.IReceiptClassifiedLineItem receiptClassifiedLineItem = receiptClassifiedLineItems.Item( i );
    WriteLineToLog( "  Sku  = " + receiptClassifiedLineItem.Sku );
    WriteLineToLog( "  Coupon name  = " + receiptClassifiedLineItem.CouponName );


answered 25 Aug '16, 16:03

Natalia%20Karaseva's gravatar image

Natalia Kara...

Where would I place this code if i am trying to incorporate this into my project when I am using the Receipt Capture SDK?

(09 Sep '16, 18:13) persaudJon

Hi! I try to answer.

The code from the Part 1 should be called once, only when you train your pattern. So it doesn't matter where you will place it. You could create new project in order to train the pattern. Or you could create separate function in your main project.

The code from the Part 2 should be integrated inside your main Receipt Capture SDK project. Еvery time, when the receipt is coming for recognition, you call the IReceiptRecognizer.Process( receiptSynthesisParams ) method. So you should pass receiptSynthesisParams with previosly set commodityEtalon ( via receiptSynthesisParams.SetCommodityEtalon( commodityEtalon ) ) and the recognition will occur with help of commodity etalon.

I'm not sure whether I clarified this question. However, if you still have questions about CommodityTrainer, please ask again with more details about your project and this issue.


answered 13 Sep '16, 14:20

Natalia%20Karaseva's gravatar image

Natalia Kara...

Thank you that helped, would you say that the more training images that you use to create the Commodity Trainer also will increase the recognition, accuracy & confidence levels of results? if so what is the recommended amount?

(14 Sep '16, 21:55) persaudJon

The OCR accuracy depends not only on amount of receipts but also on the quality of the receipts. It is necessary to use the receipts of the same quality both for training and for testing. And it's also important to check that there is no garbage in recognition results of trained receipts.

If you intend to extract 1 or 2 coupons the several receipts should be enough for creating pattern (as it is shown in the Line Item Lookup API Demo Sample). Too much receipts in CommodityEtalon could result into slow processing. However, as for me, the best way to achieve high OCR accuracy is to make an exploratory testing with different quantity of available receipts.

Hope, it will be helpful.


answered 18 Sep '16, 19:57

Natalia%20Karaseva's gravatar image

Natalia Kara...

edited 18 Sep '16, 19:58

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 24 Aug '16, 17:07

Seen: 397 times

Last updated: 18 Sep '16, 19:58

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal