예제 #1
0
        public Bitmap GetBitmap()
        {
            m_objIGXStream.FlushQueue();
            m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute();
            IImageData objIImageData = GetImage(500);
            var        bm            = m_objGxBitmap.GetBitmap(objIImageData);

            objIImageData.Destroy();
            return((Bitmap)bm.Clone());
        }
예제 #2
0
        public override bool DoSoftTriggerOnce()
        {
            try
            {
                if (m_objIGXDevice == null || m_objIGXStream == null)
                {
                    ////ErrorMessage.Append("还没有打开设备。");
                    return(false);
                }
                //每次发送触发命令之前清空采集输出队列
                //防止库内部缓存帧,造成本次GXGetImage得到的图像是上次发送触发得到的图
                m_objIGXStream.FlushQueue();

                IGXFeatureControl fc = m_objIGXDevice.GetRemoteFeatureControl();
                if (fc == null)
                {
                    ////ErrorMessage.Append("获取设备控制器异常。");
                    return(false);
                }
                //发送软触发命令
                fc.GetCommandFeature("TriggerSoftware").Execute();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #3
0
 public void OnFrameCallbackFun(object obj, IFrameData objIFrameData)
 {
     if (objIFrameData.GetStatus() == GxIAPINET.GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS)
     {
         Mat    img          = null;
         IntPtr pRGB24Buffer = IntPtr.Zero;
         int    size         = (int)objIFrameData.GetHeight() * (int)objIFrameData.GetWidth() * 3;
         byte[] imgdata      = new byte[size];
         pRGB24Buffer = objIFrameData.ConvertToRGB24(GxIAPINET.GX_VALID_BIT_LIST.GX_BIT_0_7, GxIAPINET.GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, true);
         Marshal.Copy(pRGB24Buffer, imgdata, 0, imgdata.Length);
         img = new Mat((int)objIFrameData.GetHeight(), (int)objIFrameData.GetWidth(), MatType.CV_8UC3, imgdata);
         Cv2.Flip(img, img, 0);
         camera_img = img;
         objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
         objIGXStream.FlushQueue();
     }
 }
예제 #4
0
        public Bitmap GetBitmap()
        {
            try
            {
                IImageData objIImageData = null;
                uint       nTimeout      = 500;


                //每次发送触发命令之前清空采集输出队列
                //防止库内部缓存帧,造成本次GXGetImage得到的图像是上次发送触发得到的图
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.FlushQueue();
                }

                //发送软触发命令
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute();
                }

                //获取图像
                if (null != m_objIGXStream)
                {
                    objIImageData = m_objIGXStream.GetImage(nTimeout);
                }
                var bm = m_objGxBitmap.GetBitmap(objIImageData);
                if (null != objIImageData)
                {
                    //用完之后释放资源
                    objIImageData.Destroy();
                }
                return((Bitmap)bm.Clone());
            }
            catch (Exception ex)
            {
                Tool.AppLogError(ex);
                //MessageBox.Show(ex.Message);
            };
            return(null);
        }
예제 #5
0
        private void Snapshot_Click(object sender, EventArgs e)
        {
            try
            {
                //1.Open Device
                // Before using any GxIAPINET methods, the GxIAPINET must be initialized.
                m_objIGXFactory = IGXFactory.GetInstance();
                m_objIGXFactory.Init();

                //open device
                List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>();

                // Close stream
                __CloseStream();

                // If the device is opened then close it to ensure the camera could open again.
                __CloseDevice();

                // Enumerate all camera devices
                m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);

                // Check if found any device
                if (listGXDeviceInfo.Count <= 0)
                {
                    MessageBox.Show("No devices found!");
                    return;
                }

                //Open the first found device
                m_objIGXDevice         = m_objIGXFactory.OpenDeviceBySN(listGXDeviceInfo[0].GetSN(), GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();


                // Open stream
                if (null != m_objIGXDevice)
                {
                    m_objIGXStream = m_objIGXDevice.OpenStream(0);
                }

                // It is recommended that the user set the camera's stream channel packet length value
                // according to the current network environment after turning on
                // the network camera to improve the collection performance of the network camera.
                // For the setting method, refer to the following code.
                GX_DEVICE_CLASS_LIST objDeviceClass = m_objIGXDevice.GetDeviceInfo().GetDeviceClass();
                if (GX_DEVICE_CLASS_LIST.GX_DEVICE_CLASS_GEV == objDeviceClass)
                {
                    // Determine whether the device supports the stream channel packet function.
                    if (true == m_objIGXFeatureControl.IsImplemented("GevSCPSPacketSize"))
                    {
                        // Get the optimal packet length value of the current network environment
                        uint nPacketSize = m_objIGXStream.GetOptimalPacketSize();
                        // Set the optimal packet length value to the stream channel packet length of the current device.
                        m_objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(nPacketSize);
                    }
                }

                __InitDevice();

                m_objGxBitmap = new GxBitmap(m_objIGXDevice, m_pic_ShowImage);



                //2.Start acquisition
                // Start stream channel acquisition
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StartGrab();
                }

                // Send AcquisitionStart command
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("AcquisitionStart").Execute();
                }



                //3.Snapshot
                IImageData objIImageData = null;
                double     dElapsedtime  = 0;
                uint       nTimeout      = 500;


                //Flush image queues to clear out-of-date images
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.FlushQueue();
                }

                //Send TriggerSoftware commands
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute();
                }

                //Get image
                if (null != m_objIGXStream)
                {
                    //Start stopwatch
                    m_objStopTime.Start();

                    objIImageData = m_objIGXStream.GetImage(nTimeout);

                    //Stop stopwatch and get the ElapsedTime
                    dElapsedtime = m_objStopTime.Stop();
                }

                m_objGxBitmap.Show(objIImageData);
                string strFileName = @"D:\TestImages\SWS.bmp";
                m_objGxBitmap.SaveBmp(objIImageData, strFileName);


                if (null != objIImageData)
                {
                    // Release resource
                    objIImageData.Destroy();
                }

                //4.Stop acquisition
                // Send AcquisitionStop command
                if (null != m_objIGXFeatureControl)
                {
                    m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute();
                }

                // Stop stream channel acquisition
                if (null != m_objIGXStream)
                {
                    m_objIGXStream.StopGrab();
                }

                //5.Close device
                // Reset statistical time count
                m_objStatistic.Reset();

                // close stream and device
                __CloseAll();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }