Example #1
0
        private CameraCtrlMv()
        {
            m_pDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            m_pOperator   = new CameraOperator();

            uint nBufSize = 1024 * 1024 * 50;

            pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            pBufForSave   = Marshal.AllocHGlobal((int)nSaveSize);
        }
Example #2
0
        public override bool Init(int index = 0)
        {
            bool   ret          = false;
            string serialNumber = null;

            MyCamera.MV_CC_DEVICE_INFO device;
            try
            {
                CameraOperator.EnumDevices(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);
                if (m_pDeviceList.nDeviceNum == 0)
                {
                    throw new Exception("相机未连接");
                }

                serialNumber = GetCameraSerialNumber(index);
                if (!cameraIDList.Contains(serialNumber))
                {
                    cameraIDList.Add(serialNumber);
                }

                device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
                //打开设备
                int nRet = -1;
                nRet = m_pOperator.Open(ref device);
                if (MyCamera.MV_OK != nRet)
                {
                    throw new Exception("初始化失败");
                    //return;
                }

                //设置采集连续模式
                m_pOperator.SetEnumValue("AcquisitionMode", 2);
                m_pOperator.SetEnumValue("TriggerMode", 1);
                //m_pOperator.SetPixelFormatValue(0);

                ImageCallback = new MyCamera.cbOutputdelegate(ImageOut);
                m_pOperator.RegisterImageCallBack(ImageCallback, IntPtr.Zero);

                ret = true;
            }
            catch (Exception ex)
            {
                throw new Exception(serialNumber + "初始化失败:" + ex.Message);
            }
            return(ret);
        }