Ejemplo n.º 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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Print example name.
            Console.WriteLine();
            Console.WriteLine("INTERACTIVE REGIONS AND SUBPIXEL ANNOTATIONS:");
            Console.WriteLine("---------------------------------------------");
            Console.WriteLine();
            Console.WriteLine("This program determines the number of blobs in a region");
            Console.WriteLine("defined interactively by the user. The extracted blob's");
            Console.WriteLine("features are drawn with subpixel accuracy in a zoomable");
            Console.WriteLine("display.");
            Console.WriteLine();

            // Run Interactivity Example.
            InteractivityExample(MilSystem, MilDisplay);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 2
0
        static int 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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Print module name.
            Console.Write("\nMEASUREMENT MODULE:\n");
            Console.Write("-------------------\n\n");

            if (RUN_SINGLE_MEASUREMENT_EXAMPLE == MIL.M_YES)
            {
                SingleMeasurementExample(MilSystem, MilDisplay);
            }

            if (RUN_MULTIPLE_MEASUREMENT_EXAMPLE == MIL.M_YES)
            {
                MultipleMeasurementExample(MilSystem, MilDisplay);
            }

            if (RUN_MULTIPLE_MEASUREMENT_EXAMPLE == MIL.M_YES)
            {
                FixturedMeasurementExample(MilSystem, MilDisplay);
            }

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

            return(0);
        }
Ejemplo n.º 3
0
        //*****************************************************************************
        // Main.
        //*****************************************************************************
        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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Print module name.
            Console.Write("\nMETROLOGY MODULE:\n");
            Console.Write("-------------------\n\n");

            if (RUN_SIMPLE_IMAGE_EXAMPLE == MIL.M_YES)
            {
                SimpleImageExample(MilSystem, MilDisplay);
            }

            if (RUN_COMPLETE_IMAGE_EXAMPLE == MIL.M_YES)
            {
                CompleteImageExample(MilSystem, MilDisplay);
            }

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
        static void Main(string[] args)
        {
            var    path       = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string MODEL_FILE = path + "/" + "constructionModel.mmf";
            string IMAGE_FILE = path + "/OrjinalImaj.jpg";

            MIL_ID MilApplication = MIL.M_NULL;
            MIL_ID MilSystem      = MIL.M_NULL;
            MIL_ID MilDisplay     = MIL.M_NULL;
            MIL_ID MilImage       = MIL.M_NULL;

            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);



            Console.Write("StripeMarker.\n");
            StripeMarker(MilSystem, MilDisplay, MilImage, MODEL_FILE, IMAGE_FILE);



            Console.Write("\n\nEdgeMarker.\n");
            EdgeMarker(MilSystem, MilDisplay, MilImage, MODEL_FILE, IMAGE_FILE);

            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 5
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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Print module name.
            Console.Write("CALIBRATION MODULE:\n");
            Console.Write("-------------------\n\n");

            if (RUN_LINEAR_CALIBRATION_EXAMPLE == MIL.M_YES)
            {
                LinearInterpolationCalibration(MilSystem, MilDisplay);
            }

            if (RUN_TSAI_CALIBRATION_EXAMPLE == MIL.M_YES)
            {
                TsaiCalibration(MilSystem, MilDisplay);
            }

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            //****************************************************************************
            // Main.
            //****************************************************************************

            MIL_ID MilApplication = MIL.M_NULL;     // Application identifier.
            MIL_ID MilSystem      = MIL.M_NULL;     // System identifier.
            MIL_ID MilDisplay     = MIL.M_NULL;     // Display identifier.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Run the color segmentation example.
            ColorSegmentationExample(MilSystem, MilDisplay);

            // Run the color matching example.
            ColorMatchingExample(MilSystem, MilDisplay);

            // Run the color projection example.
            ColorSeparationExample(MilSystem, MilDisplay);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 7
0
        // Main function.
        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 MilOverlayImage = MIL.M_NULL;                           // Overlay buffer identifier.
            MIL_ID HistResult      = MIL.M_NULL;                           // Histogram buffer identifier.

            MIL_INT[] HistValues      = new MIL_INT[HIST_NUM_INTENSITIES]; // Histogram values.
            double[]  XStart          = new double[HIST_NUM_INTENSITIES];
            double[]  YStart          = new double[HIST_NUM_INTENSITIES];
            double[]  XEnd            = new double[HIST_NUM_INTENSITIES];
            double[]  YEnd            = new double[HIST_NUM_INTENSITIES];
            double    AnnotationColor = MIL.M_COLOR_RED;

            // Allocate the default system and image buffer.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Restore source image into an automatically allocated image buffer.
            MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);

            // Display the image buffer and prepare for overlay annotations.
            MIL.MdispSelect(MilDisplay, MilImage);
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE);
            MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage);

            // Allocate a histogram result buffer.
            MIL.MimAllocResult(MilSystem, HIST_NUM_INTENSITIES, MIL.M_HIST_LIST, ref HistResult);

            // Calculate the histogram.
            MIL.MimHistogram(MilImage, HistResult);

            // Get the results.
            MIL.MimGetResult(HistResult, MIL.M_VALUE, HistValues);

            // Draw the histogram in the overlay.
            MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor);
            for (int i = 0; i < HIST_NUM_INTENSITIES; i++)
            {
                XStart[i] = i + HIST_X_POSITION + 1;
                YStart[i] = HIST_Y_POSITION;
                XEnd[i]   = i + HIST_X_POSITION + 1;
                YEnd[i]   = HIST_Y_POSITION - (HistValues[i] / HIST_SCALE_FACTOR);
            }
            MIL.MgraLines(MIL.M_DEFAULT, MilOverlayImage, HIST_NUM_INTENSITIES, XStart, YStart, XEnd, YEnd, MIL.M_DEFAULT);

            // Print a message.
            Console.Write("\nHISTOGRAM:\n");
            Console.Write("----------\n\n");
            Console.Write("The histogram of the image was calculated and drawn.\n");
            Console.Write("Press <Enter> to end.\n\n");
            Console.ReadKey();

            // Free all allocations.
            MIL.MimFree(HistResult);
            MIL.MbufFree(MilImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 8
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 MilPolarImage  = MIL.M_NULL;     // Destination buffer identifier.
            double SizeRadius     = 0.0;
            double SizeAngle      = 0.0;
            double CenterX        = 0.0;
            double CenterY        = 0.0;
            double Radius         = 0.0;
            int    OffsetX        = 0;
            int    OffsetY        = 0;
            int    SizeX          = 0;
            int    SizeY          = 0;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Load the source image and display it.
            MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);
            MIL.MdispSelect(MilDisplay, MilImage);

            // Calculate the parameters of the circle.
            GenerateCircle(POINT1_X, POINT1_Y, POINT2_X, POINT2_Y, POINT3_X, POINT3_Y, ref CenterX, ref CenterY, ref Radius);

            // Get the size of the destination buffer.
            MIL.MimPolarTransform(MilImage, MIL.M_NULL, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, ref SizeAngle, ref SizeRadius);

            // Allocate the destination buffer.
            OffsetX = (int)((MIL.MbufInquire(MilImage, MIL.M_SIZE_X, MIL.M_NULL) / 2) - (SizeAngle / 2));
            OffsetY = 20;
            SizeX   = (int)Math.Ceiling(SizeAngle);
            SizeY   = (int)Math.Ceiling(SizeRadius);
            MIL.MbufChild2d(MilImage, OffsetX, OffsetY, SizeX, SizeY, ref MilPolarImage);

            // Print a message.
            Console.Write("\nPOLAR TRANSFORMATION:\n");
            Console.Write("---------------------\n\n");
            Console.Write("A string will be unrolled using a polar-to-rectangular transformation.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Unroll the string.
            MIL.MimPolarTransform(MilImage, MilPolarImage, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, ref SizeAngle, ref SizeRadius);

            // Print a message on the Host screen.
            Console.Write("Press <Enter> to end.\n");
            Console.ReadKey();

            // Free buffers.
            MIL.MbufFree(MilPolarImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MilImage);
        }
Ejemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            // get a handle to the DigHookUserData object in the managed heap, we will use this
            // handle to get the object back in the callback function
            GCHandle UserHookDataHandle = GCHandle.Alloc(UserHookData);
            MIL_DIG_HOOK_FUNCTION_PTR UserHookFunctionDelegate = new MIL_DIG_HOOK_FUNCTION_PTR(ArchiveFunction);

            // Acquire the sequence. The processing hook function will
            // be called for each image grabbed to archive and display it.
            // If sequence is not saved to disk, stop after NbFrames.
            MIL.MdigProcess(MilDigitizer, MilGrabImages, NbFrames, SAVE_SEQUENCE_TO_DISK ? MIL.M_START : MIL.M_SEQUENCE, MIL.M_DEFAULT, UserHookFunctionDelegate, GCHandle.ToIntPtr(UserHookDataHandle));

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

            // Stop the sequence acquisition.
            MIL.MdigProcess(MilDigitizer, MilGrabImages, NbFrames, MIL.M_STOP, MIL.M_DEFAULT, UserHookFunctionDelegate, GCHandle.ToIntPtr(UserHookDataHandle));

            // Free the GCHandle when no longer used
            UserHookDataHandle.Free();

            // Read and print final statistics.
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_COUNT, ref FrameCount);
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, ref FrameRate);
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_MISSED, ref FrameMissed);

            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine("{0} frames archived ({1} missed), at {2:0.0} frames/sec ({3:0.0}ms/frame).", UserHookData.NbArchivedFrames, FrameMissed, FrameRate, 1000.0 / FrameRate);

            // Sequence file closing if required.
            if (SAVE_SEQUENCE_TO_DISK)
            {
                MIL.MbufExportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, FrameRate, MIL.M_CLOSE);
            }

            // Free all allocated buffers.
            MIL.MbufFree(MilImageDisp);
            for (n = 0; n < NbFrames; n++)
            {
                MIL.MbufFree(MilGrabImages[n]);
            }

            if (MilCompressedImage != MIL.M_NULL)
            {
                MIL.MbufFree(MilCompressedImage);
            }

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MIL.M_NULL);
        }
