Business Card traverse snippet

Question

How to work with the data of recognized Business Cards?

Answer

Working with IBusinessCard Object is quite similar to working with an IFRPage object. The following code snippet should contain all the required data extraction operations:

//retrieve BusinessCards recognized on the page
CSafePtr<IBusinessCards> BCards;
CheckResult(frDocument->get_BusinessCards(&BCards));

int BCardCount = 0;
CheckResult(BCards->get_Count(&BCardCount));

//go through of all the BusinessCard objects
for (int currBCard = 0; currBCard < BCardCount; currBCard++)
{			
		//unnecessary part, if you would like to print the results into a text file
		std::wfstream fs;
		CBstr OutputFile = resultsPath + L"OutputFile" + L".txt";
		fs.open(OutputFile.Ptr(), std::fstream::in | std::fstream::out | std::fstream::app);

		//setting up appropriate locate is important especially for CJK languages
		//fs.imbue(std::locale("ko"));
		fs.imbue(std::locale("Chinese_China.936"));

		fs << imageFileName << std::endl;			

	CSafePtr<IBusinessCard> BCard;
	CheckResult(BCards->get_Element(currBCard, &BCard));
			
	int BCardFieldCount = 0;
	CheckResult(BCard->get_FieldsCount(&BCardFieldCount));

	for (int currBCardField = 0; currBCardField < BCardFieldCount; currBCardField++)
	{
		CSafePtr<IBusinessCard> BCard;
		CheckResult(BCard->get_Field(currBCardField, &BCardField));

		//below are examples of getting filed type, value and CharParams etc.
		BSTR FieldValue = L"";
		CheckResult(BCardField->get_Value(&FieldValue));

		BusinessCardFieldTypeEnum FieldType;
		CheckResult(BCardField->get_Type(&FieldType));

		int FieldConfidence = 0;
		CheckResult(BCardField->get_Confidence(&FieldConfidence));

		CSafePtr<ICharParams> CharParams;
		CheckResult(BCardField->GetCharParams(0, &CharParams));

		int Right;
		CheckResult(CharParams->get_Right(&Right));
		//...

		switch (FieldType)
		{
			case BusinessCardFieldTypeEnum::BCFT_Name:
				fs << L"\tName: " << FieldValue << std::endl;
				break;

			case BusinessCardFieldTypeEnum::BCFT_Company:
				fs << L"\tCompany name: " << FieldValue << std::endl;

			default:
				break;
		}
	}
	
	//close the output stream, if you decided to print the results into a text file
	fs.close();

	//export the business card if required
	CheckResult(BCard->ExportToVCard(resultsPath + imageFileName + L".vcf"));
}

C++ code snippet

 

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.

Recently viewed