#include <mil.h>
#define IMAGE_FILE_DEFINITION M_IMAGE_PATH MIL_TEXT("QcPlates.mim")
#define IMAGE_FILE_TO_READ M_IMAGE_PATH MIL_TEXT("LicPlate.mim")
#define TEXT_DEFINITION "AVS300CVK781JNK278 EBX380QKN918HCC839 "\
"YRH900ZQR756977AMQ GPK742389EYE569ESQ"
#define NORMALIZATION_SIZE_Y 20L
#define STRING_MAX_SIZE 32L
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
MilOverlayImage,
MilStrContext,
MilStrResult;
MIL_INT NumberOfStringRead;
MIL_DOUBLE Score;
MIL_TEXT_CHAR StringResult[STRING_MAX_SIZE+1];
MIL_DOUBLE Time = 0.0;
MosPrintf(MIL_TEXT("\nSTRING READER MODULE:\n"));
MosPrintf(MIL_TEXT("---------------------\n\n"));
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(IMAGE_FILE_DEFINITION, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MstrAlloc( MilSystem, M_FONT_BASED, M_DEFAULT, &MilStrContext);
MstrAllocResult(MilSystem, M_DEFAULT, &MilStrResult);
MstrControl(MilStrContext, M_CONTEXT, M_FONT_ADD, M_USER_DEFINED);
MstrEditFont(MilStrContext, M_FONT_INDEX(0), M_CHAR_ADD,
M_USER_DEFINED + M_FOREGROUND_BLACK,
MilImage, (void *)TEXT_DEFINITION, M_NULL);
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MstrDraw(M_DEFAULT, MilStrContext, MilOverlayImage, M_DRAW_CHAR,
M_FONT_INDEX(0), M_NULL, M_ORIGINAL);
MstrEditFont(MilStrContext, M_FONT_INDEX(0), M_CHAR_NORMALIZE,
M_SIZE_Y, NORMALIZATION_SIZE_Y, M_NULL, M_NULL);
MstrControl(MilStrContext, M_CONTEXT, M_STRING_ADD, M_USER_DEFINED);
MstrControl(MilStrContext, M_CONTEXT, M_STRING_ADD, M_USER_DEFINED);
MstrControl(MilStrContext, M_CONTEXT, M_STRING_NUMBER, 1);
MstrControl(MilStrContext, M_STRING_INDEX(M_ALL), M_STRING_SIZE_MIN, 6);
MstrControl(MilStrContext, M_STRING_INDEX(M_ALL), M_STRING_SIZE_MAX, 6);
MstrSetConstraint(MilStrContext, M_STRING_INDEX(0), M_DEFAULT,
M_LETTER + M_UPPERCASE, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(1), M_DEFAULT,
M_LETTER + M_UPPERCASE, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(0), 3, M_DIGIT, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(0), 4, M_DIGIT, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(0), 5, M_DIGIT, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(1), 0, M_DIGIT, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(1), 1, M_DIGIT, M_NULL );
MstrSetConstraint(MilStrContext, M_STRING_INDEX(1), 2, M_DIGIT, M_NULL );
MosPrintf(MIL_TEXT("This program has defined a font with this ")
MIL_TEXT("Quebec plates mosaic image.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MbufLoad(IMAGE_FILE_TO_READ, MilImage);
MstrPreprocess(MilStrContext, M_DEFAULT);
MstrRead(MilStrContext, MilImage, MilStrResult);
MappTimer(M_DEFAULT, M_TIMER_RESET+M_SYNCHRONOUS, M_NULL);
MstrRead(MilStrContext, MilImage, MilStrResult);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &Time);
MstrGetResult(MilStrResult, M_GENERAL, M_STRING_NUMBER + M_TYPE_MIL_INT,
&NumberOfStringRead);
if( NumberOfStringRead >= 1)
{
MosPrintf(MIL_TEXT("The license plate was read successfully (%.2lf ms)\n\n"),
Time*1000 );
MgraColor(M_DEFAULT, M_COLOR_BLUE);
MstrDraw(M_DEFAULT, MilStrResult, MilOverlayImage, M_DRAW_STRING, M_ALL,
M_NULL, M_DEFAULT);
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MstrDraw(M_DEFAULT, MilStrResult, MilOverlayImage, M_DRAW_STRING_BOX, M_ALL,
M_NULL, M_DEFAULT);
MosPrintf(MIL_TEXT(" String Score\n") );
MosPrintf(MIL_TEXT(" -----------------------------------\n") );
MstrGetResult(MilStrResult, 0, M_STRING+M_TYPE_TEXT_CHAR, StringResult);
MstrGetResult(MilStrResult, 0, M_STRING_SCORE, &Score);
MosPrintf(MIL_TEXT(" %s %.1lf\n"), StringResult, Score );
}
else
{
MosPrintf(MIL_TEXT("Error: Plate was not read.\n"));
}
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n\n"));
MosGetch();
MstrFree(MilStrContext);
MstrFree(MilStrResult);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}