Exemplo n.º 1
0
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                    m_objFixtureTool.InputImage = objCogImage;
                    // 여기에 패턴에서 찾은 좌표를 넣어야하는데..

                    m_objFixtureTool.Run();
                    CogImage8Grey objResultImage = ( CogImage8Grey )m_objFixtureTool.OutputImage;
                    if (null == objResultImage)
                    {
                        objResultData.objCogImage = objCogImage;
                        break;
                    }
                    else
                    {
                        objResultData.objCogImage = objResultImage;
                    }
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                bReturn = true;
            } while(false);


            objResultData.bResult = bReturn;
            m_objResultData       = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = true)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                    m_objImageProcess.InputImage = objCogImage;
                    m_objImageProcess.Run();
                    CogImage8Grey objResultImage = ( CogImage8Grey )m_objImageProcess.OutputImage;
                    objResultData.objCogImage = objResultImage;
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    MakeErrorMessage("HLRun", 5505, ex.Message);
                    break;
                }

                bReturn = true;
            } while(false);

            objResultData.bitmapInputImage = null;//objCogImage.ToBitmap();
            objResultData.bResult          = bReturn;
            objResultData.eLibrary         = CResultData.enumLibrary.IMAGEPROCESS;
            m_objResultData = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                    m_dScore = 0;
                    m_objFindLineTool.InputImage = objCogImage;
                    m_objFindLineTool.Run();

                    if (0 < m_objFindLineTool.Results.Count)
                    {
                        m_objResultLine        = m_objFindLineTool.Results.GetLine();
                        m_objResultLineSegment = m_objFindLineTool.Results.GetLineSegment();
                        m_objGraphics          = m_objFindLineTool.Results[0].CreateResultGraphics(CogFindLineResultGraphicConstants.All);

                        m_objResultLine.GetXYRotation(out m_dLinePositionX, out m_dLinePositionY, out m_dAngle);
                        m_dAngle = m_dAngle * (180 / Math.PI);
                    }
                    else
                    {
                        m_dLinePositionX = 0; m_dLinePositionY = 0; m_dAngle = 0;
                        MakeErrorMessage("HLSaveRecipe", 5305, "Line Fail");
                        break;
                    }
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                m_dScore = 1;
                bReturn  = true;
            } while(false);

            //      objResultData.objGraphics = new CogCompositeShape();
            objResultData.dLinePositionX[0] = m_dLinePositionX; objResultData.dLinePositionY[0] = m_dLinePositionY; objResultData.dLineAngle[0] = m_dAngle; objResultData.dScore[0] = m_dScore;
            //  objResultData.objGraphics = m_objGraphics; objResultData.bitmapInputImage = objCogImage.ToBitmap();
            objResultData.bResult = bReturn;
            m_objResultData       = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 4
