
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//																				   //
//		Filename:		VPARESP.h												   //
//																				   //
//		Description:	VPAR (ESP) v.3.0										   //
//																				   //
//						Vehicle Plate Automatic Reader (Spain)					   //
//																				   //
//		Date:			September - 2008							  		       //
//																				   //
//		Developed by:	NEURAL LABS S.L.										   //
//																				   //
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////
// Definitions.
/////////////////////////////////////////////////////////////////////////////////////
#ifdef VPARESP_EXPORTS
#define VPARESP_API __declspec(dllexport)
#else
#define VPARESP_API __declspec(dllimport)
#endif

#define FUNCTION_MOD WINAPI




/////////////////////////////////////////////////////////////////////////////////////
// vparespInit
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Initalizes the Vehicle Plates Automatic Reader. Allocates Memory,  
//				loads the Artificial Neural Networks, etc...
//
//	Parameters:	
//
//			lAvCharacterHeight:	Aproximate average height of the characteres within
//								the images (in pixels). -1 ==> Automatic.
//	
//			bDuplicateLines:	This parameter must be true	when the imaging hardware 
//								only acquires half of the horizontal lines. 
//
//			bSort2LinesPLates:	This parameter must be true in order to sort the plates 
//								with two lines according to the spanish format.
//
//			bTrailersOn:		This parameter must be true in order to recognize two plates
//								within the images (tractor's & trailer's plates).
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API 
long FUNCTION_MOD vparespInit(long lAvCharacterHeight = -1, 
							  bool bDuplicateLines = false, 
							  bool bSort2LinesPLates = true, 
							  bool bTrailersOn = false);




/////////////////////////////////////////////////////////////////////////////////////
// vparespEnd
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Frees memory and closes the VPAR.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API void FUNCTION_MOD vparespEnd(void);



/////////////////////////////////////////////////////////////////////////////////////
// vparespSetCorrectionCoefficients
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Sets the distortion correction coefficients that will be applied 
//				to all the images before being analyzed.
//
//	Parameters:	
//
//			fDistance:			Approximate Distance between camera and object (in meters).
//
//			fVerticalCoeff:		Coefficient for correcting Vertical Perspective).
//
//			fHorizontalCoeff:	Coefficient for correcting Horizontal Perspective).
//
//			fAngle:				Angle for correcting Rotation.
//			 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API void FUNCTION_MOD  vparespSetCorrectionCoefficients(float fDistance, 
																		   float fVerticalCoeff, 
																		   float fHorizontalCoeff, 
																		   float fAngle);



/////////////////////////////////////////////////////////////////////////////////////
// vparespSetDistortionCorrectionOff
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Deactivates the distortion correction pre-process.
//				Use vparespSetCorrectionCoefficients to activate it again.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API void FUNCTION_MOD  vparespSetDistortionCorrectionOff();



/////////////////////////////////////////////////////////////////////////////////////
// vparespConfigureAutomaticCharacterHeight
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Configures the Automatic Character Height steps.
//				When vparespInit is called with the argument lAvCharacterHeight set to -1 
//				the automatic character height mode is selected. By default, the range of 
//				character heights scanned in this mode is from 25 pixels to 60 pixels.
//				By using this function, the user can select the heights that VPAR will scan, 
//				as well as the order in which they will be scanned.
//
//	Parameters:	
//
//			lNumSteps:	Number of steps that VPAR will perform in automatic height mode (maximum 10 steps).
//
//			plSteps: Array with the heights that VPAR will scan. It must contain lNumSteps elements.
//
//  Remarks:
//
//			To recover the default configuration, the following code must be executed:
//				  long lSteps[8] = { 25, 30, 35, 40, 45, 50, 55, 60 };
//				  vparespConfigureAutomaticCharacterHeight(8, lSteps);
//			 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD  vparespConfigureAutomaticCharacterHeight(long lNumSteps, long* plSteps);



/////////////////////////////////////////////////////////////////////////////////////
// vparespRead
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image, finds the vehicle plate and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageData: Buffer with the image pixels (greylevel, 8 bits/pixel).
//			 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespRead(long lWidth, long lHeight, unsigned char* pbImageData);




/////////////////////////////////////////////////////////////////////////////////////
// vparespReadBMP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a BMP file, finds the vehicle plate and recognizes 
//				the characters.
//
//	Parameters:	
//
//			pcFilename:	Filename of a standard BMP file (24 bits/pixel).
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespReadBMP(char* pcFilename);



/////////////////////////////////////////////////////////////////////////////////////
// vparespReadJPG
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a JPG file, finds the vehicle plate and recognizes 
//				the characters.
//
//	Parameters:	
//
//			pcFilename:	Filename of a standard JPG file.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespReadJPG(char* pcFilename);




/////////////////////////////////////////////////////////////////////////////////////
// vparespReadRGB24
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a 24 bits RGB buffer, finds the vehicle plate and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageDataRGB: Buffer with the image pixels (RGB, 24 bits / pixel).
//
//			bFlip: true to perform a Vertical Flip of the image buffer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespReadRGB24(long lWidth, long lHeight, unsigned char* pbImageDataRGB, bool bFlip = false);