Ejemplo n.º 10
0
        //*****************************************************************************
        // Main.
        //*****************************************************************************
        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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Run fixtured bead example.
            FixturedBeadExample(MilSystem, MilDisplay);

            // Run predefined bead example.
            PredefinedBeadExample(MilSystem, MilDisplay);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 11
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.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Run single model example.
            SingleModelExample(MilSystem, MilDisplay);

            // Run multiple model example.
            MultipleModelExample(MilSystem, MilDisplay);

            // Free defaults
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            MIL_ID MilApplication = MIL.M_NULL;
            MIL_ID MilSystem      = MIL.M_NULL;
            MIL_ID MilDisplay     = MIL.M_NULL;

            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            //Metrology(MilSystem, MilDisplay);

            //FindModel(MilSystem, MilDisplay);
            //Metro(MilSystem, MilDisplay);

            CompleteImageExample(MilSystem, MilDisplay);

            //Console.ReadKey();

            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            //****************************************************************************
            // Main.
            //****************************************************************************
            MIL_ID MilApplication = MIL.M_NULL;     // Application identifier.
            MIL_ID MilSystem      = MIL.M_NULL;     // System identifier.
            MIL_ID MilDisplay     = MIL.M_NULL;     // Display identifier.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Run the depth correction example.
            DepthCorrectionExample(MilSystem, MilDisplay);

            // Run the calibrated camera example.
            CalibratedCameraExample(MilSystem, MilDisplay);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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 MilDigitizer   = MIL.M_NULL;         // Digitizer identifier.
            MIL_ID MilImage       = MIL.M_NULL;         // Image buffer identifier.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, ref MilImage);

            // Grab continuously.
            MIL.MdigGrabContinuous(MilDigitizer, MilImage);

            // When a key is pressed, halt.
            Console.Write("\nDIGITIZER ACQUISITION:\n");
            Console.Write("----------------------\n\n");
            Console.Write("Continuous image grab in progress.\n");
            Console.Write("Press <Enter> to stop.\n\n");
            Console.ReadKey();

            // Stop continuous grab.
            MIL.MdigHalt(MilDigitizer);

            // Pause to show the result.
            Console.Write("Continuous grab stopped.\n\n");
            Console.Write("Press <Enter> to do a single image grab.\n\n");
            Console.ReadKey();

            // Monoshot grab.
            MIL.MdigGrab(MilDigitizer, MilImage);

            // Pause to show the result.
            Console.Write("Displaying the grabbed image.\n");
            Console.Write("Press <Enter> to end.\n\n");
            Console.ReadKey();

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImage);
        }
Ejemplo n.º 16
0
        //****************************************************************************
        // Main.
        //****************************************************************************
        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 MilDigitizer    = MIL.M_NULL;  // Digitizer identifier.
            MIL_ID MilDisplayImage = MIL.M_NULL;  // Display image identifier.
            MIL_ID MilModelImage   = MIL.M_NULL;  // Model image identifier.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, ref MilDisplayImage);

            // Allocate a model image buffer.
            MIL.MbufAlloc2d(MilSystem, MIL.MbufInquire(MilDisplayImage, MIL.M_SIZE_X, MIL.M_NULL), MIL.MbufInquire(MilDisplayImage, MIL.M_SIZE_Y, MIL.M_NULL), 8, MIL.M_IMAGE + MIL.M_PROC, ref MilModelImage);

            Console.Write("\nMODEL TRACKING:\n");
            Console.Write("---------------\n\n");

            // Get the model image.
            GetModelImage(MilSystem, MilDisplay, MilDigitizer, MilDisplayImage, MilModelImage);

            if (RUN_PAT_TRACKING_EXAMPLE == MIL.M_YES)
            {
                // Finds the model using pattern matching.
                MpatTrackingExample(MilSystem, MilDisplay, MilDigitizer, MilDisplayImage, MilModelImage);
            }

            if (RUN_MOD_TRACKING_EXAMPLE == MIL.M_YES)
            {
                // Finds the model using geometric model finder.
                MmodTrackingExample(MilSystem, MilDisplay, MilDigitizer, MilDisplayImage, MilModelImage);
            }

            // Free allocated buffers.
            MIL.MbufFree(MilModelImage);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilDisplayImage);
        }
        static void Acquisition()
        {
            MIL_ID MilApplication = MIL.M_NULL;
            MIL_ID MilSystem      = MIL.M_NULL;
            MIL_ID MilDisplay     = MIL.M_NULL;
            MIL_ID MilDigitizer   = MIL.M_NULL;
            MIL_ID MilImage       = MIL.M_NULL;

            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, ref MilImage);

            MIL.MdispSelect(MilDisplay, MilImage);

            //if (MilDigitizer != MIL.M_NULL)
            //{
            //    MIL.MdigGrabContinuous(MilDigitizer, MilImage);
            //    //FindModel(MilSystem, MilDisplay, MilImage);
            //    //FindModel(MilSystem, MilDisplay, MilDigitizer, MilImage);
            FindModel(MilSystem, MilDisplay, MilDigitizer, MilImage);
            //    Console.ReadKey();
            //    MIL.MdigHalt(MilDigitizer);
            //}

            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImage);
        }
