ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Barcode demo in C++?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

nachbar

USA
17 Posts

Posted - Jan 19 2014 :  17:58:38  Show Profile  Reply
I am trying to get the IEVision barcode recognition to work in C++. Actually, the recognition succeeds and returns the correct number of barcodes found, but there is no way to get the info about each barcode!

From the Delphi IEVision Barcode demo, you declare:
var
s: TIEVisionBarCodeSymbol;

and then get that object:
s := TIEVisionBarCodeSymbol( m_symbols.getObj(i) );

However, the C++ compiler will not allow you to declare a TIEVisionBarCodeSymbol, claiming (correctly), that it is an abstract class. Indeed, in ievision.hpp, the entire definition is:
__interface TIEVisionBarCodeSymbol;
typedef System::DelphiInterface<TIEVisionBarCodeSymbol> _di_TIEVisionBarCodeSymbol;
__interface TIEVisionBarCodeSymbol : public TIEVisionBase
{

public:
virtual HRESULT __safecall getSymbolType(BOOL wantExceptions, _di_TIEVisionWString &__getSymbolType_result) = 0 ;
virtual HRESULT __safecall getData(BOOL wantExceptions, _di_TIEVisionWString &__getData_result) = 0 ;
virtual HRESULT __safecall getBoundingBox(BOOL wantExceptions, TIEVisionRect &__getBoundingBox_result) = 0 ;
virtual HRESULT __safecall getXML(BOOL wantExceptions, _di_TIEVisionWString &__getXML_result) = 0 ;
};

Thus, clearly, these pure virtual functions indicate that a TIEVisionBarCodeSymbol object cannot be created. The _di_TIEVisionBarCodeSymbol interface, can, of course, be created, but any attempt to assign the _di_TIEVisionBase that is returned from getObj() produces a compile error that "No GUID associated with type TIEVisionBarCodeSymbol".

Thus, I cannot get the info about the individual identified barcodes, including their content.

Can you tell me how to get the Barcode info (from TIEVisionBarCodeSymbol) in C++?

Thank you.


James Nachbar

nachbar

USA
17 Posts

Posted - Jan 31 2014 :  22:56:38  Show Profile  Reply
Is there a C++ demo that shows how to access the barcode info from C++?

James Nachbar
Go to Top of Page

xequte

38608 Posts

Posted - Feb 21 2014 :  23:51:02  Show Profile  Reply
Hi James

We'll need to look into this and come back to you.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

fab

1310 Posts

Posted - Mar 06 2014 :  09:42:50  Show Profile  Reply
Sorry for the delay. A full C++ demo will be available from next release.

The syntax is not as simple as in Delphi:



//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ievect"
#pragma link "ieview"
#pragma link "imageenview"
#pragma resource "*.dfm"
TMainForm *MainForm;


String FindIEVisionDLLPath()
{
  // DEMO CODE ONLY
  // The IEVision.DLL may not be located in the EXE folder, so check other common locations

  String sExePath = IncludeTrailingBackslash(ExtractFilePath(Application->ExeName));

  // In same folder as EXE?
  String Result = sExePath + IEVISION_32BIT_DLL_FILENAME1;
  if (FileExists(Result))
	return Result;

  // In Registered version folder?
  Result = sExePath + "..\\..\\..\\Registered\\" + IEVISION_32BIT_DLL_FILENAME1;
  if (FileExists(Result))
	return Result;

  // In trial version folder?
  Result = sExePath + "..\\..\\..\\Trial\\" + IEVISION_32BIT_DLL_FILENAME1;
  if (FileExists(Result))
	return Result;

  // In parent folder of EXE?
  Result = sExePath + "..\\" + IEVISION_32BIT_DLL_FILENAME1;
  if (FileExists(Result))
	return Result;

  // Or its parent?
  Result = sExePath + "..\\..\\" + IEVISION_32BIT_DLL_FILENAME1;
  if (FileExists(Result))
	return Result;

  return ""; // Not found, try system path
}



//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
	: TForm(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  // Calling IEInitialize_ievision is NOT required if the IEVision DLL is located in the same folder as the EXE or on the system path
  // You need only call IEVisionAvailable which will automatically call IEInitialize_ievision
  String sDLLPath = FindIEVisionDLLPath();
  if (sDLLPath != "")
	IEInitialize_ievision(sDLLPath, false); // Initialize DLL in custom location

  if (!IEVisionAvailable()) {
	ShowMessage("This application requires the ievision.dll plugin. Please download it from www.imageen.com");
	Application->Terminate();
  }
}

//---------------------------------------------------------------------------
// Open
void __fastcall TMainForm::ButtonOpenClick(TObject *Sender)
{
  String filename = ImageEnVect1->IO->ExecuteOpenDialog();
  if (filename != "")
	LoadImage(filename);
}

