Ejemplo n.º 1
0
 private MatroxCard()
 {
     if (MilApplication == MIL.M_NULL)
     {
         MIL.MappAlloc(MIL.M_DEFAULT, ref MilApplication);
     }
 }
Ejemplo n.º 2
0
        // Gig-E System을 초기화 한다.
        public int Initialize()
        {
            //====================================================================
            // Camera System 초기화
            m_System = new BGAPI.System();
            m_State  = new BGAPI.BGAPI_FeatureState();

            // check system.
            m_iResult = BGAPI.EntryPoint.countSystems(ref m_iSystemNo);
            if (m_iResult != BGAPI.Result.OK)
            {   // BGAPI.EntryPoint.CountSystems failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CHECK_FAIL));
            }
            // create system.
            m_iResult = BGAPI.EntryPoint.createSystem(m_iSystemIndex, ref m_System);
            if (m_iResult != BGAPI.Result.OK)
            {   // BGAPI.EntryPoint.createSystems failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CREATE_FAIL));
            }
            // open system
            m_iResult = m_System.open();
            if (m_iResult != BGAPI.Result.OK)
            {   // System open failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_OPEN_FAIL));
            }

            // get camera num
            m_iResult = m_System.countCameras(ref m_iCheckCamNo);
            if (m_iResult != BGAPI.Result.OK)
            {   // System count cameras failed!
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CHECK_CAM_FAIL));
            }

            //====================================================================
            // Library System 초기화

            //MIL.MappAllocDefault(MIL.M_DEFAULT, ref m_MilApp, ref m_MilSystem, ref m_MilDisplay, MIL.M_NULL, MIL.M_NULL);

            MIL.MappAlloc(MIL.M_NULL, MIL.M_DEFAULT, ref m_MilApp);

            // Allocate a MIL system.
            MIL.MsysAlloc(MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, MIL.M_DEFAULT, ref m_MilSystem);

            // System Init 결과 저장
            m_iResult = SUCCESS;

            return(SUCCESS);
        }
Ejemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Allocates a MIL application, system, display, image buffer and digitizer (if available).
        /// </summary>
        public void Allocate()
        {
            // Allocate a MIL application.
            MIL.MappAlloc(MIL.M_NULL, MIL.M_DEFAULT, ref _appId);

            // Allocate a MIL system.
            MIL.MsysAlloc(MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, MIL.M_DEFAULT, ref _sysId);

            // Allocate a MIL display.
            MIL.MdispAlloc(_sysId, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_WINDOWED, ref _dispId);

            // Set default values for the image buffer in case no digitizer can be allocated.
            MIL_INT bufferSizeX     = DEFAULT_IMAGE_SIZE_X;
            MIL_INT bufferSizeY     = DEFAULT_IMAGE_SIZE_Y;
            MIL_INT bufferSizeBand  = DEFAULT_IMAGE_SIZE_BAND;
            long    imageAttributes = MIL.M_IMAGE | MIL.M_DISP | MIL.M_PROC;

            // Inquire the number of digitizers for the system.
            MIL_INT numberOfDigitizers = MIL.MsysInquire(_sysId, MIL.M_DIGITIZER_NUM, MIL.M_NULL);

            if (numberOfDigitizers > 0)
            {
                // Allocate a digitizer.
                MIL.MdigAlloc(_sysId, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, ref _digId);

                // Inquire the digitizer to determine the image buffer size.
                bufferSizeBand = MIL.MdigInquire(_digId, MIL.M_SIZE_BAND, MIL.M_NULL);
                bufferSizeX    = MIL.MdigInquire(_digId, MIL.M_SIZE_X, MIL.M_NULL);
                bufferSizeY    = MIL.MdigInquire(_digId, MIL.M_SIZE_Y, MIL.M_NULL);

                // Add the M_GRAB attibute to the image buffer.
                imageAttributes |= MIL.M_GRAB;
            }

            // Notify the UI that grabbing options have changed.
            RaisePropertyChangedEvent("CanStartGrab");
            RaisePropertyChangedEvent("CanStopGrab");

            // Allocate the image buffer.
            MIL.MbufAllocColor(_sysId, bufferSizeBand, bufferSizeX, bufferSizeY, 8 + MIL.M_UNSIGNED, imageAttributes, ref _bufId);

            // Notify the UI that the buffer size changed.
            RaisePropertyChangedEvent("BufferSizeX");
            RaisePropertyChangedEvent("BufferSizeY");

            // Fill the buffer with a default message.
            FillImageBuffer(bufferSizeX, bufferSizeY);
        }
