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.º 2
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.º 3
0
        public int Init(int camIndex = 0)
        {
            try
            {
                //1.初始化默认的appID和sysID
                MIL.MappAllocDefault(MIL.M_DEFAULT, ref appID, ref sysID, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL);

                //2.初始化digID,用于CameraLink控制相机
                MIL_INT digNum = MIL.MsysInquire(sysID, MIL.M_DIGITIZER_NUM, MIL.M_NULL);//获取Cameralink数量

                if (digNum < camIndex)
                {
                    throw new Exception($"Camera {camIndex} not exits! Please check !");
                }
                MIL.MdigAlloc(sysID, camIndex, dfc, MIL.M_DEFAULT, ref digID);//从DFC文件中加载相机配置,第三个参数就是DFC文件的路径

                //3.相机配置保存在DFC文件中,现在可以从digID中获取到相机的配置
                MIL.MdigInquire(digID, MIL.M_SIZE_X, ref width);  //获取相机宽度
                MIL.MdigInquire(digID, MIL.M_SIZE_Y, ref height); //获取相机高度

                //MIL.MdigInquire(digID, MIL.M_MODEL_IMAGE_ATTRIBUTE, ref imgAttribute);//用于下一步分配相机帧buffer的参数
                imgAttribute = MIL.M_GRAB | MIL.M_IMAGE | MIL.M_DISP | MIL.M_PROC;

                //4.分配buffer来存储相机帧数据
                MIL.MbufAlloc2d(sysID, width, height, 8 + MIL.M_UNSIGNED, imgAttribute, ref imgID);

                //4.初始化时,开启控制串口
                //comport.Open();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(0);
        }
Ejemplo n.º 4
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.º 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 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.º 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.
        //*****************************************************************************
        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);
        }
Ejemplo n.º 8
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.º 9
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.º 10
0
        private void mil(IntPtr UserWindowHandle)
        {
            MIL_ID MilDigitizer = MIL.M_NULL;

            MIL_INT BufSizeX = DEFAULT_IMAGE_SIZE_X;
            MIL_INT BufSizeY = DEFAULT_IMAGE_SIZE_Y;


            MIL_INT bufsx = DEFAULT_IMAGE_SIZE_X;
            MIL_INT bufsy = DEFAULT_IMAGE_SIZE_Y;

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

            MIL.MdispSelectWindow(MilDisplay, MilImage, UserWindowHandle);

            //MIL.MdispSelect(MilDisplay, MilImage);

            ////MIL.MdigAlloc(MilSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, ref MilDigitizer);
            MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, ref BufSizeX);
            MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, ref BufSizeY);

            //MIL.MdispControl(MilDisplay, MIL.M_SIZE_BIT, 8);
            // Resize the display window
            //if ((BufSizeX > DEFAULT_IMAGE_SIZE_X) || (BufSizeY > DEFAULT_IMAGE_SIZE_Y))
            //{
            //    FromHandle(UserWindowHandle).Size = new Size((int)BufSizeX, (int)BufSizeY);
            //}


            // MIL.MdispZoom(MilDisplay, -2.0, -2.0);

            //MIL.MdispControl(MilDisplay, MIL.M_VIEW_BIT_SHIFT, 8);
            MIL.MdispControl(MilDisplay, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE);
            MIL.MdispControl(MilDisplay, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE);

            ////MIL.MdispInquire(MilDisplay, MIL.M_SIZE_X, ref DEFAULT_IMAGE_SIZE_X);
            //MIL_INT imageWidth, imageHeight;
            //imageWidth = MIL.MbufInquire(MilImage, MIL.M_SIZE_X, MIL.M_NULL);
            //imageHeight = MIL.MbufInquire(MilImage, MIL.M_SIZE_Y, MIL.M_NULL);

            //MIL.MbufInquire(MilImage, MIL.M_SIZE_X, bufsx);

            //MIL.MbufInquire(MilImage, MIL.M_SIZE_X, bufsy);

            if (MilDigitizer != MIL.M_NULL)
            {
                MIL.MdigGrabContinuous(MilDigitizer, MilImage);
                //MessageBox.Show("Image Acquisition", "Acquisition");
                //MIL.MdigHalt(MilDigitizer);
            }

            //MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImage);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        public MainWindowViewModel()
        {
            _toggleGrabCommand             = new RelayCommand(ToggleGrab, param => _canExecute);
            _closeCommand                  = new RelayCommand(CloseApp, param => true);
            _calibrateFromImageCommand     = new RelayCommand(CalibrateFromImage, param => true);
            _calibrateFromDigitizerCommand = new RelayCommand(CalibrateFromDigitizer, param => true);
            _calibrateToPVACommand         = new RelayCommand(CalibrateToPVA, param => true);

            MIL.MappAllocDefault(MIL.M_DEFAULT, ref _app, ref _system, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL);

            MIL.MgraAlloc(_system, ref _calibrationGraphicsContext);
            MIL.MgraAllocList(_system, MIL.M_DEFAULT, ref _calibrationGraphics);

            // Allocate the standard dot grid calibration
            MIL.McalAlloc(_system, MIL.M_PERSPECTIVE_TRANSFORMATION, MIL.M_DEFAULT, ref _calibration);

            // Allocate the PVA calibration method using points from grid cal
            MIL.McalAlloc(_system, MIL.M_PERSPECTIVE_TRANSFORMATION, MIL.M_DEFAULT, ref _pvaCalibration);

            // Digitizer testing
            // Allocate digitizer
            MIL.MdigAlloc(_system, MIL.M_DEV0, "M_DEFAULT", MIL.M_DEV_NUMBER, ref _digitizer);
            MIL.MbufRestore(@".\CalImage.png", _system, ref _buffer);

            //
            // // Inquire the _digitizer to determine the image buffer size.
            // MIL_INT bufferSizeX;
            // MIL_INT bufferSizeY;
            // MIL_INT bufferSizeBand;
            //
            // bufferSizeX = MIL.MdigInquire(_digitizer, MIL.M_SIZE_X, MIL.M_NULL);
            // bufferSizeY = MIL.MdigInquire(_digitizer, MIL.M_SIZE_Y, MIL.M_NULL);
            // bufferSizeBand = MIL.MdigInquire(_digitizer, MIL.M_SIZE_BAND, MIL.M_NULL);
            //
            // long imageAttributes = MIL.M_IMAGE | MIL.M_DISP | MIL.M_PROC | MIL.M_GRAB;
            //
            // // Allocate the image buffer for digitizer
            // MIL.MbufAllocColor(_system, bufferSizeBand, bufferSizeX, bufferSizeY, 8 + MIL.M_UNSIGNED, imageAttributes, ref _buffer);

            // Setup Display
            MIL.MdispAlloc(_system, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_WPF, ref _display);
            MIL.MdispControl(_display, MIL.M_BACKGROUND_COLOR, MIL.M_COLOR_LIGHT_BLUE);
            MIL.MdispControl(_display, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE);
            MIL.MdispControl(_display, MIL.M_CENTER_DISPLAY, MIL.M_ENABLE);
            MIL.MdispControl(_display, MIL.M_MOUSE_USE, MIL.M_ENABLE);

            // Associate display and buffer
            MIL.MdispSelect(_display, _buffer);
        }
Ejemplo n.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 20
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.º 21
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);
        }
Ejemplo n.º 22
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.º 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        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.º 24
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.º 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  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.º 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
        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.º 28
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.º 29
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.º 30
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);
        }