//---------------------------------------------------------------------------
// Load a barcode image
void TMainForm::LoadImage(const String sFilename)
{
  // load file
  ImageEnVect1->RemoveAllObjects();
  ImageEnVect1->DeSelect();
  ImageEnVect1->IO->LoadFromFile(sFilename);

  ImageEnVect1->Fit();
  TrackBar1->Position = int(ImageEnVect1->Zoom);
}

//---------------------------------------------------------------------------
// Zoom
void __fastcall TMainForm::TrackBar1Change(TObject *Sender)
{
  ImageEnVect1->Zoom = TrackBar1->Position;
}

//---------------------------------------------------------------------------
// Detect
void __fastcall TMainForm::ButtonDetectClick(TObject *Sender)
{
  try {
	TreeViewResults->Items->Clear();
	ImageEnVect1->SelectionBase = iesbBitmap;

	TIEVisionRect selRect = IEVisionRect(0, 0, 0, 0);
	if (ImageEnVect1->Selected)
	  selRect = IEVisionRect(ImageEnVect1->SelX1,
							 ImageEnVect1->SelY1,
							 ImageEnVect1->SelX2 - ImageEnVect1->SelX1 + 1,
							 ImageEnVect1->SelY2 - ImageEnVect1->SelY1 + 1);

	// create bar code scanner object
	_di_TIEVisionBarCodeScanner barCodeScanner;
	IEVisionLib()->createBarCodeScanner(false, barCodeScanner);

	// run bar code scanner
	barCodeScanner->scan(ImageEnVect1->IEBitmap->GetIEVisionImage(), selRect, false, m_symbols);

	// get number of found symbols
	int symbolsCount;
	m_symbols->size(true, symbolsCount);

	// iterate among found symbols
	for (int i = 0; i < symbolsCount; i++) {

	  // get "i" symbol (as generic TIEVisionBase interface)
	  _di_TIEVisionBase bs;
	  m_symbols->getObj(i, false, bs);

	  // cast symbol to TIEVisionBarCodeSymbol interface
	  _di_TIEVisionBarCodeSymbol s = static_cast<TIEVisionBarCodeSymbol*>(&*bs);

	  // create a new tree child node using the symbol index
	  TTreeNode* n = TreeViewResults->Items->AddChild(NULL, IntToStr(i));

	  // get symbol type as IEVision string
	  _di_TIEVisionWString st;
	  s->getSymbolType(false, st);

	  // convert IEVision string to C string
	  WideChar* wch;
	  st->c_str(false, wch);

	  // create a new tree child node using the symbol type C string
	  TreeViewResults->Items->AddChild(n, wch);

	  // get symbol data as IEVision string
	  _di_TIEVisionWString dt;
	  s->getData(false, dt);

	  // convert IEVision string to C string
	  dt->c_str(false, wch);

	  // create a new tree child node using the symbol data C string
	  TreeViewResults->Items->AddChild(n, wch);
	}
	TreeViewResults->FullExpand();
  }
  catch(const Exception& e) {
	if (dynamic_cast<EAccessViolation const*>(&e))
	  ShowMessage("An error was encountered processing this image. Ensure you are using the latest version of the IEVision plug-in.");
	else
	  ShowMessage("An error was encountered processing this image: " + e.Message);
  }
}


//---------------------------------------------------------------------------

void __fastcall TMainForm::TreeViewResultsChange(TObject *Sender, TTreeNode *Node)
{
  while (Node->Parent)
	Node = Node->Parent;

  ImageEnVect1->RemoveAllObjects();

  // get symbol for the selected tree node (convert tree node text to int, representing the symbol index)
  _di_TIEVisionBase obj;
  m_symbols->getObj(StrToInt(Node->Text), false, obj);

  // convert TIEVisionBase interface to TIEVisionBarCodeSymbol interface (to use getBoundingBox method)
  _di_TIEVisionBarCodeSymbol sym = static_cast<TIEVisionBarCodeSymbol*>(&*obj);

  // get IEVision rectangle for the symbol
  TIEVisionRect rect;
  sym->getBoundingBox(false, rect);

  // create a TImageEnVect box which highlight the symbol bounding box
  ImageEnVect1->ObjKind[-1]         = iekBOX;
  ImageEnVect1->ObjLeft[-1]         = rect.x;
  ImageEnVect1->ObjTop[-1]          = rect.y;
  ImageEnVect1->ObjWidth[-1]        = rect.width;
  ImageEnVect1->ObjHeight[-1]       = rect.height;
  ImageEnVect1->ObjBoxHighlight[-1] = true;
  ImageEnVect1->ObjBrushColor[-1]   = clYellow;
  ImageEnVect1->AddNewObject();
}
//---------------------------------------------------------------------------

Go to Top of Page

xequte

38608 Posts

Posted - Mar 12 2014 :  16:20:27  Show Profile  Reply
Hi

Email me if you need it sooner.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

nachbar

USA
17 Posts

Posted - Apr 01 2014 :  09:39:05  Show Profile  Reply
Thanks! For now, I am using a workaround, creating a small Delphi unit to do the recognition and return the result to C++.

Thanks for working on this!

James Nachbar
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: