#include <mil.h>
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("VariousCodeReadings\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program reads different types of codes,\n")
MIL_TEXT("under various conditions.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT("graphic, calibration, code.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
static const MIL_TEXT_CHAR* CodeForegroundColorFilename = M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/BlackAndWhiteDatamatrix.mim");
void CodeForegroundColor(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay);
static const MIL_TEXT_CHAR* CodeRotationFilename = M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/GS1Databar.mim");
void CodeRotation(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay);
const MIL_INT NUMBER_GRID_ROWS = 19;
const MIL_INT NUMBER_GRID_COLUMNS = 19;
static const MIL_TEXT_CHAR* CalDeformationFilename = M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/CalibrationQRCode.mim");
static const MIL_TEXT_CHAR* CodeDeformationFilename = M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/DeformedQRCode.mim");
void CodeDeformation(const MIL_TEXT_CHAR* SrcFilename,
const MIL_TEXT_CHAR* GridFilename,
MIL_INT RowNumber,
MIL_INT ColumNumber,
MIL_ID MilSystem,
MIL_ID MilDisplay);
const MIL_INT CodeUnevenGridNumber = 5;
static const MIL_TEXT_CHAR* CodeUnevenGridFilename[CodeUnevenGridNumber] =
{
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/UnevenGridDatamatrix1.mim"),
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/UnevenGridDatamatrix2.mim"),
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/UnevenGridDatamatrix3.mim"),
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/UnevenGridDatamatrix4.mim"),
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/UnevenGridDatamatrix5.mim")
};
void CodeUnevenGrid(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay);
static const MIL_TEXT_CHAR* CodeAspectRatioAndShearingFilename = M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/SampleQRCode.mim");
void CodeAspectRatioAndShearing(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay);
const MIL_INT CodeFlippedDatamatrixNumber = 2;
static const MIL_TEXT_CHAR* CodeFlippedDatamatrixFilename[CodeFlippedDatamatrixNumber] =
{
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/FlippedDatamatrix1.mim"),
M_IMAGE_PATH MIL_TEXT("VariousCodeReadings/FlippedDatamatrix2.mim")
};
void CodeFlippedDatamatrix(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay);
void AllocDisplayImage(MIL_ID MilSystem,
MIL_ID MilSrcImage,
MIL_ID MilDisplay,
MIL_ID& MilDispProcImage,
MIL_ID& MilOverlayImage);
void RetrieveAndDrawCode(MIL_ID MilCodeResult,
MIL_ID MilDisplay,
MIL_ID MilOverlayImage,
MIL_DOUBLE DrawPosX,
MIL_DOUBLE DrawPosY,
bool DrawBox,
bool DrawCode);
int MosMain(void)
{
MIL_INT ii;
MIL_ID MilApplication = MappAlloc(M_NULL, M_DEFAULT, M_NULL);
MIL_ID MilSystem = MsysAlloc(M_DEFAULT, M_SYSTEM_HOST, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilDisplay = MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, M_NULL);
PrintHeader();
CodeForegroundColor(CodeForegroundColorFilename, MilSystem, MilDisplay);
CodeRotation(CodeRotationFilename, MilSystem, MilDisplay);
CodeDeformation(CodeDeformationFilename, CalDeformationFilename, 19, 19, MilSystem, MilDisplay);
for(ii=0; ii<CodeUnevenGridNumber; ii++)
CodeUnevenGrid(CodeUnevenGridFilename[ii], MilSystem, MilDisplay);
CodeAspectRatioAndShearing(CodeAspectRatioAndShearingFilename, MilSystem, MilDisplay);
for(ii=0; ii<CodeFlippedDatamatrixNumber; ii++)
CodeFlippedDatamatrix(CodeFlippedDatamatrixFilename[ii], MilSystem, MilDisplay);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
return 0;
}
void CodeForegroundColor(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[READING BLACK AND WHITE FOREGROUND COLOR CODES]\n\n")
MIL_TEXT("In this example two codes of opposite color are read\n")
MIL_TEXT("by setting the foreground color property.\n\n"));
MIL_ID MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MIL_INT SizeX;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, M_NULL);
McodeControl(MilCodeModel, M_USE_PRESEARCH, M_ENABLE);
McodeControl(MilCodeModel, M_FOREGROUND_VALUE, M_FOREGROUND_BLACK);
McodeRead(MilCodeContext, MilSrcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.25*SizeX, 10, true, false);
McodeControl(MilCodeModel, M_FOREGROUND_VALUE, M_FOREGROUND_WHITE);
McodeRead(MilCodeContext, MilSrcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.75*SizeX, 10, true, false);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
}
void CodeRotation(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[READING A ROTATED CODE]\n\n")
MIL_TEXT("In this example a linear code is read at any angle\n")
MIL_TEXT("by increasing the search angle range settings.\n\n"));
MIL_ID MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_INT SizeX;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_GS1_DATABAR, M_NULL, M_DEFAULT, M_NULL);
McodeControl(MilCodeModel, M_SEARCH_ANGLE_DELTA_NEG, 180);
McodeControl(MilCodeModel, M_SEARCH_ANGLE_DELTA_POS, 180);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, false);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
for(MIL_INT ii=5; ii<=360; ii+=5)
{
MdispControl(MilDisplay, M_UPDATE, M_DISABLE);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MimRotate(MilSrcImage, MilDispProcImage, (MIL_DOUBLE)(ii), M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_BILINEAR);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, false);
MdispControl(MilDisplay, M_UPDATE, M_ENABLE);
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
};
void CodeDeformation(const MIL_TEXT_CHAR* SrcFilename,
const MIL_TEXT_CHAR* GridFilename,
MIL_INT RowNumber,
MIL_INT ColumNumber,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[RECTIFYING AND READING A DISTORTED CODE]\n\n")
MIL_TEXT("In this example a distorted code printed on a given non planar surface\n")
MIL_TEXT("is read by calibrating and correcting the image of the printing surface.\n\n"));
MIL_ID MilSrcImage = MbufRestore(GridFilename, MilSystem, M_NULL);
MIL_ID MilCalContext = McalAlloc(MilSystem, M_LINEAR_INTERPOLATION, M_DEFAULT, M_NULL);
McalGrid(MilCalContext, MilSrcImage, 0, 0, 0, NUMBER_GRID_ROWS, NUMBER_GRID_COLUMNS, 1, 1, M_DEFAULT, M_CHESSBOARD_GRID);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MgraColor(M_DEFAULT, M_COLOR_BLUE);
McalDraw(M_DEFAULT, MilSrcImage, MilOverlayImage, M_DRAW_RELATIVE_COORDINATE_SYSTEM, M_DEFAULT, M_DEFAULT);
MosPrintf(MIL_TEXT("The image of the surface is calibrated using a chessboard grid.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
McalAssociate(MilCalContext, MilSrcImage, M_DEFAULT);
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MIL_INT SizeX, SizeY;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MbufInquire(MilSrcImage, M_SIZE_Y, &SizeY);
MgraColor(M_DEFAULT, M_COLOR_BLUE);
McalDraw(M_DEFAULT, MilSrcImage, MilOverlayImage, M_DRAW_RELATIVE_COORDINATE_SYSTEM, M_DEFAULT, M_DEFAULT);
MosPrintf(MIL_TEXT("The image of the distorted code is displayed.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
McalTransformImage(MilSrcImage, MilDispProcImage, MilCalContext, M_BILINEAR, M_DEFAULT, M_WARP_IMAGE + M_CLIP);
McalDraw(M_DEFAULT, MilDispProcImage, MilOverlayImage, M_DRAW_RELATIVE_COORDINATE_SYSTEM, M_DEFAULT, M_DEFAULT);
MosPrintf(MIL_TEXT("The transformed image of the code is displayed.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_QRCODE, M_NULL, M_DEFAULT, M_NULL);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 0.5*SizeY, true, true);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
McalFree(MilCalContext);
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
};
void CodeUnevenGrid(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[READING UNEVEN GRID STEP DISTORTED DATAMATRIX]\n\n")
MIL_TEXT("In this example an uneven grid step distorted datamatrix is\n")
MIL_TEXT("read by enabling the reading with distortion capability.\n\n"));
MIL_ID MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_INT SizeX;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, M_NULL);
McodeControl(MilCodeModel, M_FOREGROUND_VALUE, M_FOREGROUND_WHITE);
McodeControl(MilCodeModel, M_USE_PRESEARCH, M_ENABLE);
McodeControl(MilCodeModel, M_DISTORTION, M_UNEVEN_GRID_STEP);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, true);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
};
void CodeAspectRatioAndShearing(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[READING DATAMATRIX DISTORTED BY ASPECT RATIO AND SHEARING]\n\n")
MIL_TEXT("In this example a datamatrix is read even if it has an aspect ratio\n")
MIL_TEXT("different than 1 or if it has shearing.\n\n"));
MIL_INT ii;
const MIL_DOUBLE StepValue = 0.01;
const MIL_INT Iterations = 10;
MIL_ID MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_INT SizeX;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_QRCODE, M_NULL, M_DEFAULT, M_NULL);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, true);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_ID MilWarpMatrix = MbufAlloc2d(MilSystem, 3, 3, 32+M_FLOAT, M_ARRAY, M_NULL);
MgenWarpParameter(M_NULL, MilWarpMatrix, M_NULL, M_WARP_POLYNOMIAL, M_TRANSLATE, 0, 0);
for(ii=0; ii<Iterations; ii++)
{
MgenWarpParameter(MilWarpMatrix, MilWarpMatrix, M_NULL, M_WARP_POLYNOMIAL, M_SCALE, 1.0, 1.0+StepValue);
MdispControl(MilDisplay, M_UPDATE, M_DISABLE);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MimWarp(MilSrcImage, MilDispProcImage, MilWarpMatrix, M_NULL, M_WARP_POLYNOMIAL, M_BILINEAR+M_OVERSCAN_CLEAR);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, true);
MdispControl(MilDisplay, M_UPDATE, M_ENABLE);
}
for(ii=0; ii<Iterations; ii++)
{
MgenWarpParameter(MilWarpMatrix, MilWarpMatrix, M_NULL, M_WARP_POLYNOMIAL, M_SHEAR_X, StepValue, M_DEFAULT);
MdispControl(MilDisplay, M_UPDATE, M_DISABLE);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MimWarp(MilSrcImage, MilDispProcImage, MilWarpMatrix, M_NULL, M_WARP_POLYNOMIAL, M_BILINEAR+M_OVERSCAN_CLEAR);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, true);
MdispControl(MilDisplay, M_UPDATE, M_ENABLE);
}
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilWarpMatrix);
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
};
void CodeFlippedDatamatrix(const MIL_TEXT_CHAR* SrcFilename,
MIL_ID MilSystem,
MIL_ID MilDisplay)
{
MosPrintf(MIL_TEXT("[READING FLIPPED DATAMATRIX]\n\n")
MIL_TEXT("In this example a flipped datamatrix is\n")
MIL_TEXT("read by enabling the flip capability.\n\n"));
MIL_ID MilSrcImage = MbufRestore(SrcFilename, MilSystem, M_NULL);
MIL_ID MilDispProcImage,
MilOverlayImage;
AllocDisplayImage(MilSystem, MilSrcImage, MilDisplay, MilDispProcImage, MilOverlayImage);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MIL_INT SizeX;
MbufInquire(MilSrcImage, M_SIZE_X, &SizeX);
MIL_ID MilCodeContext = McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult = McodeAllocResult(MilSystem, M_DEFAULT, M_NULL);
MIL_ID MilCodeModel = McodeModel(MilCodeContext, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, M_NULL);
McodeControl(MilCodeModel, M_USE_PRESEARCH, M_ENABLE);
McodeControl(MilCodeModel, M_DISTORTION, M_UNEVEN_GRID_STEP);
McodeControl(MilCodeModel, M_CODE_FLIP, M_ANY);
McodeRead(MilCodeContext, MilDispProcImage, MilCodeResult);
RetrieveAndDrawCode(MilCodeResult, MilDisplay, MilOverlayImage, 0.5*SizeX, 10, true, true);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilSrcImage);
MbufFree(MilDispProcImage);
McodeFree(MilCodeContext);
McodeFree(MilCodeResult);
};
void RetrieveAndDrawCode(MIL_ID MilCodeResult,
MIL_ID MilDisplay,
MIL_ID MilOverlayImage,
MIL_DOUBLE DrawPosX,
MIL_DOUBLE DrawPosY,
bool DrawBox,
bool DrawCode)
{
const MIL_INT DispOffsetY = 30;
MIL_INT ReadStatus;
McodeGetResult(MilCodeResult, M_STATUS+M_TYPE_MIL_INT, &ReadStatus);
if (ReadStatus == M_STATUS_READ_OK)
{
MIL_INT ResultStringSize;
McodeGetResult(MilCodeResult, M_STRING_SIZE+M_TYPE_MIL_INT, &ResultStringSize);
MIL_TEXT_CHAR* ResultString = new MIL_TEXT_CHAR[ResultStringSize+1];
McodeGetResult(MilCodeResult, M_STRING, ResultString);
MIL_INT ii;
for(ii=0; ResultString[ii] != MIL_TEXT('\0'); ii++)
{
if ((ResultString[ii] < MIL_TEXT('0')) || (ResultString[ii] > MIL_TEXT('Z')))
ResultString[ii] = MIL_TEXT(' ');
}
const MIL_TEXT_CHAR PrefixString[] = MIL_TEXT("Read code: ");
MIL_INT OutputStringSize = ResultStringSize + MosStrlen(PrefixString) + 1;
MIL_TEXT_CHAR* OutputString = new MIL_TEXT_CHAR[OutputStringSize];
MosSprintf(OutputString, OutputStringSize, MIL_TEXT("%s%s"), PrefixString, ResultString);
MgraColor(M_DEFAULT, M_COLOR_CYAN);
MgraBackColor(M_DEFAULT, M_COLOR_GRAY);
MgraControl(M_DEFAULT, M_TEXT_ALIGN_HORIZONTAL, M_CENTER);
MgraText(M_DEFAULT, MilOverlayImage, DrawPosX, DrawPosY, OutputString);
if(DrawBox)
{
MgraColor(M_DEFAULT, M_COLOR_GREEN);
McodeDraw(M_DEFAULT, MilCodeResult, MilOverlayImage, M_DRAW_BOX, 0, M_DEFAULT);
}
if(DrawCode)
{
MgraColor(M_DEFAULT, M_COLOR_RED);
McodeDraw(M_DEFAULT, MilCodeResult, MilOverlayImage, M_DRAW_CODE, 0, M_DEFAULT);
}
MIL_DOUBLE PositionX, PositionY, SizeX, SizeY;
McodeControl(MilCodeResult, M_RESULT_OUTPUT_UNITS, M_PIXEL);
McodeGetResult(MilCodeResult, M_POSITION_X, &PositionX);
McodeGetResult(MilCodeResult, M_POSITION_X, &PositionY);
McodeGetResult(MilCodeResult, M_SIZE_X, &SizeX);
McodeGetResult(MilCodeResult, M_SIZE_Y, &SizeY);
MosPrintf(MIL_TEXT("Reading was successful.\n\n"));
MosPrintf(MIL_TEXT(" - %s\n"), OutputString);
MosPrintf(MIL_TEXT(" - Position: (%.2f, %.2f)\n"), PositionX, PositionY);
MosPrintf(MIL_TEXT(" - Dimensions: (%.2f x %.2f)\n\n"), SizeX, SizeY);
delete [] ResultString;
delete [] OutputString;
}
else
{
MosPrintf(MIL_TEXT("Code read operation failed.\n\n"));
}
}
void AllocDisplayImage(MIL_ID MilSystem,
MIL_ID MilSrcImage,
MIL_ID MilDisplay,
MIL_ID& MilDispProcImage,
MIL_ID& MilOverlayImage)
{
MIL_INT SrcSizeX, SrcSizeY;
MbufInquire(MilSrcImage, M_SIZE_X, &SrcSizeX);
MbufInquire(MilSrcImage, M_SIZE_Y, &SrcSizeY);
MbufAlloc2d(MilSystem,
SrcSizeX,
SrcSizeY,
8L+M_UNSIGNED,
M_IMAGE+M_PROC+M_DISP,
&MilDispProcImage);
MbufCopy(MilSrcImage, MilDispProcImage);
MdispSelect(MilDisplay, MilDispProcImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
}