Ejemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            m_FrameCallback = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback);

            tSdkCameraDevInfo[] DevList;
            MvApi.CameraEnumerateDevice(out DevList);
            int NumDev = (DevList != null ? DevList.Length : 0);

            if (NumDev < 1)
            {
                MessageBox.Show("未扫描到相机");
            }
            else if (NumDev == 1)
            {
                MvApi.CameraGrabber_Create(out m_Grabber, ref DevList[0]);
            }
            else
            {
                MvApi.CameraGrabber_CreateFromDevicePage(out m_Grabber);
            }

            if (m_Grabber != IntPtr.Zero)
            {
                MvApi.CameraGrabber_GetCameraDevInfo(m_Grabber, out m_DevInfo);
                MvApi.CameraGrabber_GetCameraHandle(m_Grabber, out m_hCamera);
                MvApi.CameraCreateSettingPage(m_hCamera, this.Handle, m_DevInfo.acFriendlyName, null, (IntPtr)0, 0);

                MvApi.CameraGrabber_SetRGBCallback(m_Grabber, m_FrameCallback, IntPtr.Zero);

                MvApi.CameraGrabber_SetHWnd(m_Grabber, this.DispWnd.Handle);
                MvApi.CameraGrabber_StartLive(m_Grabber);
            }
        }
Ejemplo n.º 2
0
        public Form2()
        {
            InitializeComponent();

            m_FrameCallback[0]  = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback0);
            m_FrameCallback[1]  = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback1);
            m_FrameCallback[2]  = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback2);
            m_FrameCallback[3]  = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback3);
            m_SaveImageComplete = new pfnCameraGrabberSaveImageComplete(CameraGrabberSaveImageComplete2);

            MvApi.CameraEnumerateDevice(out m_DevInfo);
            int NumDev = (m_DevInfo != null ? Math.Min(m_DevInfo.Length, CAMERA_NUM) : 0);

            IntPtr[] hDispWnds = { this.DispWnd1.Handle, this.DispWnd2.Handle, this.DispWnd3.Handle, this.DispWnd4.Handle };
            for (int i = 0; i < NumDev; ++i)
            {
                if (MvApi.CameraGrabber_Create(out m_Grabber[i], ref m_DevInfo[i]) == CameraSdkStatus.CAMERA_STATUS_SUCCESS)
                {
                    MvApi.CameraGrabber_GetCameraHandle(m_Grabber[i], out m_hCamera[i]);
                    MvApi.CameraCreateSettingPage(m_hCamera[i], this.Handle, m_DevInfo[i].acFriendlyName, null, (IntPtr)0, 0);

                    MvApi.CameraGrabber_SetRGBCallback(m_Grabber[i], m_FrameCallback[i], IntPtr.Zero);
                    MvApi.CameraGrabber_SetSaveImageCompleteCallback(m_Grabber[i], m_SaveImageComplete, IntPtr.Zero);

                    // 黑白相机设置ISP输出灰度图像
                    // 彩色相机ISP默认会输出BGR24图像
                    tSdkCameraCapbility cap;
                    MvApi.CameraGetCapability(m_hCamera[i], out cap);
                    if (cap.sIspCapacity.bMonoSensor != 0)
                    {
                        MvApi.CameraSetIspOutFormat(m_hCamera[i], (uint)MVSDK.emImageFormat.CAMERA_MEDIA_TYPE_MONO8);
                    }

                    MvApi.CameraGrabber_SetHWnd(m_Grabber[i], hDispWnds[i]);
                }
            }
            for (int i = 0; i < NumDev; ++i)
            {
                if (m_Grabber[i] != IntPtr.Zero)
                {
                    MvApi.CameraGrabber_StartLive(m_Grabber[i]);
                }
            }
        }
Ejemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            m_HDevelopExport = new HDevelopExport();
            m_HDevelopExport.InitHalcon(hWindowControl1.HalconWindow);

            m_FrameCallback     = new pfnCameraGrabberFrameCallback(CameraGrabberFrameCallback);
            m_SaveImageComplete = new pfnCameraGrabberSaveImageComplete(CameraGrabberSaveImageComplete);

            if (MvApi.CameraGrabber_CreateFromDevicePage(out m_Grabber) == CameraSdkStatus.CAMERA_STATUS_SUCCESS)
            {
                MvApi.CameraGrabber_GetCameraDevInfo(m_Grabber, out m_DevInfo);
                MvApi.CameraGrabber_GetCameraHandle(m_Grabber, out m_hCamera);
                MvApi.CameraCreateSettingPage(m_hCamera, this.Handle, m_DevInfo.acFriendlyName, null, (IntPtr)0, 0);

                MvApi.CameraGrabber_SetRGBCallback(m_Grabber, m_FrameCallback, IntPtr.Zero);
                MvApi.CameraGrabber_SetSaveImageCompleteCallback(m_Grabber, m_SaveImageComplete, IntPtr.Zero);

                MvApi.CameraGrabber_SetHWnd(m_Grabber, this.DispWnd.Handle);
                MvApi.CameraGrabber_StartLive(m_Grabber);
            }
        }