Ejemplo n.º 18
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.

            Console.Write("\nGRAYSCALE PATTERN MATCHING:\n");
            Console.Write("---------------------------\n\n");

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Run the search at 0 degree example.
            SearchModelExample(MilSystem, MilDisplay);

            // Run the search over 360 degrees example.
            SearchRotatedModelExample(MilSystem, MilDisplay);

            // Run the automatic model allocation example.
            AutoAllocationModelExample(MilSystem, MilDisplay);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 19
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 MilDisplayImage = MIL.M_NULL; // Image buffer identifier.
            MIL_ID MilImage        = MIL.M_NULL; // Image buffer identifier.
            MIL_ID MilPosYImage    = MIL.M_NULL; // Image buffer identifier.
            MIL_ID MilValImage     = MIL.M_NULL; // Image buffer identifier.
            MIL_ID MilExtreme      = MIL.M_NULL; // Result buffer identifier.

            double  FrameRate        = 0.0;
            int     n                = 0;
            double  PreviousTime     = 0.0;
            double  StartTime        = 0.0;
            double  EndTime          = 0.0;
            double  TotalProcessTime = 0.0;
            double  WaitTime         = 0.0;
            MIL_INT SizeX            = 0;
            MIL_INT SizeY            = 0;
            MIL_INT NumberOfImages   = 0;

            MIL_INT[] ExtremePosY = new MIL_INT[2];
            ExtremePosY[0] = 0;
            ExtremePosY[1] = 0;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Inquire characteristics of the input sequence.
            MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_SIZE_X, ref SizeX);
            MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_SIZE_Y, ref SizeY);
            MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_NUMBER_OF_IMAGES, ref NumberOfImages);
            MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_FRAME_RATE, ref FrameRate);

            // Allocate buffers to hold images.
            MIL.MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ref MilImage);
            MIL.MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_DISP, ref MilDisplayImage);
            MIL.MbufAlloc2d(MilSystem, SizeX, NumberOfImages, 16 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ref MilPosYImage);
            MIL.MbufAlloc2d(MilSystem, SizeX, NumberOfImages, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ref MilValImage);

            // Select display.
            MIL.MdispSelect(MilDisplay, MilDisplayImage);

            // Print a message.
            Console.Write("\nEXTRACTING 3D IMAGE FROM A LASER LINE:\n");
            Console.Write("--------------------------------------\n\n");
            Console.Write("The position of a laser line is being extracted from an image\n");
            Console.Write("to generate a depth image.\n\n");

            // Open the sequence file for reading.
            MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_OPEN);

            // The function must be called once before the timing loop for more accurate
            // time (dll load, ...).
            MIL.MimLocatePeak1d(MilImage, MilPosYImage, MilValImage, 0, MAX_LINE_WIDTH, MIN_INTENSITY, MIL.M_1D_COLUMNS + MIL.M_FIXED_POINT + NB_FIXED_POINT, MIL.M_DEFAULT);

            // Read and process all images in the input sequence.
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref PreviousTime);
            TotalProcessTime = 0.0;

            for (n = 0; n < NumberOfImages; n++)
            {
                // Read image from sequence.
                MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_LOAD, MIL.M_NULL, ref MilImage, MIL.M_DEFAULT, 1, MIL.M_READ);

                // Display the image.
                MIL.MbufCopy(MilImage, MilDisplayImage);

                // Locate the peak in each column of the image.
                MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref StartTime);
                MIL.MimLocatePeak1d(MilImage, MilPosYImage, MilValImage, n, MAX_LINE_WIDTH, MIN_INTENSITY, MIL.M_1D_COLUMNS + MIL.M_FIXED_POINT + NB_FIXED_POINT, MIL.M_DEFAULT);
                MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref EndTime);
                TotalProcessTime += EndTime - StartTime;

                // Wait to have a proper frame rate.
                WaitTime = (1.0 / FrameRate) - (EndTime - PreviousTime);
                if (WaitTime > 0)
                {
                    MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_WAIT, ref WaitTime);
                }
                MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref PreviousTime);
            }

            // Close the sequence file.
            MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_CLOSE);

            Console.Write("{0} images processed in {1,7:0.00} s ({2,7:0.00} ms/image).\n", NumberOfImages, TotalProcessTime, TotalProcessTime / (double)NumberOfImages * 1000.0);


            // Pause to show the result.
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            Console.Write("The reconstructed images are being displayed.\n");

            // Draw extracted peak position in each column of each image.
            for (n = 0; n < NumberOfImages; n++)
            {
                MIL.MbufClear(MilImage, 0);
                MIL.MimDraw(MIL.M_DEFAULT, MilPosYImage, MilValImage, MilImage, MIL.M_DRAW_PEAKS + MIL.M_1D_COLUMNS + MIL.M_LINES, (double)n, 1, MIL.M_FIXED_POINT + NB_FIXED_POINT);

                // Display the result image.
                MIL.MbufCopy(MilImage, MilDisplayImage);
            }


            // Pause to show the result.
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();


            // Try to allocate D3D display
            IntPtr DispHandle;

            DispHandle = MdepthD3DAlloc(MilPosYImage, MilValImage, D3D_DISPLAY_SIZE_X, D3D_DISPLAY_SIZE_Y, D3D_MESH_SCALING_X, D3D_MESH_SCALING_Y, D3D_MESH_SCALING_Z, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, IntPtr.Zero);

            if (DispHandle != IntPtr.Zero)
            {
                Console.Write("The depth buffer is displayed using D3D.\n");

                // Hide Mil Display
                MIL.MdispControl(MilDisplay, MIL.M_WINDOW_SHOW, MIL.M_DISABLE);

                MdispD3DShow(DispHandle);
                MdispD3DPrintHelp(DispHandle);

                // Pause to show the result.
                Console.Write("Press <Enter> to end.\n");
                Console.ReadKey();

                MdispD3DHide(DispHandle);
                MdispD3DFree(DispHandle);
            }
            else
            {
                Console.Write("The depth buffer is displayed using MIL.\n");

                // Find the reMIL.Mapping for result buffers.
                MIL.MimAllocResult(MilSystem, MIL.M_DEFAULT, MIL.M_STAT_LIST, ref MilExtreme);

                MIL.MimStat(MilPosYImage, MilExtreme, MIL.M_MIN + MIL.M_MAX, MIL.M_NOT_EQUAL, 0xFFFF, MIL.M_NULL);
                MIL.MimGetResult(MilExtreme, MIL.M_MIN + MIL.M_TYPE_MIL_INT, ref ExtremePosY[0]);
                MIL.MimGetResult(MilExtreme, MIL.M_MAX + MIL.M_TYPE_MIL_INT, ref ExtremePosY[1]);

                MIL.MimFree(MilExtreme);

                // Free the display and reallocate a new one of the proper dimension for results.
                MIL.MbufFree(MilDisplayImage);
                MIL.MbufAlloc2d(MilSystem,
                                (MIL_INT)((double)SizeX * (D3D_MESH_SCALING_X > 0 ? D3D_MESH_SCALING_X : -D3D_MESH_SCALING_X)),
                                (MIL_INT)((double)NumberOfImages * D3D_MESH_SCALING_Y),
                                8 + MIL.M_UNSIGNED,
                                MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP,
                                ref MilDisplayImage);
                MIL.MdispSelect(MilDisplay, MilDisplayImage);

                // Display the height buffer.
                MIL.MimClip(MilPosYImage, MilPosYImage, MIL.M_GREATER, (double)ExtremePosY[1], MIL.M_NULL, (double)ExtremePosY[1], MIL.M_NULL);
                MIL.MimArith(MilPosYImage, (double)ExtremePosY[0], MilPosYImage, MIL.M_SUB_CONST);
                MIL.MimArith(MilPosYImage, ((ExtremePosY[1] - ExtremePosY[0]) / 255.0) + 1, MilPosYImage, MIL.M_DIV_CONST);
                MIL.MimResize(MilPosYImage, MilDisplayImage, MIL.M_FILL_DESTINATION, MIL.M_FILL_DESTINATION, MIL.M_BILINEAR);

                // Pause to show the result.
                Console.Write("Press <Enter> to end.\n");
                Console.ReadKey();
            }

            // Free all allocations.
            MIL.MbufFree(MilImage);
            MIL.MbufFree(MilDisplayImage);
            MIL.MbufFree(MilPosYImage);
            MIL.MbufFree(MilValImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 20
0
        // Main function.
        static void Main(string[] args)
        {
            MIL_ID MilApplication = MIL.M_NULL;
            MIL_ID MilSystem      = MIL.M_NULL;
            MIL_ID MilDigitizer   = MIL.M_NULL;
            MIL_ID MilDisplay     = MIL.M_NULL;

            MIL_ID[]       MilImage     = new MIL_ID[2];
            MIL_ID         MilImageDisp = MIL.M_NULL;
            MIL_ID         Default      = MIL.M_DEFAULT;
            int            NbProc       = 0;
            int            n            = 0;
            double         Time         = 0.0;
            StringBuilder  Text         = new StringBuilder("0", STRING_LENGTH_MAX);
            UserDataObject userObject   = new UserDataObject();

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, ref MilImageDisp);

            // Allocate 2 grab buffers.
            for (n = 0; n < 2; n++)
            {
                MIL.MbufAlloc2d(MilSystem,
                                MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL),
                                MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL),
                                8 + MIL.M_UNSIGNED,
                                MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC,
                                ref MilImage[n]);
            }

            // Hook a function to the start of each frame to print the current frame index.
            userObject.NbGrabStart = 0;
            GCHandle userObjectHandle = GCHandle.Alloc(userObject);

            MIL_DIG_HOOK_FUNCTION_PTR grabStartDelegate = new MIL_DIG_HOOK_FUNCTION_PTR(GrabStart);

            MIL.MdigHookFunction(MilDigitizer, MIL.M_GRAB_START, grabStartDelegate, GCHandle.ToIntPtr(userObjectHandle));

            // Print a message.
            Console.WriteLine();
            Console.WriteLine("DOUBLE BUFFERING ACQUISITION AND PROCESSING:");
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine();
            Console.WriteLine("Press <Enter> to stop.");
            Console.WriteLine();

            // Put the digitizer in asynchronous mode to be able to process while grabbing.
            MIL.MdigControl(MilDigitizer, MIL.M_GRAB_MODE, MIL.M_ASYNCHRONOUS);

            // Grab the first buffer.
            MIL.MdigGrab(MilDigitizer, MilImage[0]);

            // Process one buffer while grabbing the other.
            n = 0;
            do
            {
                // Grab the other buffer while processing the previous one.
                MIL.MdigGrab(MilDigitizer, MilImage[1 - n]);

                // Synchronize and start the timer.
                if (NbProc == 0)
                {
                    MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, MIL.M_NULL);
                }

                // Write the frame counter.
                MIL.MgraText(Default, MilImage[n], 32, 32, string.Format("{0}", NbProc + 1));

                // Process the first buffer already grabbed.
                MIL.MimArith(MilImage[n], MIL.M_NULL, MilImageDisp, MIL.M_NOT);

                // Count processed buffers.
                NbProc++;

                // Toggle grab buffers.
                n = 1 - n;
            } while (!Console.KeyAvailable);

            // Wait until the end of the last grab and stop the timer.
            MIL.MdigGrabWait(MilDigitizer, MIL.M_GRAB_END);
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref Time);
            Console.ReadKey();

            // Print statistics.
            Console.WriteLine("{0} frames grabbed, at a frame rate of {1:0.00} frames/sec ({2:0.00} ms/frame).", NbProc, NbProc / Time, 1000.0 * Time / NbProc);
            Console.WriteLine("Press <Enter> to end.");
            Console.WriteLine();
            Console.ReadKey();

            // Unhook the function at the start of each frame.
            MIL.MdigHookFunction(MilDigitizer, MIL.M_GRAB_START + MIL.M_UNHOOK, grabStartDelegate, GCHandle.ToIntPtr(userObjectHandle));

            // Free GCHandle to allow the garbage collector to reclaim the object.
            userObjectHandle.Free();

            // Free allocations.
            for (n = 0; n < 2; n++)
            {
                MIL.MbufFree(MilImage[n]);
            }

            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp);
        }
