Example #1
0
 public ImageEventArgs(Command command, Cognex.VisionPro.CogImage8Grey cameraImage, int cameraIndex, double startTime)
 {
     Command     = command;
     CameraImage = cameraImage;
     CameraIndex = cameraIndex;
     StartTime   = startTime;
 }
Example #2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run 추상객체
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public virtual bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = true)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
            } while(false);

            return(bReturn);
        }
Example #3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //추가 :
        //목적 : 라이브 시 해당 델리게이트 호출
        //설명 : 동기 호출
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void UpdateDisplayLive(int iCameraIndex, Cognex.VisionPro.CogImage8Grey objLiveImage)
        {
            CFormDisplay obj = m_objFormDisplay[iCameraIndex] as CFormDisplay;

            do
            {
                if (null == obj)
                {
                    break;
                }
                // 라이브는 바로 날림
                obj.UpdateDisplay(objLiveImage);
            } while(false);
        }
Example #4
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = true)
        {
            objResultData = null;

            return(m_objVisionLibrary.HLRun(objCogImage, out objResultData));
        }
Example #5
0
        private void OnImageGrabbed(object sender, ImageGrabbedEventArgs e)
        {
            try
            {
                if (ignoreImage)
                {
                    return;
                }


                //HOperatorSet.CountSeconds(out startTime);
                // Acquire the image from the camera. Only show the latest image. The camera may acquire images faster than the images can be displayed.

                // Get the grab result.
                IGrabResult grabResult = e.GrabResult;

                // Check if the image can be displayed.
                if (grabResult.IsValid)
                {
                    // 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();
                        width  = grabResult.Width;
                        height = grabResult.Height;
                        //if (hPylonImage != null && hPylonImage.IsInitialized())
                        //{
                        //    hPylonImage.Dispose();
                        //}
                        hPylonImage = new Cognex.VisionPro.CogImage8Grey();
                        if (grabResult.PixelTypeValue == PixelType.Mono8)
                        {
                            // while (grabResult.GrabSucceeded == false) ;
                            if (grabResult.GrabSucceeded == false)
                            {/*
                              * Util.Notify(string.Format("相机{0}数据损坏,采集失败", cameraIndex));*/
                                Trace.WriteLine("数据损坏,采集失败" + width + "." + height);
                                return;
                            }
                            if (grabResult.PayloadSize == 0)
                            {/*
                              * Util.Notify(string.Format("相机{0}数据损坏,图像包大小为0", cameraIndex));*/
                                return;
                            }


                            //Util.Notify(string.Format("相机{0}数据尺寸{1}", cameraIndex, grabResult.PayloadSize));
                            //allocate the m_stream_size amount of bytes in non-managed environment
                            if (m_latestFrameAddress == IntPtr.Zero)
                            {
                                m_latestFrameAddress = Marshal.AllocHGlobal((Int32)grabResult.PayloadSize);
                            }
                            g_converter.OutputPixelFormat = PixelType.Mono8;
                            g_converter.Convert(m_latestFrameAddress, grabResult.PayloadSize, grabResult);

                            byte[] ImagebufferPtr = new byte[grabResult.Width * grabResult.Height];

                            //转换为Halcon图像显示
                            //hPylonImage.Get8GreyPixelMemory( Cognex.VisionPro.CogImageDataModeConstants.Read,);
                            Marshal.Copy(m_latestFrameAddress, ImagebufferPtr, 0, grabResult.Width * grabResult.Height - 1);


                            var cogRoot = new Cognex.VisionPro.CogImage8Root();
                            cogRoot.Initialize(grabResult.Width, grabResult.Height, m_latestFrameAddress, grabResult.Width, null);
                            hPylonImage.SetRoot(cogRoot);
                            //hPylonImage.GenImage1("byte", grabResult.Width, grabResult.Height, m_latestFrameAddress);
                        }
                        else if (grabResult.PixelTypeValue == PixelType.BayerBG8 || grabResult.PixelTypeValue == PixelType.BayerGB8)
                        {
                            //allocate the m_stream_size amount of bytes in non-managed environment
                            if (m_latestFrameAddress == IntPtr.Zero)
                            {
                                m_latestFrameAddress = Marshal.AllocHGlobal((Int32)(3 * g_camera.Parameters[PLCamera.PayloadSize].GetValue()));
                            }
                            g_converter.OutputPixelFormat = PixelType.BGR8packed;
                            g_converter.Convert(m_latestFrameAddress, 3 * grabResult.PayloadSize, grabResult);

                            /*hPylonImage.GenImageInterleaved(m_latestFrameAddress, "bgr",
                             *       grabResult.Width, grabResult.Height, -1, "byte", grabResult.Width, grabResult.Height, 0, 0, -1, 0);
                             */
                        }
                        else
                        {/*
                          * Util.Notify(string.Format("相机{0}编码格式不正确", cameraIndex));*/
                        }
                        Trace.WriteLine("采集成功" + width + "." + height);
                        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));*/
            }
            finally
            {
                // Dispose the grab result if needed for returning it to the grab loop.
                e.DisposeGrabResultIfClone();
            }
        }
