Example #1
0
        static void Main(string[] args)
        {
            MIL_ID MilApplication = MIL.M_NULL;     // Application identifier.
            MIL_ID MilSystem      = MIL.M_NULL;     // System identifier.
            MIL_ID MilDisplay     = MIL.M_NULL;     // Display identifier.
            MIL_ID MilImage       = MIL.M_NULL;     // Image buffer identifier.

            // Allocate a default MIL application, system, display and image.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, ref MilImage);

            // If no allocation errors.
            if (MIL.MappGetError(MIL.M_DEFAULT, MIL.M_GLOBAL, MIL.M_NULL) == 0)
            {
                // Perform graphic operations in the display image.
                MIL.MgraColor(MIL.M_DEFAULT, 0xF0);
                MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_LARGE);
                MIL.MgraText(MIL.M_DEFAULT, MilImage, 160L, 230L, " Welcome to MIL !!! ");
                MIL.MgraColor(MIL.M_DEFAULT, 0xC0);
                MIL.MgraRect(MIL.M_DEFAULT, MilImage, 100, 150, 530, 340);
                MIL.MgraRect(MIL.M_DEFAULT, MilImage, 120, 170, 510, 320);
                MIL.MgraRect(MIL.M_DEFAULT, MilImage, 140, 190, 490, 300);

                // Print a message.
                Console.Write("\nSYSTEM ALLOCATION:\n");
                Console.Write("------------------\n\n");
                Console.Write("System allocation successful.\n\n");
                Console.Write("     \"Welcome to MIL !!!\"\n\n");
            }
            else
            {
                Console.Write("System allocation error !\n\n");
            }

            // Wait for a key press.
            Console.Write("Press <Enter> to end.\n");
            Console.ReadKey();

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MilImage);
        }
Example #2
0
        static void AutoAllocationModelExample(MIL_ID MilSystem, MIL_ID MilDisplay)
        {
            MIL_ID  MilImage        = MIL.M_NULL;               // Image buffer identifier.
            MIL_ID  MilSubImage     = MIL.M_NULL;               // Sub-image buffer identifier.
            MIL_ID  GraphicList     = MIL.M_NULL;               // Graphic list.
            MIL_ID  Model           = MIL.M_NULL;               // Model identifier.
            MIL_ID  Result          = MIL.M_NULL;               // Result buffer identifier.
            int     AllocError      = 0;                        // Allocation error variable.
            MIL_INT ImageWidth      = 0;                        // Target image dimensions
            MIL_INT ImageHeight     = 0;
            double  OrgX            = 0.0;                      // Original center of model.
            double  OrgY            = 0.0;
            double  x               = 0.0;                      // Result variables.
            double  y               = 0.0;
            double  Score           = 0.0;
            double  AnnotationColor = MIL.M_COLOR_GREEN;        // Drawing color.

            // Load model image into an image buffer.
            MIL.MbufRestore(AUTO_MODEL_IMAGE_FILE, MilSystem, ref MilImage);

            // Display the image.
            MIL.MdispSelect(MilDisplay, MilImage);

            // Allocate a graphic list to hold the subpixel annotations to draw.
            MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, ref GraphicList);

            // Associate the graphic list to the display for annotations.
            MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList);

            // Restrict the region to be processed to the bottom right corner of the image.
            MIL.MbufInquire(MilImage, MIL.M_SIZE_X, ref ImageWidth);
            MIL.MbufInquire(MilImage, MIL.M_SIZE_Y, ref ImageHeight);
            MIL.MbufChild2d(MilImage, ImageWidth / 2, ImageHeight / 2, ImageWidth / 2, ImageHeight / 2, ref MilSubImage);

            // Add an offset to the drawings so they are aligned with the processed child image.
            MIL.MgraControl(MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, (double)-(ImageWidth / 2));
            MIL.MgraControl(MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, (double)-(ImageHeight / 2));

            // Automatically allocate a normalized grayscale type model.
            MIL.MpatAllocAutoModel(MilSystem, MilSubImage, AUTO_MODEL_WIDTH, AUTO_MODEL_HEIGHT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NORMALIZED, MIL.M_DEFAULT, ref Model);

            // Set the search accuracy to high.
            MIL.MpatSetAccuracy(Model, MIL.M_HIGH);

            // Check for that model allocation was successful.
            MIL.MappGetError(MIL.M_DEFAULT, MIL.M_CURRENT, ref AllocError);
            if (AllocError == 0)
            {
                // Draw a box around the model.
                MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor);
                MIL.MpatDraw(MIL.M_DEFAULT, Model, GraphicList, MIL.M_DRAW_BOX + MIL.M_DRAW_POSITION, MIL.M_DEFAULT, MIL.M_ORIGINAL);
                Console.Write("A model was automatically defined in the image.\n");
                Console.Write("Press <Enter> to continue.\n\n");
                Console.ReadKey();

                // Clear the annotations.
                MIL.MgraClear(MIL.M_DEFAULT, GraphicList);

                // Load target image into an image buffer.
                MIL.MbufLoad(AUTO_MODEL_TARGET_IMAGE_FILE, MilImage);

                // Allocate result.
                MIL.MpatAllocResult(MilSystem, 1, ref Result);

                // Find model.
                MIL.MpatFindModel(MilSubImage, Model, Result);

                // If one model was found above the acceptance threshold set.
                if (MIL.MpatGetNumber(Result) == 1)
                {
                    // Get results.
                    MIL.MpatGetResult(Result, MIL.M_POSITION_X, ref x);
                    MIL.MpatGetResult(Result, MIL.M_POSITION_Y, ref y);
                    MIL.MpatGetResult(Result, MIL.M_SCORE, ref Score);

                    // Draw a box around the occurrence.
                    MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor);
                    MIL.MpatDraw(MIL.M_DEFAULT, Result, GraphicList, MIL.M_DRAW_BOX + MIL.M_DRAW_POSITION, MIL.M_DEFAULT, MIL.M_DEFAULT);

                    // Analyze and print results.
                    MIL.MpatInquire(Model, MIL.M_ORIGINAL_X, ref OrgX);
                    MIL.MpatInquire(Model, MIL.M_ORIGINAL_Y, ref OrgY);
                    Console.Write("An image misaligned by 50 pixels in X and 20 pixels in Y was loaded.\n\n");
                    Console.Write("The image is found to be shifted by {0:0.00} in X, and {1:0.00} in Y.\n", x - OrgX, y - OrgY);
                    Console.Write("Model match score is {0:0.0} percent.\n", Score);
                    Console.Write("Press <Enter> to end.\n\n");
                    Console.ReadKey();
                }
                else
                {
                    Console.Write("Error: Pattern not found properly.\n");
                    Console.Write("Press <Enter> to end.\n\n");
                    Console.ReadKey();
                }

                // Free result buffer and model.
                MIL.MpatFree(Result);
                MIL.MpatFree(Model);
            }
            else
            {
                Console.Write("Error: Automatic model definition failed.\n");
                Console.Write("Press <Enter> to end.\n\n");
                Console.ReadKey();
            }

            // Remove the drawing offset.
            MIL.MgraControl(MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, 0.0);
            MIL.MgraControl(MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, 0.0);

            // Free the graphic list.
            MIL.MgraFree(GraphicList);

            // Free child buffer and defaults.
            MIL.MbufFree(MilSubImage);
            MIL.MbufFree(MilImage);
        }
