Ejemplo n.º 1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            //************整个的处理******************//
            string    picpath   = "E:\\pic\\7.jpg";
            SapBuffer picbuffer = null;

            picbuffer = new SapBuffer(picpath, SapBuffer.MemoryType.Default);
            picbuffer.Create();
            picbuffer.Load(picpath, -1);

            IntPtr BufAddress;

            picbuffer.GetAddress(out BufAddress);
            mChipDetection.ProcessImage(BufAddress, (uint)picbuffer.Width, (uint)picbuffer.Height);

            lblwordx.Text = mChipDetection.realworldx.ToString();
            lblwordy.Text = mChipDetection.realworldy.ToString();
        }
Ejemplo n.º 2
0
        //
        // Step 2: Snap a bright image to calculate the gain coefficients
        //
        private void button_Acq_Bright_Click(object sender, EventArgs e)
        {
            int nbImagesUsed = m_pFlatField.CorrectionType == SapFlatField.ScanCorrectionType.Field ? int.Parse(textBox_Frame_Avg.Text) : 1;

            // Set maximum deviation from average pixel value for bright image
            m_pFlatField.DeviationMaxWhite = 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;

            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 bright image: '{0}'", path);
                LogMessage(LogTypes.Info, str);
            }

            BrightImage();
        }