Example #1
0
        int StreamCB(ref MVAPI.IMAGE_INFO pInfo, IntPtr UserVal)
        {
            MVGigE.MVInfo2Image(m_hCam, ref pInfo, m_hImage);
            try
            {
                if (ignoreImage)
                {
                    return(0);
                }

                //HTuple startTime;
                HOperatorSet.CountSeconds(out startTime);

                // Check if the image can be displayed.
                if (m_hImage != IntPtr.Zero)
                {
                    // Reduce the number of displayed images to a reasonable amount if the camera is acquiring images very fast.
                    //if (!stopWatch.IsRunning || stopWatch.ElapsedMilliseconds > 33)
                    {
                        //stopWatch.Restart();

                        //if (hPylonImage != null && hPylonImage.IsInitialized())
                        //{
                        //    hPylonImage.Dispose();
                        //}
                        hPylonImage = new HImage();
                        if (m_PixelFormat == MVAPI.MV_PixelFormatEnums.PixelFormat_Mono8)
                        {
                            //Util.Notify(string.Format("相机{0}数据尺寸{1}", cameraIndex, grabResult.PayloadSize));
                            //allocate the m_stream_size amount of bytes in non-managed environment

                            //转换为Halcon图像显示
                            hPylonImage.GenImage1("byte", m_nWidth, m_nHeight, m_hImage);
                        }
                        else if (m_PixelFormat == MVAPI.MV_PixelFormatEnums.PixelFormat_BayerRG8)
                        {
                            hPylonImage.GenImageInterleaved(m_hImage, "bgr",
                                                            m_nWidth, m_nHeight, -1, "byte", m_nWidth, m_nHeight, 0, 0, -1, 0);
                        }
                        else
                        {
                            Util.Notify(string.Format("相机{0}编码格式不正确", cameraIndex));
                        }
                        TrigerImageEvent();
                    }
                }
            }
            catch (System.ArgumentException ex)
            {
                Util.WriteLog(this.GetType(), ex);
                Util.Notify(string.Format("相机{0}图像数据包丢失", cameraIndex));
            }
            catch (Exception ex)
            {
                Util.WriteLog(this.GetType(), ex);
                Util.Notify(string.Format("相机{0}图像数据返回出现异常", cameraIndex));
            }
            return(0);
        }
Example #2
0
 public static extern MVSTATUS_CODES MVInfo2Image(IntPtr hCam, ref MVAPI.IMAGE_INFO pInfo, IntPtr pImage);