Example #3
0
        static void Main(string[] args)
        {
            MIL_ID MilApplication      = MIL.M_NULL;    // Application identifier.
            MIL_ID MilSystem           = MIL.M_NULL;    // System identifier.
            MIL_ID MilDisplay          = MIL.M_NULL;    // Display identifier.
            MIL_ID MilImage            = MIL.M_NULL;    // Image buffer identifier.
            MIL_ID MilGraphicContextId = MIL.M_NULL;    // Graphic context identifier

            // Allocate a default MIL application, system, display and image.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, ref MilImage);

            // Allocate a graphic context
            MIL.MgraAlloc(MilSystem, ref MilGraphicContextId);

            // Perform graphic operations in the display image.
            MIL.MgraColor(MilGraphicContextId, 0xF0);
            MIL.MgraFont(MilGraphicContextId, MIL.M_FONT_DEFAULT_LARGE);
            MIL.MgraText(MilGraphicContextId, MilImage, 160L, 20L, " Welcome to MIL !!! ");

            MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 12);
            MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME(MIL.M_FONT_DEFAULT_TTF));
            MIL.MgraText(MilGraphicContextId, MilImage, 40L, 80L, "English");

            MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_DISABLE);

            MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 16);
            MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME(MIL.M_FONT_DEFAULT_TTF + ":Bold"));
            MIL.MgraText(MilGraphicContextId, MilImage, 40L, 140L, "Français");

            MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 24);
            MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME(MIL.M_FONT_DEFAULT_TTF + ":Italic"));
            MIL.MgraText(MilGraphicContextId, MilImage, 40L, 220L, "Italiano");

            MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 30);
            MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME(MIL.M_FONT_DEFAULT_TTF + ":Bold:Italic"));
            MIL.MgraText(MilGraphicContextId, MilImage, 40L, 300L, "Deutsch");

            MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 36);
            MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME("Courier New"));
            MIL.MgraText(MilGraphicContextId, MilImage, 40L, 380L, "Español");

            if (MIL.M_MIL_USE_TTF_UNICODE == 1)
            {
                // Draw Greek, Japanese and Korean
                MIL.MgraFont(MilGraphicContextId, MIL.MIL_FONT_NAME(MIL.M_FONT_DEFAULT_TTF));

                MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 12);
                MIL.MgraText(MilGraphicContextId, MilImage, 400L, 80L, "ελληνιδ");

                MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 16);
                MIL.MgraText(MilGraphicContextId, MilImage, 400L, 140L, "日本語");

                MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 24);
                MIL.MgraText(MilGraphicContextId, MilImage, 400L, 220L, "한국어");

                // Draw Arabic and Hebrew
                MIL.MgraControl(MilGraphicContextId, MIL.M_TEXT_DIRECTION, MIL.M_RIGHT_TO_LEFT);
                MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 30);
                MIL.MgraText(MilGraphicContextId, MilImage, 400L, 320L, "עברית");

                MIL.MgraControl(MilGraphicContextId, MIL.M_FONT_SIZE, 36);
                MIL.MgraText(MilGraphicContextId, MilImage, 400L, 380L, "ﻋﺮﺑﻲ");
            }

            // Print a message.
            Console.WriteLine();
            Console.WriteLine("INTERNATIONAL TEXT ANNOTATION:");
            Console.WriteLine("------------------------------");
            Console.WriteLine();
            Console.WriteLine("This example demonstrates the support of TrueType fonts by MgraText.");
            Console.WriteLine();

            if (MIL.MappGetError(MIL.M_GLOBAL + MIL.M_SYNCHRONOUS, MIL.M_NULL) != MIL.M_NULL_ERROR)
            {
                Console.WriteLine("Note: Some Unicode fonts are not available");
                Console.WriteLine();
            }

            // Wait for a key press.
            Console.WriteLine("Press <Enter> to end.");
            Console.ReadKey();

            // Free Graphic Context
            MIL.MgraFree(MilGraphicContextId);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MilImage);
        }