Example #1
0
        // Snap
        //    Acquire image(s)
        //
        private bool Snap()
        {
            // Check if the transfer object is available
            if (m_pXfer == null || !m_pXfer.Initialized)
            {
                return(false);
            }

            for (int iFrame = 0; iFrame < m_pLocalBuffer.Count; iFrame++)
            {
                // Acquire one image
                m_pXfer.Snap();

                // Wait until the acquired image has been transferred into system memory
                AbortDlg abort = new AbortDlg(m_pXfer);
                if (abort.ShowDialog() != DialogResult.OK)
                {
                    m_pXfer.Abort();
                    return(false);
                }

                //Add a short delay to ensure the transfer callback has time to arrive
                System.Threading.Thread.Sleep(100);

                if (m_pLocalBuffer != null)
                {
                    m_pLocalBuffer.Index = iFrame;
                    m_pLocalBuffer.Copy(m_pBuffer);
                }
            }
            return(true);
        }
Example #2
0
        private void UpdateView()
        {
            if (m_pColorConv.Enabled)
            {
                // Check if we are operating on-line
                if (m_pXfer != null && m_pXfer.Initialized)
                {
                    // Check if we are grabbing
                    if (m_pXfer.Grabbing)
                    {
                        // The view will be automatically updated on the next acquired frame
                        return;
                    }

                    // Check if we are using an hardware color decoder
                    if (m_pColorConv.HardwareEnabled)
                    {
                        // Acquire one frame
                        m_pXfer.Snap();
                        return;
                    }
                }

                // Else, apply color conversion to current buffer's content
                if (m_pPro != null)
                {
                    m_pPro.Execute();
                }
                else
                {
                    m_pColorConv.Convert();
                    if (m_pImageWnd != null)
                    {
                        // Redraw the color decoded image
                        m_pImageWnd.Refresh();
                    }
                }
            }
        }
Example #3
0
        static bool AutoWhiteBalanceOperations(SapAcqDevice Camera, SapBuffer Buffers, SapTransfer Transfer)
        {
            Console.WriteLine("\nCalibration in progress ...........\n\n");

            double coefBlueGain         = MAX_COEF + 1;
            double coefGreenGain        = MAX_COEF + 1;
            double coefRedGain          = MAX_COEF + 1;
            int    calibrationIteration = 0;

            // Create a new Bayer object
            SapBayer   Bayer       = new SapBayer(Buffers);
            SapFeature FeatureInfo = new SapFeature(Camera.Location);

            if (!FeatureInfo.Create())
            {
                DestroysFeaturesAndBayer(FeatureInfo, Bayer);
                return(false);
            }

            // Create Bayer object
            if (!Bayer.Create())
            {
                DestroysFeaturesAndBayer(FeatureInfo, Bayer);
                return(false);
            }

            // Initialize all Gain colors to 0
            Camera.SetFeatureValue("GainBlue", 0);
            Camera.SetFeatureValue("GainGreen", 0);
            Camera.SetFeatureValue("GainRed", 0);

            // Choose alignment used
            Bayer.Align = SapBayer.AlignMode.RGGB;

            // Definition of ROI used for calibration
            int fixSelectedRoiLeft = 0;
            int fixSelectedRoiTop  = 0;
            // Half buffer width
            int fixSelectedRoiWidth = Buffers.Width / 2;
            // Half buffer height
            int fixSelectedRoiHeight = Buffers.Height / 2;

            // Start loop for calibration until each coefficient is under 1.05
            while (coefBlueGain > MAX_COEF || coefGreenGain > MAX_COEF || coefRedGain > MAX_COEF)
            {
                if (!Transfer.Snap())
                {
                    Console.WriteLine("Unable to acquire an image");
                    return(false);
                }

                Thread.Sleep(500);
                // Call WhiteBalance function
                if (!Bayer.WhiteBalance(Buffers, fixSelectedRoiLeft, fixSelectedRoiTop, fixSelectedRoiWidth, fixSelectedRoiHeight))
                {
                    break;
                }

                // New coefficients values are reused.
                coefBlueGain  = Bayer.WBGain.Blue;
                coefGreenGain = Bayer.WBGain.Green;
                coefRedGain   = Bayer.WBGain.Red;

                if (coefRedGain > MAX_COEF)
                {
                    if (!ComputeGain("GainRed", Camera, FeatureInfo, coefRedGain))
                    {
                        break;
                    }
                }
                if (coefGreenGain > MAX_COEF)
                {
                    if (!ComputeGain("GainGreen", Camera, FeatureInfo, coefGreenGain))
                    {
                        break;
                    }
                }
                if (coefBlueGain > MAX_COEF)
                {
                    if (!ComputeGain("GainBlue", Camera, FeatureInfo, coefBlueGain))
                    {
                        break;
                    }
                }

                if (calibrationIteration >= MAX_CALIBRATION_ITERATION)
                {
                    Console.WriteLine("Iterations for calibration are at the maximum.\n");
                    break;
                }
                calibrationIteration++;
            }

            // Uncomment this part if you want to get new values after calibration.

            /*
             * int gainBlue=0, gainRed=0, gainGreen=0;
             * Camera.GetFeatureValue("GainBlue", out gainBlue);
             * Camera.GetFeatureValue("GainRed", out gainRed);
             * Camera.GetFeatureValue("GainGreen", out gainGreen);
             */

            DestroysFeaturesAndBayer(FeatureInfo, Bayer);
            Console.WriteLine("\nCalibration finished ...........\n\n");
            return(true);
        }