Ejemplo n.º 21
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        MilOverlayImage    = MIL.M_NULL;                       // Overlay image.
            MIL_ID        MilStrContext      = MIL.M_NULL;                       // String context identifier.
            MIL_ID        MilStrResult       = MIL.M_NULL;                       // String result buffer identifier.
            MIL_INT       NumberOfStringRead = 0;                                // Total number of strings to read.
            double        Score        = 0.0;                                    // String score.
            StringBuilder StringResult = new StringBuilder(STRING_MAX_SIZE + 1); // String of characters read.
            double        Time         = 0.0;                                    // Time variable.

            // Print module name.
            Console.Write("\nSTRING READER MODULE:\n");
            Console.Write("---------------------\n\n");

            // Allocate defaults
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Restore the font definition image
            MIL.MbufRestore(IMAGE_FILE_DEFINITION, MilSystem, ref MilImage);

            // Display the image and prepare for overlay annotations.
            MIL.MdispSelect(MilDisplay, MilImage);
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE);
            MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage);

            // Allocate a new empty String Reader context.
            MIL.MstrAlloc(MilSystem, MIL.M_FONT_BASED, MIL.M_DEFAULT, ref MilStrContext);

            // Allocate a new empty String Reader result buffer.
            MIL.MstrAllocResult(MilSystem, MIL.M_DEFAULT, ref MilStrResult);

            MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_ENCODING, MIL.M_UNICODE);

            // Add a new empty user defined font to the context.
            MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_FONT_ADD, MIL.M_USER_DEFINED);

            // Add user defined characters from the license plate mosaic image.
            MIL.MstrEditFont(MilStrContext, MIL.M_FONT_INDEX(0), MIL.M_CHAR_ADD, MIL.M_USER_DEFINED + MIL.M_FOREGROUND_BLACK, MilImage, TEXT_DEFINITION);

            // Draw all the characters in the font in the overlay image.
            MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN);
            MIL.MstrDraw(MIL.M_DEFAULT, MilStrContext, MilOverlayImage, MIL.M_DRAW_CHAR, MIL.M_FONT_INDEX(0), MIL.M_ORIGINAL);

            // Normalize the characters of the font to an appropriate size.
            MIL.MstrEditFont(MilStrContext, MIL.M_FONT_INDEX(0), MIL.M_CHAR_NORMALIZE, MIL.M_SIZE_Y, NORMALIZATION_SIZE_Y);

            // Add 2 new empty strings models to the context for the 2 valid types of
            // plates (3 letters followed by 3 numbers or 3 numbers followed by 3 letters)
            // Note that the read time increases with the number of strings in the context.
            MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_ADD, MIL.M_USER_DEFINED);
            MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_ADD, MIL.M_USER_DEFINED);

            // Set number of strings to read.
            MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_NUMBER, 1);

            // Set number of expected characters for all string models to 6 characters.
            MIL.MstrControl(MilStrContext, MIL.M_STRING_INDEX(MIL.M_ALL), MIL.M_STRING_SIZE_MIN, 6);
            MIL.MstrControl(MilStrContext, MIL.M_STRING_INDEX(MIL.M_ALL), MIL.M_STRING_SIZE_MAX, 6);

            // Set default constraint to uppercase letter for all string models
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), MIL.M_DEFAULT, MIL.M_LETTER + MIL.M_UPPERCASE, IntPtr.Zero);
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), MIL.M_DEFAULT, MIL.M_LETTER + MIL.M_UPPERCASE, IntPtr.Zero);

            // Set constraint of 3 last characters to digit for the first string model
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 3, MIL.M_DIGIT, IntPtr.Zero);
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 4, MIL.M_DIGIT, IntPtr.Zero);
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 5, MIL.M_DIGIT, IntPtr.Zero);

            // Set constraint of 3 first characters to digit for the second string model
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 0, MIL.M_DIGIT, IntPtr.Zero);
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 1, MIL.M_DIGIT, IntPtr.Zero);
            MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 2, MIL.M_DIGIT, IntPtr.Zero);

            // Pause to show the font definition.
            Console.Write("This program has defined a font with this Quebec plates mosaic image.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Clear the display overlay.
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT);

            // Load image to read into image buffer.
            MIL.MbufLoad(IMAGE_FILE_TO_READ, MilImage);

            // Preprocess the String Reader context.
            MIL.MstrPreprocess(MilStrContext, MIL.M_DEFAULT);

            // Dummy first call for bench measure purpose only (bench stabilization, cache effect, etc...). This first call is NOT required by the application.
            MIL.MstrRead(MilStrContext, MilImage, MilStrResult);

            // Reset the timer.
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, MIL.M_NULL);

            // Perform the read operation on the specified target image.
            MIL.MstrRead(MilStrContext, MilImage, MilStrResult);

            // Read the time.
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref Time);

            // Get number of strings read and show the result.
            MIL.MstrGetResult(MilStrResult, MIL.M_GENERAL, MIL.M_STRING_NUMBER + MIL.M_TYPE_MIL_INT, ref NumberOfStringRead);
            if (NumberOfStringRead >= 1)
            {
                Console.Write("The license plate was read successfully ({0:#.##} ms)\n\n", Time * 1000);

                // Draw read result.
                MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_BLUE);
                MIL.MstrDraw(MIL.M_DEFAULT, MilStrResult, MilOverlayImage, MIL.M_DRAW_STRING, MIL.M_ALL, MIL.M_DEFAULT);
                MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN);
                MIL.MstrDraw(MIL.M_DEFAULT, MilStrResult, MilOverlayImage, MIL.M_DRAW_STRING_BOX, MIL.M_ALL, MIL.M_DEFAULT);

                // Print the read result.
                Console.Write(" String                   Score\n");
                Console.Write(" -----------------------------------\n");
                MIL.MstrGetResult(MilStrResult, 0, MIL.M_STRING + MIL.M_TYPE_TEXT_CHAR, StringResult);
                MIL.MstrGetResult(MilStrResult, 0, MIL.M_STRING_SCORE, ref Score);
                Console.Write(" {0}                  {1:0.0}\n", StringResult.ToString(), Score);
            }
            else
            {
                Console.Write("Error: Plate was not read.\n");
            }

            // Pause to show results.
            Console.Write("\nPress <Enter> to end.\n\n");
            Console.ReadKey();

            // Free all allocations.
            MIL.MstrFree(MilStrContext);
            MIL.MstrFree(MilStrResult);
            MIL.MbufFree(MilImage);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 22
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 MilOverlayImage  = MIL.M_NULL;   // Overlay image buffer identifier.
            MIL_ID MilSubImage00    = MIL.M_NULL;   // Child buffer identifier.
            MIL_ID MilSubImage01    = MIL.M_NULL;   // Child buffer identifier.
            MIL_ID MilSubImage10    = MIL.M_NULL;   // Child buffer identifier.
            MIL_ID MilSubImage11    = MIL.M_NULL;   // Child buffer identifier.
            MIL_ID MilTransformReal = MIL.M_NULL;   // Real part of the transformed image.
            MIL_ID MilTransformIm   = MIL.M_NULL;   // Imaginary part of the transformed image.

            float[] ZeroVal = new float[1];
            ZeroVal[0] = 0.0F;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Allocate a display buffer and clear it.
            MIL.MbufAlloc2d(MilSystem, IMAGE_WIDTH * 2, IMAGE_HEIGHT * 2, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref MilImage);
            MIL.MbufClear(MilImage, 0L);

            // Display the image buffer and prepare for overlay annotations.
            MIL.MdispSelect(MilDisplay, MilImage);
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE);
            MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage);

            // Allocate child buffers in the 4 quadrants of the display image.
            MIL.MbufChild2d(MilImage, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, ref MilSubImage00);
            MIL.MbufChild2d(MilImage, IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, ref MilSubImage01);
            MIL.MbufChild2d(MilImage, 0, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, ref MilSubImage10);
            MIL.MbufChild2d(MilImage, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, ref MilSubImage11);

            // Allocate processing buffers.
            MIL.MbufAlloc2d(MilSystem, IMAGE_WIDTH, IMAGE_HEIGHT, 32 + MIL.M_FLOAT, MIL.M_IMAGE + MIL.M_PROC, ref MilTransformReal);
            MIL.MbufAlloc2d(MilSystem, IMAGE_WIDTH, IMAGE_HEIGHT, 32 + MIL.M_FLOAT, MIL.M_IMAGE + MIL.M_PROC, ref MilTransformIm);

            // Load a noisy image.
            MIL.MbufLoad(NOISY_IMAGE, MilSubImage00);

            // Print a message on the screen.
            Console.Write("\nFFT:\n");
            Console.Write("----\n\n");
            Console.Write("The frequency spectrum of a noisy image will be computed to remove the periodic noise.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // The image is Fourier transformed to obtain the magnitude of the
            // spectrum. This result will be used to design the filter.
            MIL.MimTransform(MilSubImage00, MIL.M_NULL, MilTransformReal, MilTransformIm, MIL.M_FFT, MIL.M_FORWARD + MIL.M_CENTER + MIL.M_MAGNITUDE + MIL.M_LOG_SCALE);
            MIL.MbufCopy(MilTransformReal, MilSubImage10);

            // Draw circles in the overlay around the points of interest.
            MIL.MbufCopy(MilTransformReal, MilSubImage11);
            MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_YELLOW);
            MIL.MgraArc(MIL.M_DEFAULT, MilOverlayImage, X_NEGATIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION + IMAGE_HEIGHT, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
            MIL.MgraArc(MIL.M_DEFAULT, MilOverlayImage, X_POSITIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION + IMAGE_HEIGHT, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
            MIL.MgraArc(MIL.M_DEFAULT, MilOverlayImage, X_NEGATIVE_FREQUENCY_POSITION + IMAGE_WIDTH, Y_FREQUENCY_POSITION + IMAGE_HEIGHT, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
            MIL.MgraArc(MIL.M_DEFAULT, MilOverlayImage, X_POSITIVE_FREQUENCY_POSITION + IMAGE_WIDTH, Y_FREQUENCY_POSITION + IMAGE_HEIGHT, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);

            // Put zero in the spectrum where the noise is located.
            MIL.MbufPut2d(MilSubImage11, X_NEGATIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);
            MIL.MbufPut2d(MilSubImage11, X_POSITIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);

            // Compute the Fast Fourier Transform of the image.
            MIL.MimTransform(MilSubImage00, MIL.M_NULL, MilTransformReal, MilTransformIm, MIL.M_FFT, MIL.M_FORWARD + MIL.M_CENTER);

            // Filter the image in the frequency domain.
            MIL.MbufPut2d(MilTransformReal, X_NEGATIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);
            MIL.MbufPut2d(MilTransformReal, X_POSITIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);
            MIL.MbufPut2d(MilTransformIm, X_NEGATIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);
            MIL.MbufPut2d(MilTransformIm, X_POSITIVE_FREQUENCY_POSITION, Y_FREQUENCY_POSITION, 1, 1, ZeroVal);

            // Recover the image in the spatial domain.
            MIL.MimTransform(MilTransformReal, MilTransformIm, MilSubImage01, MIL.M_NULL, MIL.M_FFT, MIL.M_REVERSE + MIL.M_CENTER + MIL.M_SATURATION);

            // Print a message.
            Console.Write("The frequency components of the noise are located in the center of the circles.\n");
            Console.Write("The noise was removed by setting these frequency components to zero.\n");
            Console.Write("Press <Enter> to end.\n\n");
            Console.ReadKey();

            // Free buffers.
            MIL.MbufFree(MilSubImage00);
            MIL.MbufFree(MilSubImage01);
            MIL.MbufFree(MilSubImage10);
            MIL.MbufFree(MilSubImage11);
            MIL.MbufFree(MilImage);
            MIL.MbufFree(MilTransformReal);
            MIL.MbufFree(MilTransformIm);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 23
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  MilSubImage     = MIL.M_NULL;                        // Sub-image buffer identifier.
            MIL_ID  MilFontSubImage = MIL.M_NULL;                        // Font display sub image.
            MIL_ID  MilOverlayImage = MIL.M_NULL;                        // Overlay image.
            MIL_ID  OcrFont         = MIL.M_NULL;                        // OCR font identifier.
            MIL_ID  OcrResult       = MIL.M_NULL;                        // OCR result buffer identifier.
            double  Score           = 0;                                 // Reading score.
            MIL_INT SizeX           = 0;                                 // Source image size x.
            MIL_INT SizeY           = 0;                                 // Source image size y.
            MIL_INT Type            = 0;                                 // Source image type.

            StringBuilder ReadString = new StringBuilder(STRING_LENGTH); // Characters to read.

            Console.Write("\nOCR MODULE (SEMI font reading):\n");
            Console.Write("-------------------------------\n\n");

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Load and display the source image into a new image buffer.
            MIL.MbufAlloc2d(MilSystem,
                            MIL.MbufDiskInquire(CHAR_IMAGE_FILE, MIL.M_SIZE_X, ref SizeX),
                            MIL.MbufDiskInquire(CHAR_IMAGE_FILE, MIL.M_SIZE_Y, ref SizeY) * 3 / 2,
                            MIL.MbufDiskInquire(CHAR_IMAGE_FILE, MIL.M_TYPE, ref Type),
                            MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP,
                            ref MilImage);
            MIL.MbufClear(MilImage, 0);
            MIL.MbufLoad(CHAR_IMAGE_FILE, MilImage);
            MIL.MdispSelect(MilDisplay, MilImage);

            // Restrict the region of the image where to read the string.
            MIL.MbufChild2d(MilImage, READ_REGION_POS_X, READ_REGION_POS_Y,
                            READ_REGION_WIDTH, READ_REGION_HEIGHT, ref MilSubImage);

            // Define the bottom of the image as the region where to copy the font representation.
            MIL.MbufChild2d(MilImage, 50, SizeY + 10, SizeX - 100, (SizeY / 3) - 10, ref MilFontSubImage);


            // Restore the OCR character font from disk.
            MIL.MocrRestoreFont(FONT_FILE_IN, MIL.M_RESTORE, MilSystem, ref OcrFont);

            /* Show the font representation. */
            MIL.MocrCopyFont(MilFontSubImage, OcrFont, MIL.M_COPY_FROM_FONT + MIL.M_ALL_CHAR, "");

            // Pause to show the original image.
            Console.Write("The SEMI string at the top will be read using the font displayed at the bottom.\n\n");
            Console.Write("Calibrating SEMI font...\n\n");

            // Calibrate the OCR font.
            MIL.MocrCalibrateFont(MilSubImage, OcrFont, STRING_CALIBRATION,
                                  CHAR_SIZE_X_MIN, CHAR_SIZE_X_MAX, CHAR_SIZE_X_STEP,
                                  CHAR_SIZE_Y_MIN, CHAR_SIZE_Y_MAX, CHAR_SIZE_Y_STEP,
                                  MIL.M_DEFAULT);

            // Set the user-specific character constraints for each string position.
            MIL.MocrSetConstraint(OcrFont, 0, MIL.M_LETTER);              // A to Z only
            MIL.MocrSetConstraint(OcrFont, 1, MIL.M_DIGIT, "9");          // 9      only
            MIL.MocrSetConstraint(OcrFont, 2, MIL.M_DIGIT);               // 0 to 9 only
            MIL.MocrSetConstraint(OcrFont, 3, MIL.M_DIGIT);               // 0 to 9 only
            MIL.MocrSetConstraint(OcrFont, 4, MIL.M_DIGIT);               // 0 to 9 only
            MIL.MocrSetConstraint(OcrFont, 5, MIL.M_DIGIT);               // 0 to 9 only
            MIL.MocrSetConstraint(OcrFont, 6, MIL.M_DIGIT);               // 0 to 9 only
            MIL.MocrSetConstraint(OcrFont, 7, MIL.M_DEFAULT, "-");        // -      only
            MIL.MocrSetConstraint(OcrFont, 8, MIL.M_LETTER, "M");         // M      only
            MIL.MocrSetConstraint(OcrFont, 9, MIL.M_LETTER, "X");         // X      only
            MIL.MocrSetConstraint(OcrFont, 10, MIL.M_LETTER, "ABCDEFGH"); // SEMI checksum
            MIL.MocrSetConstraint(OcrFont, 11, MIL.M_DIGIT, "01234567");  // SEMI checksum

            // Pause before the read operation.
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Allocate an OCR result buffer.
            MIL.MocrAllocResult(MilSystem, MIL.M_DEFAULT, ref OcrResult);

            // Read the string.
            MIL.MocrReadString(MilSubImage, OcrFont, OcrResult);

            // Get the string and its reading score.
            MIL.MocrGetResult(OcrResult, MIL.M_STRING, ReadString);
            MIL.MocrGetResult(OcrResult, MIL.M_STRING_SCORE, ref Score);

            // Print the result.
            Console.Write("\nThe string read is: \"{0}\" (score: {1:P1}).\n\n", ReadString.ToString(), Score / 100);

            // Draw the string in the overlay under the reading region.
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE);
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT);
            MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage);
            MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_LARGE);
            MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_YELLOW);
            MIL.MgraText(MIL.M_DEFAULT, MilOverlayImage,
                         READ_REGION_POS_X + (READ_REGION_WIDTH / 4),
                         READ_REGION_POS_Y + READ_REGION_HEIGHT + 50,
                         ReadString.ToString());

            // Save the calibrated font if the reading score was sufficiently high.
            if (Score > READ_SCORE_MIN)
            {
                MIL.MocrSaveFont(FONT_FILE_OUT, MIL.M_SAVE, OcrFont);
                Console.Write("Read successful, calibrated OCR font was saved to disk.\n");
            }
            else
            {
                Console.Write("Error: Read score too low, calibrated OCR font not saved.\n");
            }
            Console.Write("Press <Enter> to end.\n\n\n");
            Console.ReadKey();

            // Clear the overlay.
            MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT);

            // Free all allocations.
            MIL.MocrFree(OcrFont);
            MIL.MocrFree(OcrResult);
            MIL.MbufFree(MilSubImage);
            MIL.MbufFree(MilFontSubImage);
            MIL.MbufFree(MilImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 24
0
        // Main function.
        // --------------
        static void Main(string[] args)
        {
            MIL_ID MilApplication       = MIL.M_NULL;
            MIL_ID MilRemoteApplication = MIL.M_NULL;   // Remote Application identifier if running on a remote computer
            MIL_ID MilSystem            = MIL.M_NULL;
            MIL_ID MilDigitizer         = MIL.M_NULL;
            MIL_ID MilDisplay           = MIL.M_NULL;
            MIL_ID MilImageDisp         = MIL.M_NULL;

            MIL_ID[]       MilGrabImages      = new MIL_ID[NB_GRAB_IMAGE_MAX];
            MIL_ID         MilCompressedImage = MIL.M_NULL;
            ConsoleKeyInfo Selection          = new ConsoleKeyInfo('1', ConsoleKey.D1, false, false, false);

            int            NbFrames          = 0;
            int            n                 = 0;
            int            NbFramesReplayed  = 0;
            double         FrameRate         = 0;
            double         TimeWait          = 0;
            double         TotalReplay       = 0;
            double         GrabScale         = GRAB_SCALE;
            HookDataObject UserHookData      = new HookDataObject();
            MIL_INT        LicenseModules    = 0;
            MIL_INT        FrameCount        = 0;
            MIL_INT        FrameMissed       = 0;
            MIL_INT        CompressAttribute = 0;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, MIL.M_NULL);

            // Allocate an image and display it.
            MIL.MbufAllocColor(MilSystem,
                               MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, MIL.M_NULL),
                               (MIL_INT)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X) * GrabScale),
                               (MIL_INT)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y) * GrabScale),
                               8 + MIL.M_UNSIGNED,
                               MIL.M_IMAGE + MIL.M_GRAB + MIL.M_DISP,
                               ref MilImageDisp);

            MIL.MbufClear(MilImageDisp, 0x0);
            MIL.MdispSelect(MilDisplay, MilImageDisp);

            // Grab continuously on display at the specified scale.
            MIL.MdigControl(MilDigitizer, MIL.M_GRAB_SCALE, GrabScale);
            MIL.MdigGrabContinuous(MilDigitizer, MilImageDisp);

            // Print a message
            Console.WriteLine();
            Console.WriteLine("SEQUENCE ACQUISITION:");
            Console.WriteLine("--------------------");
            Console.WriteLine();

            // Inquire MIL licenses.
            MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, ref MilRemoteApplication);
            MIL.MappInquire(MilRemoteApplication, MIL.M_LICENSE_MODULES, ref LicenseModules);

            // If sequence is saved to disk, select between grabbing an
            // uncompressed, JPEG or JPEG2000 sequence.
            if (SAVE_SEQUENCE_TO_DISK && ((LicenseModules & (MIL.M_LICENSE_JPEGSTD | MIL.M_LICENSE_JPEG2000)) != 0))
            {
                Console.WriteLine("Choose the sequence format:");
                Console.WriteLine("1) Uncompressed images.");
                if ((LicenseModules & MIL.M_LICENSE_JPEGSTD) != 0)
                {
                    Console.WriteLine("2) Compressed images with a lossy JPEG algorithm.");
                }
                if ((LicenseModules & MIL.M_LICENSE_JPEG2000) != 0)
                {
                    Console.WriteLine("3) Compressed images with a lossy JPEG 2000 algorithm.");
                }
                Selection = Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Press <Enter> to record images.");
                Console.ReadKey();
            }


            // Set the buffer attribute.
            switch (Selection.Key)
            {
            case ConsoleKey.NumPad1:
            case ConsoleKey.D1:
            case ConsoleKey.Enter:
                Console.WriteLine();
                Console.WriteLine("Recording uncompressed images...");
                Console.WriteLine();
                CompressAttribute = MIL.M_NULL;
                break;

            case ConsoleKey.NumPad2:
            case ConsoleKey.D2:
                Console.WriteLine();
                Console.WriteLine("Recording JPEG images...");
                Console.WriteLine();
                CompressAttribute = MIL.M_COMPRESS + MIL.M_JPEG_LOSSY;
                break;

            case ConsoleKey.NumPad3:
            case ConsoleKey.D3:
                Console.WriteLine();
                Console.WriteLine("Recording JPEG 2000 images...");
                Console.WriteLine();
                CompressAttribute = MIL.M_COMPRESS + MIL.M_JPEG2000_LOSSY;
                break;

            default:
                Console.WriteLine();
                Console.WriteLine("Invalid selection !.");
                Console.WriteLine();
                Console.WriteLine("Using uncompressed images.");
                Console.WriteLine();
                CompressAttribute = MIL.M_NULL;
                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                break;
            }

            // Allocate a compressed buffer if required.
            if (CompressAttribute != MIL.M_NULL)
            {
                MIL.MbufAllocColor(MilSystem,
                                   MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, MIL.M_NULL),
                                   (int)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL) * GrabScale),
                                   (int)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL) * GrabScale),
                                   8 + MIL.M_UNSIGNED,
                                   MIL.M_IMAGE + CompressAttribute,
                                   ref MilCompressedImage);

                MIL.MbufControl(MilCompressedImage, MIL.M_Q_FACTOR, COMPRESSION_Q_FACTOR);
            }

            // Allocate the grab buffers to hold the sequence buffering.
            MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_DISABLE);
            for (NbFrames = 0, n = 0; n < NB_GRAB_IMAGE_MAX; n++)
            {
                MIL.MbufAllocColor(MilSystem,
                                   MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, MIL.M_NULL),
                                   (int)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL) * GrabScale),
                                   (int)(MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL) * GrabScale),
                                   8 + MIL.M_UNSIGNED,
                                   MIL.M_IMAGE + MIL.M_GRAB,
                                   ref MilGrabImages[n]);

                if (MilGrabImages[n] != MIL.M_NULL)
                {
                    NbFrames++;
                    MIL.MbufClear(MilGrabImages[n], 0xFF);
                }
                else
                {
                    break;
                }
            }
            MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_ENABLE);

            // Free buffers to leave some space for possible temporary buffers.
            for (n = 0; n < 2 && NbFrames > 0; n++)
            {
                NbFrames--;
                MIL.MbufFree(MilGrabImages[NbFrames]);
            }

            // Halt continuous grab.
            MIL.MdigHalt(MilDigitizer);

            // Open the AVI file if required.
            if (SAVE_SEQUENCE_TO_DISK)
            {
                Console.WriteLine("Saving the sequence to an AVI file...");
                Console.WriteLine();
                MIL.MbufExportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_DEFAULT, MIL.M_OPEN);
            }

            // Initialize User's archiving function hook data structure.
            UserHookData.MilSystem          = MilSystem;
            UserHookData.MilDisplay         = MilDisplay;
            UserHookData.MilImageDisp       = MilImageDisp;
            UserHookData.MilCompressedImage = MilCompressedImage;
            UserHookData.SaveSequenceToDisk = SAVE_SEQUENCE_TO_DISK;
            UserHookData.NbGrabbedFrames    = 0;
            UserHookData.NbArchivedFrames   = 0;

            // get a handle to the DigHookUserData object in the managed heap, we will use this
            // handle to get the object back in the callback function
            GCHandle UserHookDataHandle = GCHandle.Alloc(UserHookData);
            MIL_DIG_HOOK_FUNCTION_PTR UserHookFunctionDelegate = new MIL_DIG_HOOK_FUNCTION_PTR(ArchiveFunction);

            // Acquire the sequence. The processing hook function will
            // be called for each image grabbed to archive and display it.
            // If sequence is not saved to disk, stop after NbFrames.
            MIL.MdigProcess(MilDigitizer, MilGrabImages, NbFrames, SAVE_SEQUENCE_TO_DISK ? MIL.M_START : MIL.M_SEQUENCE, MIL.M_DEFAULT, UserHookFunctionDelegate, GCHandle.ToIntPtr(UserHookDataHandle));

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

            // Stop the sequence acquisition.
            MIL.MdigProcess(MilDigitizer, MilGrabImages, NbFrames, MIL.M_STOP, MIL.M_DEFAULT, UserHookFunctionDelegate, GCHandle.ToIntPtr(UserHookDataHandle));

            // Free the GCHandle when no longer used
            UserHookDataHandle.Free();

            // Read and print final statistics.
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_COUNT, ref FrameCount);
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, ref FrameRate);
            MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_MISSED, ref FrameMissed);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("{0} frames archived ({1} missed), at {2:0.0} frames/sec ({3:0.0}ms/frame).", UserHookData.NbArchivedFrames, FrameMissed, FrameRate, 1000.0 / FrameRate);

            // Sequence file closing if required.
            if (SAVE_SEQUENCE_TO_DISK)
            {
                MIL.MbufExportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, FrameRate, MIL.M_CLOSE);
            }

            // Playback the sequence until a key is pressed.
            if (UserHookData.NbArchivedFrames > 0)
            {
                do
                {
                    // If sequence must be loaded.
                    if (SAVE_SEQUENCE_TO_DISK)
                    {
                        // Inquire information about the sequence.
                        Console.WriteLine();
                        Console.WriteLine("Playing back sequence from the AVI file...");
                        Console.WriteLine();
                        Console.WriteLine("Press <Enter> to end.");
                        Console.WriteLine();
                        Console.WriteLine();
                        MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_NUMBER_OF_IMAGES, ref FrameCount);
                        MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_FRAME_RATE, ref FrameRate);
                        MIL.MbufDiskInquire(SEQUENCE_FILE, MIL.M_COMPRESSION_TYPE, ref CompressAttribute);

                        // Open the sequence file.
                        MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_OPEN);
                    }

                    // Copy the images to the screen respecting the sequence frame rate.
                    TotalReplay      = 0.0;
                    NbFramesReplayed = 0;
                    for (n = 0; n < FrameCount; n++)
                    {
                        // Reset the time.
                        MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET, MIL.M_NULL);

                        // If image was saved to disk.
                        if (SAVE_SEQUENCE_TO_DISK)
                        {
                            // Load image directly to the display.
                            MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_LOAD, MIL.M_NULL, ref MilImageDisp, n, 1, MIL.M_READ);
                            NbFramesReplayed++;
                            Console.Write("Frame #{0}             \r", NbFramesReplayed);
                        }
                        else
                        {
                            // Copy the grabbed image to the display.
                            MIL.MbufCopy(MilGrabImages[n], MilImageDisp);
                            NbFramesReplayed++;
                            Console.Write("Frame #{0}             \r", NbFramesReplayed);
                        }


                        // Check for a pressed key to exit.
                        if (Console.KeyAvailable && (n >= (NB_GRAB_IMAGE_MAX - 1)))
                        {
                            Console.ReadKey(true);
                            break;
                        }

                        // Wait to have a proper frame rate.
                        MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, ref TimeWait);
                        TotalReplay += TimeWait;
                        TimeWait     = (1 / FrameRate) - TimeWait;
                        MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_WAIT, ref TimeWait);
                        TotalReplay += (TimeWait > 0) ? TimeWait : 0.0;
                    }

                    // Close the sequence file.
                    if (SAVE_SEQUENCE_TO_DISK)
                    {
                        MIL.MbufImportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MIL.M_CLOSE);
                    }

                    // Print statistics.
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("{0} frames replayed, at a frame rate of {1:0.0} frames/sec ({2:0.0} ms/frame).", NbFramesReplayed, n / TotalReplay, 1000.0 * TotalReplay / n);
                    Console.WriteLine();
                    Console.WriteLine("Press <Enter> to end (or any other key to playback again).");
                    Console.WriteLine();
                }while (Console.ReadKey(true).Key != ConsoleKey.Enter);
            }

            // Free all allocated buffers.
            MIL.MbufFree(MilImageDisp);
            for (n = 0; n < NbFrames; n++)
            {
                MIL.MbufFree(MilGrabImages[n]);
            }

            if (MilCompressedImage != MIL.M_NULL)
            {
                MIL.MbufFree(MilCompressedImage);
            }

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MIL.M_NULL);
        }
