Пример #1
0
        private void CameraGrabberSaveImageComplete2(
            IntPtr Grabber,
            IntPtr Image,       // 需要调用CameraImage_Destroy释放
            CameraSdkStatus Status,
            IntPtr Context)
        {
            if (Image != IntPtr.Zero)
            {
                tSdkCameraDevInfo devInfo;
                MvApi.CameraGrabber_GetCameraDevInfo(Grabber, out devInfo);

                Encoding myEncoding = Encoding.GetEncoding("utf-8");
                string   sData      = myEncoding.GetString(devInfo.acSn);
                sData = sData.TrimEnd('\0');
                sData = sData.Substring(0, 12);

                string filename = System.IO.Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory.ToString(),
                    string.Format("{0}-{1}-{2}.jpg", System.Environment.TickCount, sData, devInfo.uInstance));

                MvApi.CameraImage_SaveAsJpeg(Image, filename, 90);

                m_saveFilenames += filename + "\r\n";
                m_countFiles++;
            }
            if (m_countFiles == CAMERA_NUM)
            {
                MessageBox.Show(m_saveFilenames);
            }


            MvApi.CameraImage_Destroy(Image);
        }
Пример #2
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);
            }
        }
Пример #3
0
        private void InitCamera()
        {
            CameraSdkStatus status = 0;

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

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

            if (status == 0)
            {
                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);

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

                    // 创建灰度调色板
                    Bitmap Image = new Bitmap(1, 1, PixelFormat.Format8bppIndexed);
                    m_GrayPal = Image.Palette;
                    for (int Y = 0; Y < m_GrayPal.Entries.Length; Y++)
                    {
                        m_GrayPal.Entries[Y] = Color.FromArgb(255, Y, Y, Y);
                    }
                }

                // 设置VFlip,由于SDK输出的数据默认是从底到顶的,打开VFlip后就可以直接转换为Bitmap
                MvApi.CameraSetMirror(m_hCamera, 1, 1);

                // 为了演示如何在回调中使用相机数据创建Bitmap并显示到PictureBox中,这里不使用SDK内置的绘制操作
                //MvApi.CameraGrabber_SetHWnd(m_Grabber, this.DispWnd.Handle);

                MvApi.CameraGrabber_StartLive(m_Grabber);
            }
            else
            {
                MessageBox.Show(String.Format("打开相机失败,原因:{0}", status));
            }
        }
Пример #4
0
        private string buttonBeginRecord_GetPathName(IntPtr Grabber)
        {
            tSdkCameraDevInfo devInfo;

            MvApi.CameraGrabber_GetCameraDevInfo(Grabber, out devInfo);

            Encoding myEncoding = Encoding.GetEncoding("utf-8");
            string   sData      = myEncoding.GetString(devInfo.acSn);

            sData = sData.TrimEnd('\0');
            sData = sData.Substring(0, 12);

            string filename = System.IO.Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory.ToString(),
                string.Format("{0}-{1}-{2}.avi", System.Environment.TickCount, sData, devInfo.uInstance));

            return(filename);
        }
Пример #5
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);
            }
        }