0
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                bReturn = true;
            } while(false);


            objResultData.bResult = bReturn;
            m_objResultData       = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 5
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                    if (null == objCogImage)
                    {
                        break;
                    }
                    if (false == m_objPMAlignTool.Pattern.Trained)
                    {
                        break;
                    }
                    objCogImage.SelectedSpaceName = "@";
                    m_objPMAlignTool.InputImage   = objCogImage;

                    if (false == bUseCalibrationImage)
                    {
                        m_objPMAlignTool.InputImage.CoordinateSpaceTree.RootName = @"#@Checkerboard Calibration";
                        m_objPMAlignTool.InputImage.SelectedSpaceName            = @"#@Checkerboard Calibration";
                    }


                    m_objPMAlignTool.Run();

                    if (0 < m_objPMAlignTool.Results.Count) //&& iScoreLimit < m_objPMAlignTool.Results[0].Score * 100 ) // 리미트 설정은 추후
                    {
                        for (int iLoopCount = 0; iLoopCount < m_objPMAlignTool.Results.Count; iLoopCount++)
                        {
                            if (( int )Abstract.CVisionLibraryAbstract.CResultData.enumInspectPosition.INSPECT_POSITION_FINAL <= iLoopCount)
                            {
                                break;
                            }
                            m_dPositionX[iLoopCount] = m_objPMAlignTool.Results[iLoopCount].GetPose().TranslationX; m_dPositionY[iLoopCount] = m_objPMAlignTool.Results[iLoopCount].GetPose().TranslationY; m_dAngle[iLoopCount] = m_objPMAlignTool.Results[iLoopCount].GetPose().Rotation *(180 / Math.PI); m_dScore[iLoopCount] = m_objPMAlignTool.Results[iLoopCount].Score;
                            //m_objGraphics[ iLoopCount ] = m_objPMAlignTool.Results[ iLoopCount ].CreateResultGraphics( CogPMAlignResultGraphicConstants.All );
                        }
                        CogImage8Grey FixtureImage = (CogImage8Grey)m_objPMAlignTool.InputImage;//.CopyBase( CogImageCopyModeConstants.CopyPixels ) as CogImage8Grey;
                        FixtureImage.SelectedSpaceName = "@";

                        m_objFixtureTool.InputImage = FixtureImage;
                        m_objFixtureTool.RunParams.UnfixturedFromFixturedTransform = m_objPMAlignTool.Results[0].GetPose();
                        m_objFixtureTool.Run();
                        objResultData.objCogImage = m_objFixtureTool.OutputImage as CogImage8Grey;
                        if (null == objResultData.objCogImage)
                        {
                            m_objFixtureTool.InputImage = FixtureImage;
                            m_objFixtureTool.RunParams.UnfixturedFromFixturedTransform = m_objPMAlignTool.Results[0].GetPose();
                            m_objFixtureTool.Run();
                            objResultData.objCogImage = m_objFixtureTool.OutputImage as CogImage8Grey;
                        }
                    }
                    else
                    {
                        for (int iLoopCount = 0; iLoopCount < ( int )Abstract.CVisionLibraryAbstract.CResultData.enumInspectPosition.INSPECT_POSITION_FINAL; iLoopCount++)
                        {
                            // m_objGraphics = null;
                            m_dPositionX[iLoopCount] = m_dPositionY[iLoopCount] = -1; m_dAngle[iLoopCount] = 0; m_dScore[iLoopCount] = 0;
                        }
                        objResultData.objCogImage = objCogImage;
                        MakeErrorMessage("HLRun", 5205, "Pattern Fail");
                        break;
                    }
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                bReturn = true;
            } while(false);

            if (null != m_objPMAlignTool.Results)
            {
                for (int iLoopCount = 0; iLoopCount < m_objPMAlignTool.Results.Count; iLoopCount++)
                {
                    if (false == bReturn)
                    {
                    }
                    else
                    {
                        if (( int )Abstract.CVisionLibraryAbstract.CResultData.enumInspectPosition.INSPECT_POSITION_FINAL <= iLoopCount)
                        {
                            break;
                        }
                        objResultData.objGraphics[iLoopCount] = new CogCompositeShape();
                        objResultData.objGraphics[iLoopCount] = m_objGraphics[iLoopCount];
                        objResultData.dPositionX[iLoopCount]  = m_dPositionX[iLoopCount]; objResultData.dPositionY[iLoopCount] = m_dPositionY[iLoopCount]; objResultData.dPositionAngle[iLoopCount] = m_dAngle[iLoopCount]; objResultData.dScore[iLoopCount] = m_dScore[iLoopCount];
                    }
                }
            }
            if (null != objCogImage)
            {
                objResultData.bitmapInputImage = null;//objCogImage.ToBitmap();
            }
            //m_objGraphics[ 0 ] = m_objPMAlignTool.CreateLastRunRecord();
            objResultData.objGraphics[0] = m_objPMAlignTool.CreateLastRunRecord();
            objResultData.bResult        = bReturn; objResultData.eLibrary = CResultData.enumLibrary.PMALIGN;
            m_objResultData = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 6
