#include <mil.h>
#define EXAMPLE_PATH M_IMAGE_PATH MIL_TEXT("USDotNumberStr/")
#define IMAGE_FILE EXAMPLE_PATH MIL_TEXT("USDotNumberStr.mim")
MIL_CONST_TEXT_PTR STRING_FONT = EXAMPLE_PATH MIL_TEXT("USDotNumberStr.msr");
#define STRUCT_ELEM_WIDTH 1
#define STRUCT_ELEM_HEIGHT 7
#define STRUCT_ELEM_DEPTH 32
#define ITERATION_NB 5
void ReadString(MIL_ID MilImage, MIL_ID MilGraphicList, MIL_CONST_TEXT_PTR StringFont);
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("USDotNumberStr\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This example demonstrates how to use the String Reader module to read a U.S.\n")
MIL_TEXT("Department of Transportation number. A vertical top-hat filtering is applied\n")
MIL_TEXT("before the read operation to enhance image quality.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT("image processing, string reader.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n"));
MosGetch();
}
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilGraphicList,
MilImage,
MilDispImage,
MilStructElem;
MIL_DOUBLE AnnotationColor = M_COLOR_GREEN;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &MilDisplay);
MgraAllocList(MilSystem, M_DEFAULT, &MilGraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, MilGraphicList);
MgraColor(M_DEFAULT, AnnotationColor);
PrintHeader();
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MbufRestore(IMAGE_FILE, MilSystem, &MilDispImage);
MdispSelect(MilDisplay, MilDispImage);
MosPrintf(MIL_TEXT("\nThe original image is displayed.\n\n")
MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufAlloc2d(MilSystem, STRUCT_ELEM_WIDTH, STRUCT_ELEM_HEIGHT, STRUCT_ELEM_DEPTH+M_UNSIGNED,
M_STRUCT_ELEMENT, &MilStructElem);
MbufClear(MilStructElem, 0);
MimMorphic(MilImage, MilDispImage, MilStructElem, M_TOP_HAT, ITERATION_NB, M_GRAYSCALE);
MosPrintf(MIL_TEXT("A top-hat filtering using a custom %dx%d structuring element is applied\n"),
STRUCT_ELEM_WIDTH,STRUCT_ELEM_HEIGHT);
MosPrintf(MIL_TEXT("to improve the background uniformity.\n\n")
MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
ReadString(MilDispImage, MilGraphicList, STRING_FONT);
MosPrintf(MIL_TEXT("Press <Enter> to finish.\n"));
MosGetch();
MbufFree(MilStructElem);
MbufFree(MilDispImage);
MbufFree(MilImage);
MgraFree(MilGraphicList);
MdispFree(MilDisplay);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
void ReadString(MIL_ID MilImage, MIL_ID MilGraphicList, MIL_CONST_TEXT_PTR StringFont)
{
MIL_ID MilStrContext,
MilStrResult;
MIL_TEXT_CHAR StringResult[20];
MIL_DOUBLE Score;
MIL_ID MilSystem = MbufInquire(MilImage, M_OWNER_SYSTEM, M_NULL);
MstrRestore(StringFont, MilSystem, M_DEFAULT, &MilStrContext);
MstrPreprocess(MilStrContext, M_DEFAULT);
MstrAllocResult(MilSystem, M_DEFAULT, &MilStrResult);
MstrRead(MilStrContext, MilImage, MilStrResult);
MstrGetResult(MilStrResult, 0, M_STRING+M_TYPE_TEXT_CHAR, StringResult);
MstrGetResult(MilStrResult, 0, M_STRING_SCORE, &Score);
MosPrintf(MIL_TEXT("The string starting with \"USDOT\" is read using a pre-defined context.\n")
MIL_TEXT(" -----------------------------\n")
MIL_TEXT(" String Score\n")
MIL_TEXT(" -----------------------------\n"));
MosPrintf(MIL_TEXT(" %s %.1f\n\n"), StringResult, Score);
MstrDraw(M_DEFAULT, MilStrResult, MilGraphicList, M_DRAW_STRING_BOX+M_DRAW_STRING, M_ALL,
M_NULL, M_DEFAULT);
MstrFree(MilStrResult);
MstrFree(MilStrContext);
}