/////////////////////////////////////////////////////////////////////////////////////
// vparespReadRGB32
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a 32 bits RGB buffer, finds the vehicle plate and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageDataRGB: Buffer with the image pixels (RGB, 32 bits / pixel).
//
//			bFlip: true to perform a Vertical Flip of the image buffer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespReadRGB32(long lWidth, long lHeight, unsigned char* pbImageDataRGB, bool bFlip = false);



/////////////////////////////////////////////////////////////////////////////////////
// vparespGetNumberOfPlates
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Returns the number of registration plates found.
// 
//	Return Value:	Number of Plates.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespGetNumberOfPlates();



/////////////////////////////////////////////////////////////////////////////////////
// vparespGetText
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the registration number read.
// 
//	Parameters: 
//
//			strResult:	Text string with the result.
//
//			lPlate:		If there is more than one plate found, this is the plate index 
//						(0 for the first one). 
//
//	Return Value:		OK    --> true
//						ERROR --> false 
//  
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API bool FUNCTION_MOD vparespGetText(char * strResult, long lPlate = 0);




/////////////////////////////////////////////////////////////////////////////////////
// vparespGetNumberOfCharacters
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the number of characters in the last plate analyzed.
//  
//	Parameters: 
//
//			lPlate: If there is more than one plate found, this is the plate index 
//					(0 for the first one). 
//
//	Return Value:	Number of Characters.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespGetNumberOfCharacters(long lPlate = 0);




/////////////////////////////////////////////////////////////////////////////////////
// vparespGetGlobalConfidence
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the confidence factor (0 - 100%) for the last plate analyzed.
//
//	Parameters: 
//
//			lPlate: If there is more than one plate found, this is the plate index 
//					(0 for the first one). 
// 
//	Return Value:	Overall Confidence Factor.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API  float FUNCTION_MOD vparespGetGlobalConfidence(long lPlate = 0);




/////////////////////////////////////////////////////////////////////////////////////
// vparespGetCharacterConfidence
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the confidence factor (0 - 100%) for a specific character.
//
//	Parameters:	
//
//			lIndex:	Index of the character [0 .. NumberOfCharacters-1]
//
//			lPlate: If there is more than one plate found, this is the plate index 
//					(0 for the first one). 
// 
//	Return Value:	Character Confidence Factor.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API float FUNCTION_MOD vparespGetCharacterConfidence(long lIndex, long lPlate = 0);




/////////////////////////////////////////////////////////////////////////////////////
// vparespGetAverageCharacterHeight
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the average height in pixels of the characters recognized in the last plate analyzed.
// 
//	Parameters: 
//
//			lPlate: If there is more than one plate found, this is the plate index 
//					(0 for the first one). 
// 
//	Return Value:	Average Character Height.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API  float FUNCTION_MOD vparespGetAverageCharacterHeight(long lPlate = 0);




/////////////////////////////////////////////////////////////////////////////////////
// vparespGetRectangle
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the coordinates of the rectangle containing the last plate analyzed.
//
//	Parameters:	
//
//			plLeft:		The LEFT coordinate (or X1) is returned here.
//
//			plTop:		The TOP coordinate (or Y1) is returned here.
//
//			plRight:	The RIGHT coordinate (or X2) is returned here.
//
//			plBottom:	The TOP coordinate (or Y2) is returned here.
//
//			lPlate:		If there is more than one plate found, this is the plate index 
//						(0 for the first one). 
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API void FUNCTION_MOD vparespGetRectangle(long* plLeft, long* plTop, long* plRight, long* plBottom, long lPlate = 0);



/////////////////////////////////////////////////////////////////////////////////////
// vparespGetProcessingTime
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Returns the time taken to process the last image.
//
//	Return Value:	Process time in milliseconds.
//
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespGetProcessingTime();



/////////////////////////////////////////////////////////////////////////////////////
// vparespSetTimeOut
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Sets a maximum processing time for the "Read" functions. 
//					If the process has not finished after the specified timeout, 
//					the "Read" functions will time-out and quit.
//
//	Parameters:
//
//			lMilliseconds:	Maximum processing time in milliseconds.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API void FUNCTION_MOD vparespSetTimeOut(long lMilliseconds);




/////////////////////////////////////////////////////////////////////////////////////
// vparespWriteHASP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Escribe datos en la memoria interna de la mochila de 
//					protección (dongle). Esta capacidad de almacenar datos en 
//					el HASP puede ser usada por el usuario para cualquier propósito. 
//					Los datos son encriptados automáticamente antes de escribirse 
//					en la memoria del HASP.
//					Pueden almacenarse un máximo de 24 bytes.
//
//	Parameters:
//
//			pData:	Buffer con los datos a escribir en la memoria del HASP.		
//
//			lSize:	Tamaño (en bytes) de los datos a escribir (máximo 24).
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespWriteHASP(BYTE* pData, long lSize);



/////////////////////////////////////////////////////////////////////////////////////
// vparespReadHASP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Lee los datos almacenados en la memoria interna de la mochila 
//					de protección (dongle). Esta capacidad de almacenar datos 
//					en el HASP puede ser usada por el usuario para cualquier 
//					propósito. Los datos son desencriptados automáticamente después 
//					de leerse de la memoria del HASP.
//
//	Parameters:
//
//			pData:		Buffer donde se almacenarán los datos leídos de la memoria 
//						del HASP.
//
//			lSize:		Tamaño (en bytes) de los datos a leer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" VPARESP_API long FUNCTION_MOD vparespReadHASP(BYTE* pData, long lSize);



