#include <mil.h>
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n"));
MosPrintf(MIL_TEXT("EllipseShapeFinder\n\n"));
MosPrintf(MIL_TEXT("[SYNOPSIS]\n"));
MosPrintf(MIL_TEXT("This example uses model finder to define ellipse models and search for\n"));
MosPrintf(MIL_TEXT("ellipses in target images. Different cases are presented, such as searching\n"));
MosPrintf(MIL_TEXT("for multiple occurrences in a defined aspect ratio range, and using a large\n"));
MosPrintf(MIL_TEXT("range to search in a complex scene with challenging search conditions).\n\n"));
MosPrintf(MIL_TEXT("[MODULES USED]\n"));
MosPrintf(MIL_TEXT("Modules used: application, system, display,\n geometric model finder.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
void EllipseSearchExample1(MIL_ID MilSystem, MIL_ID MilDisplay);
void EllipseAspectRatioRangeSearchExample1(MIL_ID MilSystem, MIL_ID MilDisplay);
void EllipseAspectRatioRangeSearchExample2(MIL_ID MilSystem, MIL_ID MilDisplay);
void EllipseSearchExample2(MIL_ID MilSystem, MIL_ID MilDisplay);
void EllipseSearchExample3(MIL_ID MilSystem, MIL_ID MilDisplay);
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &MilDisplay);
PrintHeader();
EllipseSearchExample1(MilSystem, MilDisplay);
EllipseAspectRatioRangeSearchExample1(MilSystem, MilDisplay);
EllipseAspectRatioRangeSearchExample2(MilSystem, MilDisplay);
EllipseSearchExample2(MilSystem, MilDisplay);
EllipseSearchExample3(MilSystem, MilDisplay);
MdispFree(MilDisplay);
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
#define ELLIPSE_SEARCH_TARGET_IMAGE_1 M_IMAGE_PATH MIL_TEXT("/EllipseShapeFinder/EllipseSearchTarget1.mim")
#define MODEL_WIDTH_1 160.0
#define MODEL_HEIGHT_1 120.0
#define MODEL_MAX_OCCURRENCES 10L
void EllipseSearchExample1(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilImage,
GraphicList;
MIL_ID MilSearchContext,
MilResult;
MIL_DOUBLE PositionDrawColor = M_COLOR_RED;
MIL_DOUBLE ModelDrawColor = M_COLOR_GREEN;
MIL_DOUBLE BoxDrawColor = M_COLOR_BLUE;
MIL_INT NumResults = 0L;
MIL_DOUBLE Score[MODEL_MAX_OCCURRENCES],
XPosition[MODEL_MAX_OCCURRENCES],
YPosition[MODEL_MAX_OCCURRENCES],
Width[MODEL_MAX_OCCURRENCES],
Height[MODEL_MAX_OCCURRENCES],
Time = 0.0;
int i;
MbufRestore(ELLIPSE_SEARCH_TARGET_IMAGE_1, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MmodAlloc(MilSystem, M_SHAPE_ELLIPSE, M_DEFAULT, &MilSearchContext);
MmodAllocResult(MilSystem, M_SHAPE_ELLIPSE, &MilResult);
MmodDefine(MilSearchContext, M_ELLIPSE, M_DEFAULT, MODEL_WIDTH_1,
MODEL_HEIGHT_1, M_DEFAULT, M_DEFAULT);
MmodPreprocess(MilSearchContext, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_RESET + M_SYNCHRONOUS, M_NULL);
MmodFind(MilSearchContext, MilImage, MilResult);
MappTimer(M_DEFAULT, M_TIMER_READ + M_SYNCHRONOUS, &Time);
MmodGetResult(MilResult, M_DEFAULT, M_NUMBER + M_TYPE_MIL_INT, &NumResults);
MosPrintf(MIL_TEXT("\n\nAn ellipse model was defined with "));
MosPrintf(MIL_TEXT("a nominal width of %-3.1f%. "), MODEL_WIDTH_1);
MosPrintf(MIL_TEXT("and a nominal \nheight of %-3.1f%..\n\n"), MODEL_HEIGHT_1);
if ((NumResults >= 1) && (NumResults <= MODEL_MAX_OCCURRENCES))
{
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_X, XPosition);
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_Y, YPosition);
MmodGetResult(MilResult, M_DEFAULT, M_WIDTH, Width);
MmodGetResult(MilResult, M_DEFAULT, M_HEIGHT, Height);
MmodGetResult(MilResult, M_DEFAULT, M_SCORE, Score);
MosPrintf(MIL_TEXT("The ellipse was found in the target image:\n\n"));
MosPrintf(MIL_TEXT("Result X-Position Y-Position Width Height Aspect-Ratio Score\n\n"));
for(i = 0; i < NumResults; i++)
{
MosPrintf(MIL_TEXT("%-9d%-13.2f%-13.2f%-9.2f%-11.2f%-13.2f%-5.2f%%\n"), i, XPosition[i],
YPosition[i], Width[i], Height[i], Width[i] / Height[i], Score[i]);
}
MosPrintf(MIL_TEXT("\nThe search time was %.1f ms.\n\n"), Time*1000.0);
MgraColor(M_DEFAULT, PositionDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_POSITION, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, BoxDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_BOX, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, ModelDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_EDGES, M_DEFAULT, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("The model was not found or the number of models ")
MIL_TEXT("found is greater than\n"));
MosPrintf(MIL_TEXT("the specified maximum number of occurrence !\n\n"));
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MmodFree(MilSearchContext);
MmodFree(MilResult);
}
#define SAGITTA_TOLERANCE_1 40
#define NUMBER_OF_MODEL_1 7
void EllipseAspectRatioRangeSearchExample1(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilImage,
GraphicList;
MIL_ID MilSearchContext,
MilResult;
MIL_DOUBLE PositionDrawColor = M_COLOR_RED;
MIL_DOUBLE ModelDrawColor = M_COLOR_GREEN;
MIL_INT NumResults = 0L;
MIL_DOUBLE Score[MODEL_MAX_OCCURRENCES],
XPosition[MODEL_MAX_OCCURRENCES],
YPosition[MODEL_MAX_OCCURRENCES],
Width[MODEL_MAX_OCCURRENCES],
Height[MODEL_MAX_OCCURRENCES],
Time = 0.0;
int i;
MbufRestore(ELLIPSE_SEARCH_TARGET_IMAGE_1, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MmodAlloc(MilSystem, M_SHAPE_ELLIPSE, M_DEFAULT, &MilSearchContext);
MmodAllocResult(MilSystem, M_SHAPE_ELLIPSE, &MilResult);
MmodDefine(MilSearchContext, M_ELLIPSE, M_DEFAULT, MODEL_WIDTH_1,
MODEL_HEIGHT_1, M_DEFAULT, M_DEFAULT);
MmodControl(MilSearchContext, M_CONTEXT, M_DETAIL_LEVEL, M_HIGH);
MmodControl(MilSearchContext, 0, M_MODEL_ASPECT_RATIO_MAX_FACTOR, M_INFINITE);
MmodControl(MilSearchContext, 0, M_MODEL_ASPECT_RATIO_MIN_FACTOR, M_CIRCLE_ASPECT_RATIO);
MmodControl(MilSearchContext, 0, M_SCALE_MAX_FACTOR, M_INFINITE);
MmodControl(MilSearchContext, 0, M_SCALE_MIN_FACTOR, 0);
MmodControl(MilSearchContext, M_DEFAULT, M_SAGITTA_TOLERANCE, SAGITTA_TOLERANCE_1);
MmodControl(MilSearchContext, M_DEFAULT, M_NUMBER, NUMBER_OF_MODEL_1);
MmodControl(MilSearchContext, M_DEFAULT, M_MIN_SEPARATION_ANGLE, M_DISABLE);
MmodPreprocess(MilSearchContext, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_RESET + M_SYNCHRONOUS, M_NULL);
MmodFind(MilSearchContext, MilImage, MilResult);
MappTimer(M_DEFAULT, M_TIMER_READ + M_SYNCHRONOUS, &Time);
MmodGetResult(MilResult, M_DEFAULT, M_NUMBER + M_TYPE_MIL_INT, &NumResults);
MosPrintf(MIL_TEXT("\n\nAn ellipse model was defined with "));
MosPrintf(MIL_TEXT("a nominal width of %-3.1f%, "), MODEL_WIDTH_1);
MosPrintf(MIL_TEXT("a nominal \nheight of %-3.1f%, "), MODEL_HEIGHT_1);
MosPrintf(MIL_TEXT("an infinite scale tolerance, "));
MosPrintf(MIL_TEXT("and an infinite aspect \nration tolerance.\n\n"));
if((NumResults >= 1) && (NumResults <= MODEL_MAX_OCCURRENCES))
{
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_X, XPosition);
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_Y, YPosition);
MmodGetResult(MilResult, M_DEFAULT, M_WIDTH, Width);
MmodGetResult(MilResult, M_DEFAULT, M_HEIGHT, Height);
MmodGetResult(MilResult, M_DEFAULT, M_SCORE, Score);
MosPrintf(MIL_TEXT("Multiple ellipses, as indicated below, were found "));
MosPrintf(MIL_TEXT("in the target image, \ndespite the following complexities:\n"));
MosPrintf(MIL_TEXT("\t. Large aspect ratio range.\n"));
MosPrintf(MIL_TEXT("\t. Large scale range.\n"));
MosPrintf(MIL_TEXT("\t. Low contrast.\n\n"));
MosPrintf(MIL_TEXT("Result X-Position Y-Position Width Height Aspect-Ratio Score\n\n"));
for(i = 0; i < NumResults; i++)
{
MosPrintf(MIL_TEXT("%-9d%-13.2f%-13.2f%-9.2f%-11.2f%-13.2f%-5.2f%%\n"), i, XPosition[i],
YPosition[i], Width[i], Height[i], Width[i] / Height[i], Score[i]);
}
MosPrintf(MIL_TEXT("\nThe search time was %.1f ms.\n\n"), Time*1000.0);
MgraColor(M_DEFAULT, PositionDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_POSITION, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, ModelDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_EDGES, M_DEFAULT, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("The model was not found or the number of models ")
MIL_TEXT("found is greater than\n"));
MosPrintf(MIL_TEXT("the specified maximum number of occurrence !\n\n"));
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MmodFree(MilSearchContext);
MmodFree(MilResult);
}
#define SCALE_REFERENCE_1 0.5
#define MIN_ASPECT_RATIO_FACTOR_VALUE_1 0.9
#define MAX_ASPECT_RATIO_FACTOR_VALUE_1 1.1
void EllipseAspectRatioRangeSearchExample2(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilImage,
GraphicList;
MIL_ID MilSearchContext,
MilResult;
MIL_DOUBLE PositionDrawColor = M_COLOR_RED;
MIL_DOUBLE ModelDrawColor = M_COLOR_GREEN;
MIL_INT NumResults = 0L;
MIL_DOUBLE Score[MODEL_MAX_OCCURRENCES],
XPosition[MODEL_MAX_OCCURRENCES],
YPosition[MODEL_MAX_OCCURRENCES],
Width[MODEL_MAX_OCCURRENCES],
Height[MODEL_MAX_OCCURRENCES],
Time = 0.0;
int i;
MbufRestore(ELLIPSE_SEARCH_TARGET_IMAGE_1, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MmodAlloc(MilSystem, M_SHAPE_ELLIPSE, M_DEFAULT, &MilSearchContext);
MmodAllocResult(MilSystem, M_SHAPE_ELLIPSE, &MilResult);
MmodDefine(MilSearchContext, M_ELLIPSE, M_DEFAULT, MODEL_WIDTH_1,
MODEL_HEIGHT_1, M_DEFAULT, M_DEFAULT);
MmodControl(MilSearchContext, M_CONTEXT, M_DETAIL_LEVEL, M_HIGH);
MmodControl(MilSearchContext, M_DEFAULT, M_SCALE, SCALE_REFERENCE_1);
MmodControl(MilSearchContext, M_DEFAULT, M_MODEL_ASPECT_RATIO_MIN_FACTOR, MIN_ASPECT_RATIO_FACTOR_VALUE_1);
MmodControl(MilSearchContext, M_DEFAULT, M_MODEL_ASPECT_RATIO_MAX_FACTOR, MAX_ASPECT_RATIO_FACTOR_VALUE_1);
MmodControl(MilSearchContext, M_DEFAULT, M_SEARCH_ASPECT_RATIO_CONSTRAINT, M_DISABLE);
MmodControl(MilSearchContext, M_DEFAULT, M_SAGITTA_TOLERANCE, SAGITTA_TOLERANCE_1);
MmodPreprocess(MilSearchContext, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_RESET + M_SYNCHRONOUS, M_NULL);
MmodFind(MilSearchContext, MilImage, MilResult);
MappTimer(M_DEFAULT, M_TIMER_READ + M_SYNCHRONOUS, &Time);
MmodGetResult(MilResult, M_DEFAULT, M_NUMBER + M_TYPE_MIL_INT, &NumResults);
MosPrintf(MIL_TEXT("\n\nAn ellipse model was defined with "));
MosPrintf(MIL_TEXT("a nominal width of %-3.1f%, "), SCALE_REFERENCE_1 * MODEL_WIDTH_1);
MosPrintf(MIL_TEXT("a nominal \nheight of %-3.1f%, "), SCALE_REFERENCE_1 * MODEL_HEIGHT_1);
MosPrintf(MIL_TEXT("and an aspect ratio tolerance of 10 %%.\n\n"));
if((NumResults >= 1) && (NumResults <= MODEL_MAX_OCCURRENCES))
{
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_X, XPosition);
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_Y, YPosition);
MmodGetResult(MilResult, M_DEFAULT, M_WIDTH, Width);
MmodGetResult(MilResult, M_DEFAULT, M_HEIGHT, Height);
MmodGetResult(MilResult, M_DEFAULT, M_SCORE, Score);
MosPrintf(MIL_TEXT("The ellipse was found in the target image, "));
MosPrintf(MIL_TEXT("while respecting the aspect \nratio range.\n\n"));
MosPrintf(MIL_TEXT("Result X-Position Y-Position Width Height Aspect-Ratio Score\n\n"));
for(i = 0; i < NumResults; i++)
{
MosPrintf(MIL_TEXT("%-9d%-13.2f%-13.2f%-9.2f%-11.2f%-13.2f%-5.2f%%\n"), i, XPosition[i],
YPosition[i], Width[i], Height[i], Width[i] / Height[i], Score[i]);
}
MosPrintf(MIL_TEXT("\nThe search time was %.1f ms.\n\n"), Time*1000.0);
MgraColor(M_DEFAULT, PositionDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_POSITION, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, ModelDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_EDGES, M_DEFAULT, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("The model was not found or the number of models ")
MIL_TEXT("found is greater than\n"));
MosPrintf(MIL_TEXT("the specified maximum number of occurrence !\n\n"));
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MmodFree(MilSearchContext);
MmodFree(MilResult);
}
#define ELLIPSE_SEARCH_TARGET_IMAGE_2 M_IMAGE_PATH MIL_TEXT("/EllipseShapeFinder/EllipseSearchTarget2.mim")
#define NUMBER_OF_MODELS_2 7L
#define MODEL_WIDTH_2 320.0
#define MODEL_HEIGHT_2 180.0
#define SMOOTHNESS_VALUE_2 100.0
#define MIN_SCALE_FACTOR_VALUE_2 0.1
void EllipseSearchExample2(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilImage,
GraphicList;
MIL_ID MilSearchContext,
MilResult;
MIL_DOUBLE PositionDrawColor = M_COLOR_RED;
MIL_DOUBLE ModelDrawColor = M_COLOR_GREEN;
MIL_INT NumResults = 0L;
MIL_DOUBLE Score[MODEL_MAX_OCCURRENCES],
XPosition[MODEL_MAX_OCCURRENCES],
YPosition[MODEL_MAX_OCCURRENCES],
Width[MODEL_MAX_OCCURRENCES],
Height[MODEL_MAX_OCCURRENCES],
Time = 0.0;
int i;
MbufRestore(ELLIPSE_SEARCH_TARGET_IMAGE_2, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MmodAlloc(MilSystem, M_SHAPE_ELLIPSE, M_DEFAULT, &MilSearchContext);
MmodAllocResult(MilSystem, M_SHAPE_ELLIPSE, &MilResult);
MmodDefine(MilSearchContext, M_ELLIPSE, M_DEFAULT, MODEL_WIDTH_2,
MODEL_HEIGHT_2, M_DEFAULT, M_DEFAULT);
MmodControl(MilSearchContext, M_CONTEXT, M_SMOOTHNESS, SMOOTHNESS_VALUE_2);
MmodControl(MilSearchContext, 0, M_SCALE_MIN_FACTOR, MIN_SCALE_FACTOR_VALUE_2);
MmodControl(MilSearchContext, M_DEFAULT, M_NUMBER, NUMBER_OF_MODELS_2);
MmodPreprocess(MilSearchContext, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_RESET + M_SYNCHRONOUS, M_NULL);
MmodFind(MilSearchContext, MilImage, MilResult);
MappTimer(M_DEFAULT, M_TIMER_READ + M_SYNCHRONOUS, &Time);
MmodGetResult(MilResult, M_DEFAULT, M_NUMBER + M_TYPE_MIL_INT, &NumResults);
MosPrintf(MIL_TEXT("\n\nAn ellipse model was defined with "));
MosPrintf(MIL_TEXT("a nominal width of %-3.1f%. "), MODEL_WIDTH_2);
MosPrintf(MIL_TEXT("and a nominal \nheight of %-3.1f%..\n\n"), MODEL_HEIGHT_2);
if ((NumResults >= 1) && (NumResults <= MODEL_MAX_OCCURRENCES))
{
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_X, XPosition);
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_Y, YPosition);
MmodGetResult(MilResult, M_DEFAULT, M_WIDTH, Width);
MmodGetResult(MilResult, M_DEFAULT, M_HEIGHT, Height);
MmodGetResult(MilResult, M_DEFAULT, M_SCORE, Score);
MosPrintf(MIL_TEXT("Multiple ellipses, as indicated below, were found in the "));
MosPrintf(MIL_TEXT("target image, \ndespite the following complexitie:\n "));
MosPrintf(MIL_TEXT("\t. High scale range.\n\n"));
MosPrintf(MIL_TEXT("Result X-Position Y-Position Width Height Aspect-Ratio Score\n\n"));
for (i = 0; i<NumResults; i++)
{
MosPrintf(MIL_TEXT("%-9d%-13.2f%-13.2f%-9.2f%-11.2f%-13.2f%-5.2f%%\n"), i, XPosition[i],
YPosition[i], Width[i], Height[i], Width[i] / Height[i], Score[i]);
}
MosPrintf(MIL_TEXT("\nThe search time was %.1f ms.\n\n"), Time*1000.0);
MgraColor(M_DEFAULT, PositionDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_POSITION, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, ModelDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_EDGES, M_DEFAULT, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("The ellipses were not found or the number of ")
MIL_TEXT("ellipses found is greater than\n"));
MosPrintf(MIL_TEXT("the defined value of maximum occurrences !\n\n"));
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MmodFree(MilSearchContext);
MmodFree(MilResult);
}
#define ELLIPSE_SEARCH_TARGET_IMAGE_3 M_IMAGE_PATH MIL_TEXT("/EllipseShapeFinder/EllipseSearchTarget3.mim")
#define NUMBER_OF_MODELS_3 2L
#define MODEL_WIDTH_3 480.0
#define MODEL_HEIGHT_3 360.0
#define SMOOTHNESS_VALUE_3 60.0
#define SAGITTA_TOLERANCE_3 10
void EllipseSearchExample3(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilImage,
GraphicList;
MIL_ID MilSearchContext,
MilResult;
MIL_DOUBLE PositionDrawColor = M_COLOR_RED;
MIL_DOUBLE ModelDrawColor = M_COLOR_GREEN;
MIL_INT NumResults = 0L;
MIL_DOUBLE Score[MODEL_MAX_OCCURRENCES],
XPosition[MODEL_MAX_OCCURRENCES],
YPosition[MODEL_MAX_OCCURRENCES],
Width[MODEL_MAX_OCCURRENCES],
Height[MODEL_MAX_OCCURRENCES],
Time = 0.0;
int i;
MbufRestore(ELLIPSE_SEARCH_TARGET_IMAGE_3, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MgraAllocList(MilSystem, M_DEFAULT, &GraphicList);
MdispControl(MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);
MmodAlloc(MilSystem, M_SHAPE_ELLIPSE, M_DEFAULT, &MilSearchContext);
MmodAllocResult(MilSystem, M_SHAPE_ELLIPSE, &MilResult);
MmodDefine(MilSearchContext, M_ELLIPSE, M_DEFAULT, MODEL_WIDTH_3,
MODEL_HEIGHT_3, M_DEFAULT, M_DEFAULT);
MmodControl(MilSearchContext, M_CONTEXT, M_DETAIL_LEVEL, M_VERY_HIGH);
MmodControl(MilSearchContext, M_CONTEXT, M_SMOOTHNESS, SMOOTHNESS_VALUE_3);
MmodControl(MilSearchContext, M_DEFAULT, M_NUMBER, NUMBER_OF_MODELS_3);
MmodControl(MilSearchContext, M_DEFAULT, M_SAGITTA_TOLERANCE, SAGITTA_TOLERANCE_3);
MmodPreprocess(MilSearchContext, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_RESET + M_SYNCHRONOUS, M_NULL);
MmodFind(MilSearchContext, MilImage, MilResult);
MappTimer(M_DEFAULT, M_TIMER_READ + M_SYNCHRONOUS, &Time);
MmodGetResult(MilResult, M_DEFAULT, M_NUMBER + M_TYPE_MIL_INT, &NumResults);
MosPrintf(MIL_TEXT("\n\nAn ellipse model was defined with "));
MosPrintf(MIL_TEXT("a nominal width of %-3.1f%. "), MODEL_WIDTH_3);
MosPrintf(MIL_TEXT("and a nominal \nwidth of %-3.1f%..\n\n"), MODEL_HEIGHT_3);
if ((NumResults >= 1) && (NumResults <= MODEL_MAX_OCCURRENCES))
{
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_X, XPosition);
MmodGetResult(MilResult, M_DEFAULT, M_POSITION_Y, YPosition);
MmodGetResult(MilResult, M_DEFAULT, M_WIDTH, Width);
MmodGetResult(MilResult, M_DEFAULT, M_HEIGHT, Height);
MmodGetResult(MilResult, M_DEFAULT, M_SCORE, Score);
MosPrintf(MIL_TEXT("Multiple ellipses, as indicated below, were found in the target image, "));
MosPrintf(MIL_TEXT(" \ndespite the following complexities:\n"));
MosPrintf(MIL_TEXT("\t. Occlusion.\n"));
MosPrintf(MIL_TEXT("\t. Low contrast.\n"));
MosPrintf(MIL_TEXT("\t. Noisy edges.\n\n"));
MosPrintf(MIL_TEXT("Result X-Position Y-Position Width Height Aspect-Ratio Score\n\n"));
for(i = 0; i < NumResults; i++)
{
MosPrintf(MIL_TEXT("%-9d%-13.2f%-13.2f%-9.2f%-11.2f%-13.2f%-5.2f%%\n"), i, XPosition[i],
YPosition[i], Width[i], Height[i], Width[i] / Height[i], Score[i]);
}
MosPrintf(MIL_TEXT("\nThe search time was %.1f ms.\n\n"), Time*1000.0);
MgraColor(M_DEFAULT, PositionDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_POSITION, M_DEFAULT, M_DEFAULT);
MgraColor(M_DEFAULT, ModelDrawColor);
MmodDraw(M_DEFAULT, MilResult, GraphicList, M_DRAW_EDGES, M_DEFAULT, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("The ellipses were not found or the number of ")
MIL_TEXT("ellipses found is greater than\n"));
MosPrintf(MIL_TEXT("the defined value of maximum occurrences !\n\n"));
}
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MgraFree(GraphicList);
MbufFree(MilImage);
MmodFree(MilSearchContext);
MmodFree(MilResult);
}