Esempio n. 1
0
        private void UpdateImageData(IBaseData objIBaseData)
        {
            try
            {
                GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                if (null != objIBaseData)
                {
                    emValidBits = DahengHelper.GetBestValidBit(objIBaseData.GetPixelFormat());
                    if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                    {
                        if (isColor)
                        {
                            IntPtr buffer = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, true);
                            FillRGB24(buffer);
                        }
                        else
                        {
                            IntPtr buffer = objIBaseData.GetBuffer();
                            FillY800(buffer);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            waitHandle.Set();
        }
Esempio n. 2
0
        /// <summary>
        /// 存储图像
        /// </summary>
        /// <param name="objIBaseData">图像数据对象</param>
        /// <param name="strFilePath">显示图像文件名</param>
        public void SaveBmp(IBaseData objIBaseData, string strFilePath)
        {
            GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;

            //检查图像是否改变并更新Buffer
            __UpdateBufferSize(objIBaseData);

            if (null != objIBaseData)
            {
                emValidBits = __GetBestValudBit(objIBaseData.GetPixelFormat());
                if (m_bIsColor)
                {
                    IntPtr pBufferColor = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
                    Marshal.Copy(pBufferColor, m_byColorBuffer, 0, __GetStride(m_nWidth, m_bIsColor) * m_nHeigh);
                    __UpdateBitmapForSave(m_byColorBuffer);
                }
                else
                {
                    IntPtr pBufferMono = IntPtr.Zero;
                    if (__IsPixelFormat8(objIBaseData.GetPixelFormat()))
                    {
                        pBufferMono = objIBaseData.GetBuffer();
                    }
                    else
                    {
                        pBufferMono = objIBaseData.ConvertToRaw8(emValidBits);
                    }
                    Marshal.Copy(pBufferMono, m_byMonoBuffer, 0, __GetStride(m_nWidth, m_bIsColor) * m_nHeigh);

                    __UpdateBitmapForSave(m_byMonoBuffer);
                }
                m_bitmapForSave.Save(strFilePath, ImageFormat.Bmp);
            }
        }
Esempio n. 3
0
        public HObject Show(IBaseData objIBaseData)
        {
            GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;

            if (null != objIBaseData)
            {
                emValidBits = GetBestValudBit(objIBaseData.GetPixelFormat());
                if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                {
                    IntPtr pBufferMono = IntPtr.Zero;
                    if (IsPixelFormat8(objIBaseData.GetPixelFormat()))
                    {
                        pBufferMono = objIBaseData.GetBuffer();
                    }
                    else
                    {
                        pBufferMono = objIBaseData.ConvertToRaw8(emValidBits);
                    }
                    Marshal.Copy(pBufferMono, m_byMonoBuffer, 0, nWidth * nHeigh);

                    unsafe
                    {
                        fixed(byte *p = m_byMonoBuffer)
                        {
                            HOperatorSet.GenEmptyObj(out HObject image);
                            image.Dispose();
                            HOperatorSet.GenImage1(out image, "byte", nWidth, nHeigh, new IntPtr(p));
                            return(image);
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// 图像采集到事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StreamGrabber_ImageGrabbed(object objUserParam, IFrameData objIFrameData)
        {
            try
            {
                if (HoImage != null &&
                    HoImage.IsInitialized())
                {
                    HoImage.Dispose();
                    HoImage = null;
                    //System.Threading.Thread.Sleep(10);
                    //System.GC.Collect();
                    //System.GC.WaitForPendingFinalizers();
                    IsImageGrabbed = false;
                }
                int width  = (int)objIFrameData.GetWidth();
                int height = (int)objIFrameData.GetHeight();

                #region 相机SDK内部像素格式转换
                IntPtr            pBuffer;
                GX_VALID_BIT_LIST emValidBits = __GetBestValudBit(objIFrameData.GetPixelFormat());
                if (_IsColorMode)
                {//彩色
                    //不需要释放指针空间
                    pBuffer = objIFrameData.ConvertToRGB24(emValidBits
                                                           , GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
                    HOperatorSet.GenImageInterleaved(out HoImage, new HTuple(pBuffer), "bgr",
                                                     width, height, new HTuple(-1),
                                                     "byte", width, height, 0, 0, -1, 0);
                }
                else
                {//黑白
                    if (__IsPixelFormat8(objIFrameData.GetPixelFormat()))
                    {
                        pBuffer = objIFrameData.GetBuffer();
                    }
                    else
                    {
                        //不需要释放指针空间
                        pBuffer = objIFrameData.ConvertToRaw8(emValidBits);
                    }
                    HOperatorSet.GenImage1(out HoImage, "byte", width, height, new HTuple(pBuffer));
                }

                if (HoImage != null &&
                    HoImage.IsInitialized())
                {
                    IsImageGrabbed = true;
                    if (CameraImageGrabbedEvt != null)
                    {
                        CameraImageGrabbedEvt(Camera, HoImage);
                    }
                }
            }
            catch (Exception ex)
            { }
            finally
            {
            }
            #endregion
        }
Esempio n. 5
0
        /// <summary>
        /// 通过GX_PIXEL_FORMAT_ENTRY获取最优Bit位
        /// </summary>
        /// <param name="em">图像数据格式</param>
        /// <returns>最优Bit位</returns>
        private GX_VALID_BIT_LIST __GetBestValudBit(GX_PIXEL_FORMAT_ENTRY emPixelFormatEntry)
        {
            GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;

            switch (emPixelFormatEntry)
            {
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG8:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG10:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_2_9;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG12:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_4_11;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO14:
            {
                //暂时没有这样的数据格式待升级
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG16:
            {
                //暂时没有这样的数据格式待升级
                break;
            }

            default:
                break;
            }
            return(emValidBits);
        }
Esempio n. 6
0
        private const uint GX_PIXEL_8BIT     = 0x00080000;                    ///<8 bit data image format

        /// <summary>
        /// Get the best 8 bit by GX_PIXEL_FORMAT_ENTRY
        /// </summary>
        /// <param name="em">image format</param>
        /// <returns>best bit bit</returns>
        public static GX_VALID_BIT_LIST GetBestValidBit(GX_PIXEL_FORMAT_ENTRY emPixelFormatEntry)
        {
            GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;

            switch (emPixelFormatEntry)
            {
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB8:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG8:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB10:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG10:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_2_9;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB12:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG12:
            {
                emValidBits = GX_VALID_BIT_LIST.GX_BIT_4_11;
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO14:
            {
                //There is no such data format to be upgraded
                break;
            }

            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_MONO16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GR16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_RG16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_GB16:
            case GX_PIXEL_FORMAT_ENTRY.GX_PIXEL_FORMAT_BAYER_BG16:
            {
                //There is no such data format to be upgraded
                break;
            }

            default:
                break;
            }
            return(emValidBits);
        }
Esempio n. 7
0
        private void UpdateImageData(IBaseData objIBaseData)
        {
            try
            {
                GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                if (null != objIBaseData)
                {
                    emValidBits = DahengHelper.GetBestValidBit(objIBaseData.GetPixelFormat());
                    if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                    {
                        if (isColor)
                        {
                            if (currentStreamFormat == DahengStreamFormat.RGB)
                            {
                                IntPtr buffer = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, true);
                                FillRGB24(buffer);
                            }
                            else if (currentStreamFormat == DahengStreamFormat.Raw)
                            {
                                IntPtr bufferRaw = objIBaseData.ConvertToRaw8(emValidBits);
                                FillY800(bufferRaw);
                            }
                        }
                        else
                        {
                            IntPtr buffer = objIBaseData.GetBuffer();
                            FillY800(buffer);

                            //IntPtr pBufferMono = IntPtr.Zero;
                            //if (IsPixelFormat8(objIBaseData.GetPixelFormat()))
                            //{
                            //    pBufferMono = objIBaseData.GetBuffer();
                            //}
                            //else
                            //{
                            //    pBufferMono = objIBaseData.ConvertToRaw8(emValidBits);
                            //}

                            //Marshal.Copy(pBufferMono, m_byMonoBuffer, 0, width * height);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 用于显示图像
        /// </summary>
        /// <param name="objIBaseData">图像数据对象</param>
        public void Show(IBaseData objIBaseData)
        {
            GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;

            //检查图像是否改变并更新Buffer
            __UpdateBufferSize(objIBaseData);


            if (null != objIBaseData)
            {
                emValidBits = __GetBestValudBit(objIBaseData.GetPixelFormat());
                if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                {
                    if (m_bIsColor)
                    {
                        IntPtr pBufferColor = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
                        Marshal.Copy(pBufferColor, m_byColorBuffer, 0, __GetStride(m_nWidth, m_bIsColor) * m_nHeigh);
                        __ShowImage(m_byColorBuffer);
                    }
                    else
                    {
                        IntPtr pBufferMono = IntPtr.Zero;
                        if (__IsPixelFormat8(objIBaseData.GetPixelFormat()))
                        {
                            pBufferMono = objIBaseData.GetBuffer();
                        }
                        else
                        {
                            pBufferMono = objIBaseData.ConvertToRaw8(emValidBits);
                        }
                        Marshal.Copy(pBufferMono, m_byMonoBuffer, 0, __GetStride(m_nWidth, m_bIsColor) * m_nHeigh);

                        __ShowImage(m_byMonoBuffer);
                    }
                }
            }
        }