Ejemplo n.º 1
0
        private void LogMessage(LogTypes messageType, String str)
        {
            String message = "";

            // Message header
            switch (messageType)
            {
            case LogTypes.Error:
                message = "[Err] ";
                break;

            case LogTypes.Warning:
                message = "[Wrn] ";
                break;

            case LogTypes.Info:
                message = "[Msg] ";
                break;
            }

            message += str;
            LogMessageBox.BeginUpdate();
            LogMessageBox.Items.Add(message);
            LogMessageBox.EndUpdate();
        }
Ejemplo n.º 2
0
        private void button_Acq_Dark_Click(object sender, EventArgs e)
        {
            int nbImagesUsed = m_pFlatField.CorrectionType == SapFlatField.ScanCorrectionType.Field ? int.Parse(textBox_Frame_Avg.Text) : 1;

            // Set correction type
            m_pFlatField.CorrectionType = m_CorrectionType;

            // Set video type
            m_pFlatField.SetVideoType(m_VideoType, SapBayer.AlignMode.BGGR);

            // Set maximum deviation from average pixel value for dark image
            m_pFlatField.DeviationMaxBlack = int.Parse(textBox_Max_Dev.Text);

            // Set number of lines to average and vertical offset
            m_pFlatField.NumLinesAverage = int.Parse(textBox_Line_Avg.Text);
            m_pFlatField.VerticalOffset  = int.Parse(textBox_Vert_Offset.Text);

            // Set wether to declare pixels with clipped coefficient as defective
            m_pFlatField.ClippedGainOffsetDefects = ClippedCoefsDefects_checkbox.Checked;

            //Multi flat-field not implemented in .NET
            // Set calibration index
            //m_pFlatField->SetIndex(m_CalibrationIndex);

            LogMessageBox.ResetText();

            if (m_pXfer != null && m_pXfer.Initialized)
            {
                m_pLocalBuffer = new SapBuffer(nbImagesUsed, m_pBuffer, SapBuffer.MemoryType.Default);
                m_pLocalBuffer.Create();

                // Acquire an image
                if (!Snap())
                {
                    LogMessage(LogTypes.Error, "Unable to acquire an image");
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }
            }
            else
            {
                // Load an image

                m_pLocalBuffer = new SapBuffer(1, m_pBuffer, SapBuffer.MemoryType.Default);
                m_pLocalBuffer.Create();

                LoadSaveDlg dlg = new LoadSaveDlg(null, true, false);
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }

                String path = dlg.PathName;

                // Create a temporary buffer in order to know the selected file's native format and pixel depth

                SapBuffer loadBuffer = new SapBuffer(path, SapBuffer.MemoryType.Default);
                loadBuffer.Create();

                if (loadBuffer.Format != m_pBuffer.Format || loadBuffer.PixelDepth != m_pBuffer.PixelDepth)
                {
                    LogMessage(LogTypes.Warning, "Image file has a different format than expected.  Pixel values may get shifted.");
                }

                if (loadBuffer.Width != m_pBuffer.Width || loadBuffer.Height != m_pBuffer.Height)
                {
                    LogMessage(LogTypes.Error, "Image file selected doesn't have same dimensions as buffer.");
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }

                //loadBuffer.Load(path,1);
                m_pLocalBuffer.Copy(loadBuffer);

                String str;
                str = String.Format("Loaded dark image: {}", path);
                LogMessage(LogTypes.Info, str);
            }
            DarkImage();
        }