0
        public static unsafe System.Drawing.Bitmap BytesToBitmap(byte[] bytes, int width, int height)
        {
            try
            {
                Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
                //获取图像的BitmapData对像
                BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

                byte *ptr = (byte *)(bmpData.Scan0);
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        int offset = (height - i - 1) * bmpData.Width + j;
                        int val    = bytes[offset];
                        *(ptr + j) = (byte)val;
                    }

                    ptr = ptr + bmpData.Stride;
                }

                //Marshal.Copy(bmpData, 0, ptr, scanBytes);
                bitmap.UnlockBits(bmpData);  // 解锁内存区域

                // 修改生成位图的索引表,从伪彩修改为灰度
                ColorPalette palette;
                // 获取一个Format8bppIndexed格式图像的Palette对象
                using (Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))
                {
                    palette = bmp.Palette;
                }
                for (int i = 0; i < 256; i++)
                {
                    palette.Entries[i] = Color.FromArgb(i, i, i);
                }
                // 修改生成位图的索引表
                bitmap.Palette = palette;

                string filePatn = "k:\\temp\\" + "_InspCode_";
                if (!Directory.Exists(filePatn))
                {
                    Directory.CreateDirectory(filePatn);
                }
                // int jobID_Code = _jobID_Code + 1;
                string saveImagepath = filePatn + "\\" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + ".bmp";

                Cognex.VisionPro.CogImage8Grey G8 = new Cognex.VisionPro.CogImage8Grey(bitmap);

                Bitmap bitmap1 = G8.ToBitmap();

                bitmap1.Save(saveImagepath);
                return(bitmap1);
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        private unsafe void Button_CAPTURE_Click(object sender, EventArgs e)
        {
            if (m_nDeviceCurSel == -1)
            {
                return;
            }

            int nCaptureWidth    = 0;
            int nCaptureHeight   = 0;
            int nCaptureBitCount = 0;

            int nRet = KSJApiBase.KSJ_CaptureGetSizeEx(m_nDeviceCurSel, ref nCaptureWidth, ref nCaptureHeight, ref nCaptureBitCount);

            PrintErrorMessage(nRet);

            byte[] pImageData = new byte[nCaptureWidth * nCaptureHeight * (nCaptureBitCount >> 3)];

            long counterStart = 0;

            KSJApiBase.QueryPerformanceCounter(ref counterStart);

            nRet = KSJApiBase.KSJ_CaptureRgbData(m_nDeviceCurSel, pImageData);

            PrintErrorMessage(nRet);
            if (nRet != KSJCode.RET_SUCCESS)
            {
                TextBox_ELAPSE_TIME.Text = "Capture Fail.";
            }

            long counterEnd = 0;

            KSJApiBase.QueryPerformanceCounter(ref counterEnd);

            long nFreq = 0;

            KSJApiBase.QueryPerformanceFrequency(ref nFreq);

            float fInterval = (float)(counterEnd - counterStart);
            float fElapse   = fInterval / (float)nFreq * 1000;  // MS

            bool bCheck = CheckBox_SAVE.Checked;

            if (bCheck)
            {
                string szFileName = string.Format("capture-{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}.bmp", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                                  DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, fElapse);
                KSJApiBase.KSJ_HelperSaveToBmp(pImageData, nCaptureWidth, nCaptureHeight, nCaptureBitCount, szFileName);
            }

            TextBox_ELAPSE_TIME.Text = string.Format("Elapse: {0}ms", fElapse);

            Bitmap bitmap = new Bitmap(nCaptureWidth, nCaptureHeight, PixelFormat.Format8bppIndexed);
            //获取图像的BitmapData对像
            BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

            byte *ptr = (byte *)(bmpData.Scan0);

            for (int i = 0; i < nCaptureHeight; i++)
            {
                for (int j = 0; j < nCaptureWidth; j++)
                {
                    int offset = (nCaptureHeight - i - 1) * bmpData.Width + j;
                    int val    = pImageData[offset];
                    *(ptr + j) = (byte)val;
                }

                ptr = ptr + bmpData.Stride;
            }

            //Marshal.Copy(bmpData, 0, ptr, scanBytes);
            bitmap.UnlockBits(bmpData);  // 解锁内存区域

            // 修改生成位图的索引表,从伪彩修改为灰度
            ColorPalette palette;

            // 获取一个Format8bppIndexed格式图像的Palette对象
            using (Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))
            {
                palette = bmp.Palette;
            }
            for (int i = 0; i < 256; i++)
            {
                palette.Entries[i] = Color.FromArgb(i, i, i);
            }
            // 修改生成位图的索引表
            bitmap.Palette = palette;

            Cognex.VisionPro.CogImage8Grey G8 = new Cognex.VisionPro.CogImage8Grey(bitmap);

            cogDisplay1.Image = G8;
        }