Example #6
0
        private void SaveImage(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO pFrameInfo, IntPtr pUser)
        {
            try
            {
                if (ignoreImage)
                {
                    return;
                }

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

                // Reduce the number of displayed images to a reasonable amount if the camera is acquiring images very fast.
                //if (!stopWatch.IsRunning || stopWatch.ElapsedMilliseconds > 10)
                {
                    //stopWatch.Restart();

                    //if (hPylonImage != null && hPylonImage.IsInitialized())
                    //{
                    //    hPylonImage.Dispose();
                    //}
                    hPylonImage = new Cognex.VisionPro.CogImage8Grey();

                    if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
                    {
                        //hPylonImage.GenImage1("byte", pFrameInfo.nWidth, pFrameInfo.nHeight, pData);
                        var cogRoot = new Cognex.VisionPro.CogImage8Root();



                        uint buffersize = new uint();


                        // m_pOperator.GetIntValue("PayloadSize",ref buffersize);



                        //byte[] ImagebufferPtr = new byte[pFrameInfo.nWidth * pFrameInfo.nHeight];
                        //var pBufForDriver = Marshal.AllocHGlobal((Int32)(buffersize));



                        //Marshal.Copy(pBufForDriver, ImagebufferPtr, 0, pFrameInfo.nWidth * pFrameInfo.nHeight - 1);

                        cogRoot.Initialize(pFrameInfo.nWidth, pFrameInfo.nHeight, pData, pFrameInfo.nWidth, null);

                        hPylonImage.SetRoot(cogRoot);
                        GC.Collect();
                        //Marshal.FreeHGlobal(pBufForDriver);


                        /*
                         * MyCamera.MV_FRAME_OUT info = new MyCamera.MV_FRAME_OUT();
                         * var stDevInfo = (MyCamera.MV_FRAME_OUT)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_FRAME_OUT));*/
                    }
                    else if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
                    {/*
                      * hPylonImage.GenImageInterleaved(pData,
                      * "rgb",
                      *  pFrameInfo.nWidth, pFrameInfo.nHeight,
                      * -1, "byte",
                      * pFrameInfo.nWidth, pFrameInfo.nHeight,
                      * 0, 0, -1, 0);*/
                    }
                    else
                    {/*
                      * Util.Notify(string.Format("相机{0}编码格式不正确,当前格式{1}", cameraIndex, pFrameInfo.enPixelType));*/
                    }
                    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));*/
            }
        }