Ejemplo n.º 4
0
        //**************************************************************************
        //
        // Name:         MilApplication()
        //
        // Synopsis:     This function is the core of the MIL application that
        //               is executed when the "Start" menu item of this
        //               Windows forms program is selected. See main() in the
        //               program.cs file for the program's entry point.
        //
        //               It uses MIL to display a welcoming message in the
        //               specified user window and to grab in it (if it is supported)
        //               using the target system.
        //
        //**************************************************************************
        private void MilApplication(IntPtr UserWindowHandle)
        {
            // MIL variables
            MIL_ID  MilApplication = MIL.M_NULL; // MIL Application identifier.
            MIL_ID  MilSystem      = MIL.M_NULL; // MIL System identifier.
            MIL_ID  MilDisplay     = MIL.M_NULL; // MIL Display identifier.
            MIL_ID  MilDigitizer   = MIL.M_NULL; // MIL Digitizer identifier.
            MIL_ID  MilImage       = MIL.M_NULL; // MIL Image buffer identifier.
            MIL_INT BufSizeX       = DEFAULT_IMAGE_SIZE_X;
            MIL_INT BufSizeY       = DEFAULT_IMAGE_SIZE_Y;
            MIL_INT BufSizeBand    = DEFAULT_IMAGE_SIZE_BAND;

            // Allocate a MIL application.
            MIL.MappAlloc(MIL.M_NULL, MIL.M_DEFAULT, ref MilApplication);

            // Allocate a MIL system.
            MIL.MsysAlloc(MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, MIL.M_DEFAULT, ref MilSystem);

            // Allocate a MIL display.
            MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_WINDOWED, ref MilDisplay);

            // Allocate a MIL digitizer, if supported, and set the target image size.
            if (MIL.MsysInquire(MilSystem, MIL.M_DIGITIZER_NUM, MIL.M_NULL) > 0)
            {
                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.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, ref BufSizeBand);

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

            // Allocate a MIL buffer.
            long Attributes = MIL.M_IMAGE + MIL.M_DISP;

            if (MilDigitizer != MIL.M_NULL)
            {
                // Add M_GRAB attribute if a digitizer is allocated.
                Attributes |= MIL.M_GRAB;
            }
            MIL.MbufAllocColor(MilSystem, BufSizeBand, BufSizeX, BufSizeY, 8 + MIL.M_UNSIGNED, Attributes, ref MilImage);

            // Clear the buffer.
            MIL.MbufClear(MilImage, 0);

            // Select the MIL buffer to be displayed in the user-specified window.
            MIL.MdispSelectWindow(MilDisplay, MilImage, UserWindowHandle);

            // Print a string in the image buffer using MIL.
            // Note: When a MIL buffer is modified using a MIL command, the display
            // automatically updates the window passed to MIL.MdispSelectWindow().

            MIL.MgraFont(MIL.M_DEFAULT, MIL.M_FONT_DEFAULT_LARGE);
            MIL.MgraText(MIL.M_DEFAULT, MilImage, (BufSizeX / 8) * 2, BufSizeY / 2, " Welcome to MIL !!! ");
            MIL.MgraRect(MIL.M_DEFAULT, MilImage, ((BufSizeX / 8) * 2) - 60, (BufSizeY / 2) - 80, ((BufSizeX / 8) * 2) + 370, (BufSizeY / 2) + 100);
            MIL.MgraRect(MIL.M_DEFAULT, MilImage, ((BufSizeX / 8) * 2) - 40, (BufSizeY / 2) - 60, ((BufSizeX / 8) * 2) + 350, (BufSizeY / 2) + 80);
            MIL.MgraRect(MIL.M_DEFAULT, MilImage, ((BufSizeX / 8) * 2) - 20, (BufSizeY / 2) - 40, ((BufSizeX / 8) * 2) + 330, (BufSizeY / 2) + 60);

            // Open a message box to wait for a key press.
            MessageBox.Show("\"Welcome to MIL !!!\" was printed", "MIL application example", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            // Grab in the user window if supported.
            if (MilDigitizer != MIL.M_NULL)
            {
                // Grab continuously.
                MIL.MdigGrabContinuous(MilDigitizer, MilImage);

                // Open a message box to wait for a key press.
                MessageBox.Show("Continuous grab in progress", "MIL application example", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

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

            // Remove the MIL buffer from the display.
            MIL.MdispSelect(MilDisplay, MIL.M_NULL);

            // Free allocated objects.
            MIL.MbufFree(MilImage);

            if (MilDigitizer != MIL.M_NULL)
            {
                MIL.MdigFree(MilDigitizer);
            }

            MIL.MdispFree(MilDisplay);
            MIL.MsysFree(MilSystem);
            MIL.MappFree(MilApplication);
        }
Ejemplo n.º 5
0
        public void Grab_Image()
        {
            //변수 선언
            MIL_INT Image_Size     = 450;
            MIL_INT Buf_Define     = 25;
            MIL_ID  MilApplication = MIL.M_NULL;
            MIL_ID  MilSystem      = MIL.M_NULL;
            MIL_ID  MilDisplay     = MIL.M_NULL;
            MIL_ID  MilDigiti      = MIL.M_NULL;

            MIL_ID[] Milimage        = new MIL_ID[25];
            string[] FileName        = new string[25];
            String[] strPathFileName = new String[25];
            Image[]  Img             = new Image[25];
            String   File_temp       = string.Empty;

            //ALLOC 설정
            MIL.MappAlloc(MIL.M_DEFAULT, ref MilApplication);
            MIL.MsysAlloc(MIL.M_SYSTEM_SOLIOS, MIL.M_DEV0, MIL.M_DEFAULT, ref MilSystem);

            //DCF상에서 450 * 25 사이즈에 대하여 영상획득하게 설정되어 있습니다. 바꾸시길 원하시면 DCF상에서 바꾸시고 소스상에서
            //MIL_INT Image_Size = 450; MIL_INT Buf_Define = 25; 값들을 변경하여 주시면 됩니다.
            //제가 원한사이즈는 4096 * 11250 ( 450 사이즈에 대하여 25번 GRAB하였습니다.)

            for (int i = 0; i < Buf_Define; i++)
            {
                MIL.MbufAllocColor(MilSystem, 3, 4096, Image_Size, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_GRAB + MIL.M_DISP, ref Milimage[i]);
            }

            MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, ref MilDisplay);
            MIL.MdigAlloc(MilSystem, MIL.M_DEFAULT, "scan.dcf", MIL.M_DEFAULT, ref MilDigiti);
            MIL.MdigControl(MilDigiti, MIL.M_CAMERALINK_CC3_SOURCE, MIL.M_GRAB_EXPOSURE);
            SaveFileDialog SaveFile = new SaveFileDialog();

            //파일저장 경로 설정 -> 윈도우폼으로 저장경로 설정
            SaveFile.DefaultExt = "jpg";
            SaveFile.Filter     = "*.jpg|*.jpg| *.mim|*.mim| *.tif|*.tif";
            if (SaveFile.ShowDialog() == DialogResult.OK)
            {
                File_temp = SaveFile.FileName;
            }

            //위에 경로에 대하여 이미지 저장
            for (int i = 0; i < Buf_Define; i++)
            {
                MIL.MbufClear(Milimage[i], 0);
                MIL.MdispSelect(MilDisplay, Milimage[i]);
                MIL.MdigGrab(MilDigiti, Milimage[i]);
            }

            //Filename changed.
            //File_temp
            for (int j = 0; j < Buf_Define; j++)
            {
                FileName[j] = File_temp.Replace(".jpg", "_" + j + ".jpg");
                MIL.MbufExport(FileName[j], MIL.M_JPEG_LOSSY, Milimage[j]);
            }

            //ALLOC 해제
            for (int i = 0; i < Buf_Define; i++)
            {
                MIL.MbufFree(Milimage[i]);
            }

            MIL.MdigFree(MilDigiti);
            MIL.MdispFree(MilDisplay);
            MIL.MsysFree(MilSystem);
        }
Ejemplo n.º 6
0
        private void CameraOpen()
        {
            try
            {
                //mil app open
                MIL.MappAlloc(MIL.M_NULL, MIL.M_DEFAULT, ref _MilApplication);
                //mil throw 관리
                MIL.MappControl(_MilApplication, MIL.M_ERROR, MIL.M_THROW_EXCEPTION);

                //설치된 보드 드라이버 수 가져오기
                var insSysCount = MIL.MappInquire(MIL.M_INSTALLED_SYSTEM_COUNT);
                for (int i = 0; i < insSysCount; i++)
                {
                    MIL_ID        tmpSystem = MIL.M_NULL;
                    StringBuilder sb        = new StringBuilder();

                    //보드 종류 문자열로 뽑아내기
                    MIL.MappInquire(_MilApplication, MIL.M_INSTALLED_SYSTEM_DESCRIPTOR + i, sb);

                    var boardCount = 0;
                    //같은 종류의 보드 몇 개까지 존재하는지 확인
                    while (sb.ToString() != "M_SYSTEM_HOST")
                    {
                        MIL_ID systemId = MIL.M_NULL;
                        try
                        {
                            //보드 alloc
                            MIL.MsysAlloc(sb.ToString(), boardCount, MIL.M_DEFAULT, ref systemId);
                        }
                        catch
                        {
                            //해당 보드는 메인보드에서 인식되지 않음 (없음)
                            break;
                        }
                        //alloc된 보드 추가
                        var cam = new MatroxCamera();

                        //Digitizer 몇개 존재하는지 확인
                        var digCount = MIL.MsysInquire(systemId, MIL.M_DIGITIZER_NUM);
                        //임의의 dcf file 추가 (원하는 dcf로 변경)
                        var dcfPath = AppDomain.CurrentDomain.BaseDirectory + @"\camfile.dcf";

                        //보드에 연결된 카메라 수만큼 돎
                        for (int ii = 0; ii < digCount; ii++)
                        {
                            MIL_ID digitId = MIL.M_NULL;
                            //digitizer alloc
                            MIL.MdigAlloc(systemId, ii, dcfPath, MIL.M_DEFAULT, ref digitId);
                            cam.SystemID    = systemId;
                            cam.DigitizerID = digitId;
                        }
                        MatroxCameraList.Add(cam);
                        boardCount++;
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + "\n" + err.StackTrace);
            }
        }