Ejemplo n.º 25
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 MilDisplayImage = MIL.M_NULL;    // Image buffer identifier.
            MIL_ID MilImage        = MIL.M_NULL;    // Image buffer identifier.
            MIL_ID MilKernel       = MIL.M_NULL;    // Custom kernel identifier.
            int    n    = 0;
            double Time = 0.0;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Restore source image into an automatically allocated image buffers.
            MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);
            MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilDisplayImage);

            // Zoom display to see the result of image processing better.
            MIL.MdispZoom(MilDisplay, ZOOM_VALUE, ZOOM_VALUE);

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

            // Pause to show the original image.
            Console.Write("\nIMAGE PROCESSING:\n");
            Console.Write("-----------------\n\n");
            Console.Write("This program performs a convolution on the displayed image.\n");
            Console.Write("It uses a custom smoothing kernel.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Allocate a MIL kernel.
            MIL.MbufAlloc2d(MilSystem, KERNEL_WIDTH, KERNEL_HEIGHT, KERNEL_DEPTH + MIL.M_UNSIGNED, MIL.M_KERNEL, ref MilKernel);

            // Put the custom data in it.
            MIL.MbufPut(MilKernel, KernelData);

            // Set a normalization (divide) factor to have a kernel with
            // a sum equal to one.
            MIL.MbufControlNeighborhood(MilKernel, MIL.M_NORMALIZATION_FACTOR, 16);

            // Convolve the image using the kernel.
            MIL.MimConvolve(MilImage, MilDisplayImage, MilKernel);

            // Now time the convolution (MimConvolve()):
            // Overscan calculation is disabled and a destination image that
            // is not displayed is used to have the real convolution time. Also the
            // function must be called once before the timing loop for more accurate
            // time (dll load, ...).
            MIL.MbufControlNeighborhood(MilKernel, MIL.M_OVERSCAN, MIL.M_DISABLE);
            MIL.MimConvolve(MilDisplayImage, MilImage, MilKernel);
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, MIL.M_NULL);
            for (n = 0; n < NB_LOOP; n++)
            {
                MIL.MimConvolve(MilDisplayImage, MilImage, MilKernel);
            }
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref Time);

            // Pause to show the result.
            Console.Write("Convolve time: {0:0.000} ms.\n", Time * 1000 / NB_LOOP);
            Console.Write("Press <Enter> to terminate.\n");
            Console.ReadKey();

            // Free all allocations.
            MIL.MbufFree(MilKernel);
            MIL.MbufFree(MilImage);
            MIL.MbufFree(MilDisplayImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 26
0
        // Main function.
        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  MilLeftSubImage      = MIL.M_NULL;      // Sub-image buffer identifier for original image.
            MIL_ID  MilRightSubImage     = MIL.M_NULL;      // Sub-image buffer identifier for processed image.
            MIL_ID  MilLumSubImage       = MIL.M_NULL;      // Sub-image buffer identifier for luminance.
            MIL_ID  MilRedBandSubImage   = MIL.M_NULL;      // Sub-image buffer identifier for red component.
            MIL_ID  MilGreenBandSubImage = MIL.M_NULL;      // Sub-image buffer identifier for green component.
            MIL_ID  MilBlueBandSubImage  = MIL.M_NULL;      // Sub-image buffer identifier for blue component.
            MIL_INT SizeX    = 0;
            MIL_INT SizeY    = 0;
            MIL_INT SizeBand = 0;
            MIL_INT Type     = 0;

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Allocate a color display buffer twice the size of the source image and display it.
            MIL.MbufAllocColor(MilSystem,
                               MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_BAND, ref SizeBand),
                               MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_X, ref SizeX) * 2,
                               MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_Y, ref SizeY),
                               MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_TYPE, ref Type),
                               MIL.M_IMAGE + MIL.M_DISP + MIL.M_PROC, ref MilImage);
            MIL.MbufClear(MilImage, 0);
            MIL.MdispSelect(MilDisplay, MilImage);

            // Define 2 child buffers that maps to the left and right part of the display
            // buffer, to put the source and destination color images.
            //
            MIL.MbufChild2d(MilImage, 0, 0, SizeX, SizeY, ref MilLeftSubImage);
            MIL.MbufChild2d(MilImage, SizeX, 0, SizeX, SizeY, ref MilRightSubImage);

            // Load the color source image on the left.
            MIL.MbufLoad(IMAGE_FILE, MilLeftSubImage);

            // Define child buffers that map to the red, green and blue components
            // of the source image.
            //
            MIL.MbufChildColor(MilLeftSubImage, MIL.M_RED, ref MilRedBandSubImage);
            MIL.MbufChildColor(MilLeftSubImage, MIL.M_GREEN, ref MilGreenBandSubImage);
            MIL.MbufChildColor(MilLeftSubImage, MIL.M_BLUE, ref MilBlueBandSubImage);

            // Write color text annotations to show access in each individual band of the image.
            //
            // Note that this is typically done more simply by using:
            //  MIL.MgraColor(MIL.M_DEFAULT, MIL.M_RGB(0xFF,0x90,0x00));
            //  MIL.MgraText(MIL.M_DEFAULT, MilLeftSubImage, ...);

            MIL.MgraColor(MIL.M_DEFAULT, 0xFF);
            MIL.MgraText(MIL.M_DEFAULT, MilRedBandSubImage, SizeX / 16, SizeY / 8, " TOUCAN ");
            MIL.MgraColor(MIL.M_DEFAULT, 0x90);
            MIL.MgraText(MIL.M_DEFAULT, MilGreenBandSubImage, SizeX / 16, SizeY / 8, " TOUCAN ");
            MIL.MgraColor(MIL.M_DEFAULT, 0x00);
            MIL.MgraText(MIL.M_DEFAULT, MilBlueBandSubImage, SizeX / 16, SizeY / 8, " TOUCAN ");

            // Print a message.
            Console.Write("\nCOLOR OPERATIONS:\n");
            Console.Write("-----------------\n\n");
            Console.Write("A color source image was loaded on the left and color text\n");
            Console.Write("annotations were written in it.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Convert image to Hue, Luminance, Saturation color space (HSL).
            MIL.MimConvert(MilLeftSubImage, MilRightSubImage, MIL.M_RGB_TO_HSL);

            // Create a child buffer that maps to the luminance component.
            MIL.MbufChildColor(MilRightSubImage, MIL.M_LUMINANCE, ref MilLumSubImage);

            // Add an offset to the luminance component.
            MIL.MimArith(MilLumSubImage, IMAGE_LUMINANCE_OFFSET, MilLumSubImage, MIL.M_ADD_CONST + MIL.M_SATURATION);

            // Convert image back to Red, Green, Blue color space (RGB) for display.
            MIL.MimConvert(MilRightSubImage, MilRightSubImage, MIL.M_HSL_TO_RGB);

            // Print a message.
            Console.Write("Luminance was increased using color image processing.\n");

            // Print a message.
            Console.Write("Press <Enter> to end.\n");
            Console.ReadKey();

            // Release sub-images and color image buffer.
            MIL.MbufFree(MilLumSubImage);
            MIL.MbufFree(MilRedBandSubImage);
            MIL.MbufFree(MilGreenBandSubImage);
            MIL.MbufFree(MilBlueBandSubImage);
            MIL.MbufFree(MilRightSubImage);
            MIL.MbufFree(MilLeftSubImage);
            MIL.MbufFree(MilImage);

            // Release defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 27
0
        // Main function:
        // --------------
        static void Main(string[] args)
        {
            MIL_ID       MilApplication       = MIL.M_NULL;         // Application identifier.
            MIL_ID       MilRemoteApplication = MIL.M_NULL;         // Remote Application identifier if running on a remote computer
            MIL_ID       MilSystem            = MIL.M_NULL;         // System identifier.
            MIL_ID       MilDisplay           = MIL.M_NULL;         // Display identifier.
            MIL_ID       MilImage             = MIL.M_NULL;         // Image buffer identifiers.
            MIL_ID       MilOrgImage          = MIL.M_NULL;
            THREAD_PARAM TParTopLeft          = new THREAD_PARAM(); // Parameters passed to top left thread.
            THREAD_PARAM TParBotLeft          = new THREAD_PARAM(); // Parameters passed to bottom left thread.
            THREAD_PARAM TParTopRight         = new THREAD_PARAM(); // Parameters passed to top right thread.
            THREAD_PARAM TParBotRight         = new THREAD_PARAM(); // Parameters passed to bottom right thread.
            double       Time            = 0.0;                     // Timer variables.
            double       FramesPerSecond = 0.0;
            MIL_INT      LicenseModules  = 0;                       // List of available MIL modules.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Allocate and display the main image buffer.
            MIL.MbufAlloc2d(MilSystem, IMAGE_WIDTH * 2, IMAGE_HEIGHT * 2, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref MilImage);
            MIL.MbufClear(MilImage, 0);
            MIL.MdispSelect(MilDisplay, MilImage);

            // Allocate an image buffer to keep the original.
            MIL.MbufAlloc2d(MilSystem, IMAGE_WIDTH, IMAGE_HEIGHT, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ref MilOrgImage);

            // Allocate a destination child buffer for each thread.
            MIL.MbufChild2d(MilImage, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, ref TParTopLeft.SrcImage);
            MIL.MbufChild2d(MilImage, 0, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, ref TParBotLeft.DstImage);
            MIL.MbufChild2d(MilImage, IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, ref TParTopRight.SrcImage);
            MIL.MbufChild2d(MilImage, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, ref TParBotRight.DstImage);

            // Allocate synchronization events.
            MIL.MthrAlloc(MilSystem, MIL.M_EVENT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, ref TParTopLeft.DoneEvent);
            MIL.MthrAlloc(MilSystem, MIL.M_EVENT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, ref TParBotLeft.DoneEvent);
            MIL.MthrAlloc(MilSystem, MIL.M_EVENT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, ref TParTopRight.DoneEvent);
            MIL.MthrAlloc(MilSystem, MIL.M_EVENT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, ref TParBotRight.DoneEvent);

            // Inquire MIL licenses.
            MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, ref MilRemoteApplication);
            MIL.MappInquire(MilRemoteApplication, MIL.M_LICENSE_MODULES, ref LicenseModules);

            // Initialize remaining thread parameters.
            TParTopLeft.System            = MilSystem;
            TParTopLeft.OrgImage          = MilOrgImage;
            TParTopLeft.DstImage          = TParTopLeft.SrcImage;
            TParTopLeft.ReadyEvent        = TParBotLeft.DoneEvent;
            TParTopLeft.NumberOfIteration = 0;
            TParTopLeft.Radius            = 0;
            TParTopLeft.Exit             = 0;
            TParTopLeft.LicenseModules   = LicenseModules;
            TParTopLeft.SlaveThreadParam = TParBotLeft;

            TParBotLeft.System            = MilSystem;
            TParBotLeft.OrgImage          = 0;
            TParBotLeft.SrcImage          = TParTopLeft.DstImage;
            TParBotLeft.ReadyEvent        = TParTopLeft.DoneEvent;
            TParBotLeft.NumberOfIteration = 0;
            TParBotLeft.Radius            = 0;
            TParBotLeft.Exit             = 0;
            TParBotLeft.LicenseModules   = LicenseModules;
            TParBotLeft.SlaveThreadParam = null;

            TParTopRight.System            = MilSystem;
            TParTopRight.OrgImage          = MilOrgImage;
            TParTopRight.DstImage          = TParTopRight.SrcImage;
            TParTopRight.ReadyEvent        = TParBotRight.DoneEvent;
            TParTopRight.NumberOfIteration = 0;
            TParTopRight.Radius            = 0;
            TParTopRight.Exit             = 0;
            TParTopRight.LicenseModules   = LicenseModules;
            TParTopRight.SlaveThreadParam = TParBotRight;

            TParBotRight.System            = MilSystem;
            TParBotRight.OrgImage          = 0;
            TParBotRight.SrcImage          = TParTopRight.DstImage;
            TParBotRight.ReadyEvent        = TParTopRight.DoneEvent;
            TParBotRight.NumberOfIteration = 0;
            TParBotRight.Radius            = 0;
            TParBotRight.Exit             = 0;
            TParBotRight.LicenseModules   = LicenseModules;
            TParBotRight.SlaveThreadParam = null;

            // Initialize the original image to process.
            MIL.MbufLoad(IMAGE_FILE, MilOrgImage);

            // Start the 4 threads.
            MIL_THREAD_FUNCTION_PTR TopThreadDelegate      = new MIL_THREAD_FUNCTION_PTR(TopThread);
            MIL_THREAD_FUNCTION_PTR BotLeftThreadDelegate  = new MIL_THREAD_FUNCTION_PTR(BotLeftThread);
            MIL_THREAD_FUNCTION_PTR BotRightThreadDelegate = new MIL_THREAD_FUNCTION_PTR(BotRightThread);

            GCHandle TParTopLeftHandle  = GCHandle.Alloc(TParTopLeft);
            GCHandle TParBotLeftHandle  = GCHandle.Alloc(TParBotLeft);
            GCHandle TParTopRightHandle = GCHandle.Alloc(TParTopRight);
            GCHandle TParBotRightHandle = GCHandle.Alloc(TParBotRight);

            MIL.MthrAlloc(MilSystem, MIL.M_THREAD, MIL.M_DEFAULT, TopThreadDelegate, GCHandle.ToIntPtr(TParTopLeftHandle), ref TParTopLeft.Id);
            MIL.MthrAlloc(MilSystem, MIL.M_THREAD, MIL.M_DEFAULT, BotLeftThreadDelegate, GCHandle.ToIntPtr(TParBotLeftHandle), ref TParBotLeft.Id);
            MIL.MthrAlloc(MilSystem, MIL.M_THREAD, MIL.M_DEFAULT, TopThreadDelegate, GCHandle.ToIntPtr(TParTopRightHandle), ref TParTopRight.Id);
            MIL.MthrAlloc(MilSystem, MIL.M_THREAD, MIL.M_DEFAULT, BotRightThreadDelegate, GCHandle.ToIntPtr(TParBotRightHandle), ref TParBotRight.Id);

            // Start the timer.
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, MIL.M_NULL);

            // Set events to start operation of top left and top right threads.
            MIL.MthrControl(TParTopLeft.ReadyEvent, MIL.M_EVENT_SET, MIL.M_SIGNALED);
            MIL.MthrControl(TParTopRight.ReadyEvent, MIL.M_EVENT_SET, MIL.M_SIGNALED);

            // Report that the threads are started and wait for a key press to stop them.
            Console.Write("\nMULTI-THREADING:\n");
            Console.Write("----------------\n\n");
            Console.Write("4 threads running...\n");
            Console.Write("Press <Enter> to stop.\n\n");
            Console.ReadKey();

            // Signal the threads to exit.
            TParTopLeft.Exit  = 1;
            TParTopRight.Exit = 1;

            // Wait for all threads to terminate.
            MIL.MthrWait(TParTopLeft.Id, MIL.M_THREAD_END_WAIT);
            MIL.MthrWait(TParBotLeft.Id, MIL.M_THREAD_END_WAIT);
            MIL.MthrWait(TParTopRight.Id, MIL.M_THREAD_END_WAIT);
            MIL.MthrWait(TParBotRight.Id, MIL.M_THREAD_END_WAIT);

            // Stop the timer and calculate the number of frames per second processed.
            MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref Time);
            FramesPerSecond = (TParTopLeft.NumberOfIteration + TParBotLeft.NumberOfIteration + TParTopRight.NumberOfIteration + TParBotRight.NumberOfIteration) / Time;

            // Print statistics.
            Console.Write("Top left iterations done:     {0,4}.\n", TParTopLeft.NumberOfIteration);
            Console.Write("Bottom left iterations done:  {0,4}.\n", TParBotLeft.NumberOfIteration);
            Console.Write("Top right iterations done:    {0,4}.\n", TParTopRight.NumberOfIteration);
            Console.Write("Bottom right iterations done: {0,4}.\n\n", TParBotRight.NumberOfIteration);
            Console.Write("Processing speed for the 4 threads: {0:0.0} Images/Sec.\n\n", FramesPerSecond);
            Console.Write("Press <Enter> to end.\n\n");
            Console.ReadKey();

            // Free threads.
            MIL.MthrFree(TParTopLeft.Id);
            MIL.MthrFree(TParBotLeft.Id);
            MIL.MthrFree(TParTopRight.Id);
            MIL.MthrFree(TParBotRight.Id);

            // Free events.
            MIL.MthrFree(TParTopLeft.DoneEvent);
            MIL.MthrFree(TParBotLeft.DoneEvent);
            MIL.MthrFree(TParTopRight.DoneEvent);
            MIL.MthrFree(TParBotRight.DoneEvent);

            // Free buffers.
            MIL.MbufFree(TParTopLeft.SrcImage);
            MIL.MbufFree(TParTopRight.SrcImage);
            MIL.MbufFree(TParBotLeft.DstImage);
            MIL.MbufFree(TParBotRight.DstImage);
            MIL.MbufFree(MilOrgImage);
            MIL.MbufFree(MilImage);

            // Free the GCHandles
            TParTopLeftHandle.Free();
            TParBotLeftHandle.Free();
            TParTopRightHandle.Free();
            TParBotRightHandle.Free();

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 28
0
        // Main to test the custom function. //
        // --------------------------------- //

        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_INT ReturnValue    = 0;             // Return value of the function.

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

            // Load source image into a Host memory image buffer.
            MIL.MbufAlloc2d(MilSystem,
                            MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_X),
                            MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_Y),
                            8 + MIL.M_UNSIGNED,
                            MIL.M_IMAGE + MIL.M_DISP + MIL.M_HOST_MEMORY,
                            ref MilImage);
            MIL.MbufLoad(IMAGE_FILE, MilImage);

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

            // Pause.
            Console.WriteLine();
            Console.WriteLine("MIL FUNCTION DEVELOPER'S TOOLKIT:");
            Console.WriteLine("----------------------------------");
            Console.WriteLine();
            Console.WriteLine("This example creates a custom MIL function that processes");
            Console.WriteLine("an image using its data pointer directly.");
            Console.WriteLine();
            Console.WriteLine("Target image was loaded.");
            Console.WriteLine("Press a key to continue.");
            Console.WriteLine();
            Console.ReadKey();

            // Run the custom function only if the target system's memory is local and accessible.
            if (MIL.MsysInquire(MilSystem, MIL.M_LOCATION, MIL.M_NULL) == MIL.M_LOCAL)
            {
                // Process the image directly with the custom MIL function.
                ReturnValue = AddConstant(MilImage, MilImage, 0x40);

                // Print a conclusion message.
                if (ReturnValue == MIL.M_NULL)
                {
                    Console.WriteLine("The white level of the image was augmented.");
                }
                else
                {
                    Console.WriteLine("An error was returned by the Slave function.");
                }
            }
            else
            {
                // Print that the example don't run remotely.
                Console.WriteLine("This example doesn't run with Distributed MIL.");
            }

            // Wait for a key to terminate.
            Console.WriteLine("Press a key to terminate.");
            Console.WriteLine();
            Console.ReadKey();

            // Free all allocations.
            MIL.MbufFree(MilImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 29
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  GraphicList    = MIL.M_NULL;                            // Graphic list identifier.
            MIL_ID  MilEdgeContext = MIL.M_NULL;                            // Edge context.
            MIL_ID  MilEdgeResult  = MIL.M_NULL;                            // Edge result identifier.
            double  EdgeDrawColor  = CONTOUR_DRAW_COLOR;                    // Edge draw color.
            double  LabelDrawColor = CONTOUR_LABEL_COLOR;                   // Text draw color.
            MIL_INT NumEdgeFound   = 0;                                     // Number of edges found.
            MIL_INT NumResults     = 0;                                     // Number of results found.
            int     i = 0;                                                  // Loop variable.

            double[] MeanFeretDiameter = new double[CONTOUR_MAX_RESULTS];   // Edge mean Feret diameter.

            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Restore the image and display it.
            MIL.MbufRestore(CONTOUR_IMAGE, MilSystem, ref MilImage);
            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);

            // Pause to show the original image.
            Console.Write("\nEDGE MODULE:\n");
            Console.Write("------------\n\n");
            Console.Write("This program determines the outer seal diameters in the displayed image \n");
            Console.Write("by detecting and analyzing contours with the Edge Finder module.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Allocate a Edge Finder context.
            MIL.MedgeAlloc(MilSystem, MIL.M_CONTOUR, MIL.M_DEFAULT, ref MilEdgeContext);

            // Allocate a result buffer.
            MIL.MedgeAllocResult(MilSystem, MIL.M_DEFAULT, ref MilEdgeResult);

            // Enable features to compute.
            MIL.MedgeControl(MilEdgeContext, MIL.M_MOMENT_ELONGATION, MIL.M_ENABLE);
            MIL.MedgeControl(MilEdgeContext, MIL.M_FERET_MEAN_DIAMETER + MIL.M_SORT1_DOWN, MIL.M_ENABLE);

            // Calculate edges and features.
            MIL.MedgeCalculate(MilEdgeContext, MilImage, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MilEdgeResult, MIL.M_DEFAULT);

            // Get the number of edges found.
            MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_NUMBER_OF_CHAINS + MIL.M_TYPE_MIL_INT, ref NumEdgeFound);

            // Draw edges in the source image to show the result.
            MIL.MgraColor(MIL.M_DEFAULT, EdgeDrawColor);
            MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_EDGES, MIL.M_DEFAULT, MIL.M_DEFAULT);

            // Pause to show the edges.
            Console.Write("{0} edges were found in the image.\n", NumEdgeFound);
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Exclude elongated edges.
            MIL.MedgeSelect(MilEdgeResult, MIL.M_EXCLUDE, MIL.M_MOMENT_ELONGATION, MIL.M_LESS, CONTOUR_MAXIMUM_ELONGATION, MIL.M_NULL);

            // Exclude inner chains.
            MIL.MedgeSelect(MilEdgeResult, MIL.M_EXCLUDE, MIL.M_INCLUDED_EDGES, MIL.M_INSIDE_BOX, MIL.M_NULL, MIL.M_NULL);

            // Draw remaining edges and their index to show the result.
            MIL.MgraClear(MIL.M_DEFAULT, GraphicList);
            MIL.MgraColor(MIL.M_DEFAULT, EdgeDrawColor);
            MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_EDGES, MIL.M_DEFAULT, MIL.M_DEFAULT);

            // Pause to show the results.
            Console.Write("Elongated edges and inner edges of each seal were removed.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Get the number of edges found.
            MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_NUMBER_OF_CHAINS + MIL.M_TYPE_MIL_INT, ref NumResults);

            // If the right number of edges were found.
            if ((NumResults >= 1) && (NumResults <= CONTOUR_MAX_RESULTS))
            {
                // Draw the index of each edge.
                MIL.MgraColor(MIL.M_DEFAULT, LabelDrawColor);
                MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_INDEX, MIL.M_DEFAULT, MIL.M_DEFAULT);

                // Get the mean Feret diameters.
                MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_FERET_MEAN_DIAMETER, MeanFeretDiameter);

                // Print the results.
                Console.Write("Mean diameter of the {0} outer edges are:\n\n", NumResults);
                Console.Write("Index   Mean diameter \n");
                for (i = 0; i < NumResults; i++)
                {
                    Console.Write("{0,-11}{1,-13:0.00}\n", i, MeanFeretDiameter[i]);
                }
            }
            else
            {
                Console.Write("Edges have not been found or the number of found edges is greater than\n");
                Console.Write("the specified maximum number of edges !\n\n");
            }

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

            // Free MIL objects.
            MIL.MgraFree(GraphicList);
            MIL.MbufFree(MilImage);
            MIL.MedgeFree(MilEdgeContext);
            MIL.MedgeFree(MilEdgeResult);

            // Free defaults.
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            MIL_ID  MilApplication       = MIL.M_NULL;  // Application identifier.
            MIL_ID  MilRemoteApplication = MIL.M_NULL;  // Remote Application identifier if running on a remote computer
            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  MilExtremeResult     = 0;           // Extreme result buffer identifier.
            int     MaxLabelNumber       = 0;           // Highest label value.
            MIL_INT LicenseModules       = 0;           // List of available MIL modules.


            // Allocate defaults.
            MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL);

            // Restore source image and display it.
            MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage);
            MIL.MdispSelect(MilDisplay, MilImage);

            // Pause to show the original image.
            Console.Write("\nIMAGE PROCESSING:\n");
            Console.Write("-----------------\n\n");
            Console.Write("This program extracts the dark particles in the image.\n");
            Console.Write("Press <Enter> to continue.\n\n");
            Console.ReadKey();

            // Binarize the image with an automatically calculated threshold so that
            // particles are represented in white and the background removed.
            MIL.MimBinarize(MilImage, MilImage, MIL.M_BIMODAL + MIL.M_LESS_OR_EQUAL, MIL.M_NULL, MIL.M_NULL);

            // Print a message for the extracted particles.
            Console.Write("These particles were extracted from the original image.\n");

            // If MIL IM module is available, count and label the larger particles.
            MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, ref MilRemoteApplication);
            MIL.MappInquire(MilRemoteApplication, MIL.M_LICENSE_MODULES, ref LicenseModules);

            if ((LicenseModules & MIL.M_LICENSE_IM) != 0)
            {
                // Pause to show the extracted particles.
                Console.Write("Press <Enter> to continue.\n\n");
                Console.ReadKey();

                // Close small holes.
                MIL.MimClose(MilImage, MilImage, IMAGE_SMALL_PARTICLE_RADIUS, MIL.M_BINARY);

                // Remove small particles.
                MIL.MimOpen(MilImage, MilImage, IMAGE_SMALL_PARTICLE_RADIUS, MIL.M_BINARY);

                // Label the image.
                MIL.MimLabel(MilImage, MilImage, MIL.M_DEFAULT);

                // The largest label value corresponds to the number of particles in the image.
                MIL.MimAllocResult(MilSystem, 1, MIL.M_EXTREME_LIST, ref MilExtremeResult);
                MIL.MimFindExtreme(MilImage, MilExtremeResult, MIL.M_MAX_VALUE);
                MIL.MimGetResult(MilExtremeResult, MIL.M_VALUE, ref MaxLabelNumber);
                MIL.MimFree(MilExtremeResult);

                // Multiply the labeling result to augment the gray level of the particles.
                MIL.MimArith(MilImage, (int)(256 / (double)MaxLabelNumber), MilImage, MIL.M_MULT_CONST);

                // Display the resulting particles in pseudo-color.
                MIL.MdispLut(MilDisplay, MIL.M_PSEUDO);

                // Print results.
                Console.Write("There were {0} large particles in the original image.\n", MaxLabelNumber);
            }

            // Pause to show the result.
            Console.Write("Press <Enter> to end.\n\n");
            Console.ReadKey();

            // Free all allocations.
            MIL.MbufFree(MilImage);
            MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL);
        }