Exemplo n.º 8
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try {
                    m_dScore = 0;
                    //이미지 결과 그래픽 생성
                    objResultData.objLineGraphics = new CogCompositeShape[2];

                    for (int iLoopCount = 0; iLoopCount < ( int )CResultData.enumLine.LINE_FINAL; iLoopCount++)
                    {
                        m_objFindLineTool[iLoopCount].InputImage = objCogImage;
                        m_objFindLineTool[iLoopCount].Run();

                        if (0 < m_objFindLineTool[iLoopCount].Results.Count)
                        {
                            m_objResultLine[iLoopCount]        = m_objFindLineTool[iLoopCount].Results.GetLine();
                            m_objResultLineSegment[iLoopCount] = m_objFindLineTool[iLoopCount].Results.GetLineSegment();
                            m_objLineGraphics[iLoopCount]      = m_objFindLineTool[iLoopCount].Results[0].CreateResultGraphics(CogFindLineResultGraphicConstants.All);

                            objResultData.objLineGraphics[iLoopCount] = new CogCompositeShape();
                            objResultData.objLineGraphics[iLoopCount] = m_objLineGraphics[iLoopCount];
                            m_objResultLine[iLoopCount].GetXYRotation(out m_dLinePositionX[iLoopCount], out m_dLinePositionY[iLoopCount], out m_dLineAngle[iLoopCount]);
                            m_dLineAngle[iLoopCount] = m_dLineAngle[iLoopCount] * (180 / Math.PI);
                        }
                        else
                        {
                            m_dLinePositionX[iLoopCount] = 0; m_dLinePositionY[iLoopCount] = 0; m_dLineAngle[iLoopCount] = 0;
                            MakeErrorMessage("HLSaveRecipe", 5405, "Line Fail");
                            break;
                        }
                    }
                } catch (System.Exception ex) {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    break;
                }

                m_objIntersectTool.InputImage = objCogImage;
                m_objIntersectTool.LineA      = m_objResultLine[( int )CResultData.enumLine.LINE_VERTICAL]; m_objIntersectTool.LineB = m_objResultLine[( int )CResultData.enumLine.LINE_HORIZON];
                m_objIntersectTool.Run();

                if (true == m_objIntersectTool.Intersects)
                {
                    m_dAngle = Math.Abs(m_objIntersectTool.Angle * (180 / Math.PI));

                    if ((85 < m_dAngle || 95 > m_dAngle) || (265 < m_dAngle || 275 > m_dAngle))
                    {
                        m_dPositionX = m_objIntersectTool.X; m_dPositionY = m_objIntersectTool.Y;
                    }
                    else
                    {
                        m_dPositionX = -1; m_dPositionY = -1;
                        MakeErrorMessage("HLSaveRecipe", 5406, "IntersectTool Angle Range Out");
                        break;
                    }
                }
                else
                {
                    m_dPositionX = -1; m_dPositionY = -1;
                    MakeErrorMessage("HLSaveRecipe", 5407, "IntersectTool Fail");
                    break;
                }

                m_dScore = 1;
                bReturn  = true;
            } while(false);
            for (int iLoopCount = 0; iLoopCount < ( int )CResultData.enumLine.LINE_FINAL; iLoopCount++)
            {
                objResultData.dLinePositionX[iLoopCount] = m_dLinePositionX[iLoopCount]; objResultData.dLinePositionY[0] = m_dLinePositionY[iLoopCount]; objResultData.dLineAngle[0] = m_dLineAngle[iLoopCount];
            }
            objResultData.dPositionX[0] = m_dPositionX; objResultData.dPositionY[0] = m_dPositionY; objResultData.dScore[0] = m_dScore;
//            objResultData.bitmapInputImage = objCogImage.ToBitmap();
            objResultData.bResult = bReturn; objResultData.eLibrary = CResultData.enumLibrary.FINDLINE_INTERSECT;
            m_objResultData       = ( CResultData )objResultData.Clone();

            return(bReturn);
        }
 public CogImage8Grey(CogImage8Grey other);