Example #7
0
            public void Init()
            {
                iInspectionPosition                    = 0;
                eResult                                = CDefine.enumResult.RESULT_NG;
                strCellID                              = "";
                strTriggerTime                         = "";
                strTactTime                            = "";
                objInputGrabImage                      = null;
                objOutputGrabImage                     = null;
                objVidiResult                          = new List <CDefine.enumResult>();
                objMeasureResult                       = new List <CDefine.enumResult>();
                objMeasureResult3DWidth                = new List <CDefine.enumResult>();
                objPMSImage                            = new List <Cognex.VisionPro.CogImage8Grey>();
                objPMSImageMeasure                     = new List <Cognex.VisionPro.CogImage8Grey>();
                objInputGrabOriginImage                = new List <Cognex.VisionPro.CogImage8Grey>();
                objInputGrabOriginalImageBitmap        = new List <Bitmap>();
                objInputGrabOriginImageVIDI            = new List <Cognex.VisionPro.CogImage8Grey>();
                objInputGrabOriginalImageBitmapVIDI    = new List <Bitmap>();
                objInputGrabOriginImageMeasure         = new List <Cognex.VisionPro.CogImage8Grey>();
                objInputGrabOriginalImageBitmapMeasure = new List <Bitmap>();
                objPMSImageBitmap                      = new List <Bitmap>();
                objPMSImageBitmapMeasure               = new List <Bitmap>();
                objCropImageVidi                       = new List <Cognex.VisionPro.CogImage8Grey>();
                objCropImageBitmapVidi                 = new List <Bitmap>();
                objCropImageMeasure                    = new List <Cognex.VisionPro.CogImage8Grey>();
                objCropImageBitmapMeasure              = new List <Bitmap>();
                objCropImageMeasureSecond              = new List <Cognex.VisionPro.CogImage8Grey>();
                objCropImageBitmapMeasureSecond        = new List <Bitmap>();
                dListMeasureSizeWidth                  = new List <double>();
                dListMeasureSizeHeight                 = new List <double>();
                objMeasureRegion                       = new List <structureDataRegionMeasure>();
                objMeasureLine                         = new List <structureDataLineMeasure>();
                objVidiResultImage                     = new List <Cognex.VisionPro.CogImage8Grey>();
                objVidiResultOverlayGraphic            = new List <Cognex.VisionPro.CogImage8Grey>();
                obj3DResultOverlayGraphic              = new List <Cognex.VisionPro.CogImage8Grey>();
                objMeasureAreaRect                     = new List <List <Rectangle> >();
                objMeasureAreaValue                    = new List <List <double> >();
                objVidiScore                           = new List <double>();
                objVidiTactTime                        = new List <string>();
                objMeasureTactTime                     = new List <string>();

                i3DImageWidth  = 0;
                i3DImageHeight = 0;
                i3DResolutionX = 0;
                i3DResolutionY = 0;
                i3DResolutionZ = 0;
                i3DOffsetZ     = 0;
                obj3DHeghtThresholdOverCount = new List <int>();
                obj3DImageHeight             = new Cognex.VisionPro.CogImage8Grey();
                obj3DImageIntensity          = new Cognex.VisionPro.CogImage8Grey();
                obj3DImage                       = new List <Cognex.VisionPro.CogImage8Grey>();
                obj3DImageBitmap                 = new List <Bitmap>();
                obj3DImageHeightBitmap           = new Bitmap(10, 10);
                obj3DImageIntensityBitmap        = new Bitmap(10, 10);
                obj3DRegionData                  = new List <structureDataRegion3D>();
                obj3DResultHeightData            = new List <double[, ]>();
                obj3DListHeightOverBlobCountHigh = new List <int>();
                obj3DListHeightOverBlobCountLow  = new List <int>();
                obj3DListWeldWidth               = new List <double>();
                obj3DListSampleHeightData        = new List <double> [CDefine.DEF_MAX_COUNT_CROP_REGION];
                dPatternPositionX                = 0;
                dPatternPositionY                = 0;

                for (int iLoopCount = 0; iLoopCount < 4; iLoopCount++)
                {
                    objInputGrabOriginImage.Add(new Cognex.VisionPro.CogImage8Grey());
                    objInputGrabOriginalImageBitmap.Add(new Bitmap(10, 10));
                    objInputGrabOriginImageVIDI.Add(new Cognex.VisionPro.CogImage8Grey());
                    objInputGrabOriginalImageBitmapVIDI.Add(new Bitmap(10, 10));
                    objInputGrabOriginImageMeasure.Add(new Cognex.VisionPro.CogImage8Grey());
                    objInputGrabOriginalImageBitmapMeasure.Add(new Bitmap(10, 10));
                    objPMSImage.Add(new Cognex.VisionPro.CogImage8Grey());
                    objPMSImageBitmap.Add(new Bitmap(10, 10));
                    objPMSImageMeasure.Add(new Cognex.VisionPro.CogImage8Grey());
                    objPMSImageBitmapMeasure.Add(new Bitmap(10, 10));
                    obj3DImage.Add(new Cognex.VisionPro.CogImage8Grey());
                    obj3DImageBitmap.Add(new Bitmap(10, 10));
                }

                for (int iLoopCount = 0; iLoopCount < CDefine.DEF_MAX_COUNT_CROP_REGION; iLoopCount++)
                {
                    structureDataRegion3D objData = new structureDataRegion3D();
                    objData.obj3DListNGPositionX          = new List <int>();
                    objData.obj3DListNGPositionY          = new List <int>();
                    obj3DListSampleHeightData[iLoopCount] = new List <double>();
                    obj3DRegionData.Add(objData);
                }

                iIndexDisplayOriginalImage = 0;
            }