Esempio n. 1
0
        public static void Run(Bitmap image, int index, out ArrayList data)
        {
            ICogImage outimage = new CogImage8Grey(image);

            block.Inputs["InputImage"].Value = outimage;
            block.Inputs["Index"].Value      = index;
            block.Run();
            if (block.RunStatus.Result == CogToolResultConstants.Accept)
            {
                data = (ArrayList)block.Outputs["data"].Value;
            }
            else
            {
                throw new Exception("Vision Run Fail");
            }
        }
Esempio n. 2
0
        private void RunTool(int imagePathSn)
        {
            if (testImagePathList.Count > imagePathSn)
            {
                CogImage8Grey img = new CogImage8Grey(new Bitmap(testImagePathList[imagePathSn]));
                //var imgFile = new CogImageFileTool();
                //imgFile.Operator.Open(testImagePathList[imagePathSn], CogImageFileModeConstants.Read);
                //imgFile.Run();
                //ICogImage img = imgFile.OutputImage;
                if (_enableCheckerboard)
                {
                    _cogCalibCheckerboard.InputImage = img;
                    _cogCalibCheckerboard.Run();
                    img = (CogImage8Grey)_cogCalibCheckerboard.OutputImage;
                }
                _cogToolBlock.Inputs[1].Value = img;
                if (_enableCalibNPointToNPoint)
                {
                    _cogCalibNPointToNPoint.InputImage = img;
                    _cogCalibNPointToNPoint.Run();
                    img = (CogImage8Grey)_cogCalibNPointToNPoint.OutputImage;
                }
                _cogToolBlock.Inputs[0].Value = img;
                _cogToolBlock.Run();

                _imageSelectCount = imagePathSn + 1;
                RefreshImageCount();
            }
            else
            {
                MessageBox.Show(@"找不到指定图片");
            }
        }
Esempio n. 3
0
        private void ImageSource_OnImage(Object theImage)
        {
            if (watchOn != null)
            {
                watchOn.Abort();
            }

            if (Sr_status == SensorStatus.Aborting)
            {
                SmartRayImageSource.SoftTrigger();
                NotifierHelper.Notify("ImageSource.SoftTriger");
            }
            else

            {
                NotifierHelper.Notify("Sensor.OnImage", "获得图像。");

                object[] imgs = theImage as object[];

                this.LiveDisplay.Image = imgs[0] as ICogImage;
                LiveDisplay.Fit();

                visionProAlg.Inputs["ZMap"].Value      = imgs[0];
                visionProAlg.Inputs["Intensity"].Value = imgs[1];
                visionProAlg.Run();
                //this.VisionProject.VisionAlgorithm.Inputs["ZMap"] = imgs[0];
                //this.VisionProject.VisionAlgorithm.Inputs["Intensity"] = imgs[1];
                //this.VisionProject.VisionAlgorithm.Run();
            }

            Sr_status = SensorStatus.Idle;
        }
Esempio n. 4
0
        public int ExtractPosData(int Index, ICogImage CalibImage) // Image 에서 Pixel 좌표를 추출 
        {
            double ResultX, ResultY;

            try
            {

                ToolBlock_Calib_Extractor.Inputs["InputImage1"].Value = CalibImage;

                ToolBlock_Calib_Extractor.Run();

                ResultX = (double)ToolBlock_Calib_Extractor.Outputs["Pos1_X"].Value;
                ResultY = (double)ToolBlock_Calib_Extractor.Outputs["Pos1_Y"].Value;

                List_PixelPos_X.Insert(Index, ResultX);
                List_PixelPos_Y.Insert(Index, ResultY);


                return 1;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
Esempio n. 5
0
        public static void RunOnce()
        {
            _formMain.Invoke((MethodInvoker)(() => { _formMain.btnReset.Enabled = true; }));

            _block.Run();
            _formMain.Invoke((MethodInvoker)(() =>
            {
                _formMain.cogRecordDisplay1.Record =
                    _block.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"];
            }));

            string runResult;

            if (CogToolResultConstants.Accept == _block.RunStatus.Result)
            {
                runResult = resultOK;
            }
            else
            {
                CogPMAlignTool pma = (CogPMAlignTool)_block.Tools["主定位"];
                runResult = pma.Results.Count == 0 ? resultNoProduct : resultNG;
            }
            HandleResult(runResult);


            Y1           = (double)_block.Outputs["Y1"].Value;
            Y2           = (double)_block.Outputs["Y2"].Value;
            X1           = (double)_block.Outputs["X1"].Value;
            X2           = (double)_block.Outputs["X2"].Value;
            angle        = (double)_block.Outputs["Angle"].Value;
            angleUncalib = (double)_block.Outputs["AngleUncalib"].Value;
            X1_pixel     = (double)_block.Outputs["X1_pixel"].Value;
            X2_pixel     = (double)_block.Outputs["X2_pixel"].Value;
            Y1_pixel     = (double)_block.Outputs["Y1_pixel"].Value;
            Y2_pixel     = (double)_block.Outputs["Y2_pixel"].Value;



            lock (_formMain._chartFormMarshaller.mu_currentIndex)
            {
                SaveLog(_formMain._chartFormMarshaller.currentIndex, runResult);
                _formMain.showCurrentIndex(_formMain._chartFormMarshaller.currentIndex);
                _formMain._chartFormMarshaller.incrementItemCount();
                noErrorInThisRound &= (_block.RunStatus.Result != CogToolResultConstants.Error);
                _formMain._chartFormMarshaller.collectData(X1, X2, Y1, Y2, angle);
                if (_formMain._chartFormMarshaller.RoundEndReached())
                {
                    // if no error occur within a round, update summery and clear. Otherwise, just clear.
                    _formMain._chartFormMarshaller.resetItemCount();
                    if (noErrorInThisRound)
                    {
                        _formMain._chartFormMarshaller.GenerateSummery();
                    }

                    _formMain._chartFormMarshaller.clearDataBuffers();
                    // reset this flag for next round
                    noErrorInThisRound = true;
                }
            }
        }
Esempio n. 6
0
        public void RunToolBlock(CogToolBlock toolBlock, ICogImage image, string brand, int index)
        {
            toolBlock.Inputs["InputImage"].Value            = image;
            toolBlock.Inputs["Brand"].Value                 = brand;
            toolBlock.Inputs["iAcquirePositionIndex"].Value = index;
            toolBlock.Run();

            RunParams.CcdDisplayBlock[CcdId].Post(1);
            RunParams.CcdCheckBlock[CcdId].Post(0);
        }
        private void btnGetRef1_Click(object sender, EventArgs e)
        {
            Button btn      = (Button)sender;
            string strIndex = btn.Name.Substring(9);
            int    index    = int.Parse(strIndex);

            tempBlock.Run();
            this.cogRecordDisplay1.Record = tempBlock.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"];
            if (CogToolResultConstants.Accept == tempBlock.RunStatus.Result)
            {
                double x = Math.Round((double)tempBlock.Outputs["X"].Value, 3);
                double y = Math.Round((double)tempBlock.Outputs["Y"].Value, 3);
                this.dataGridView1.Rows[index - 1].Cells[0].Value = x;
                this.dataGridView1.Rows[index - 1].Cells[1].Value = y;
            }
            else
            {
                MessageBox.Show("获取点失败");
            }
        }
Esempio n. 8
0
        private ResultType RunBlock()
        {
            _toolBlock.Run();

            if (_resultCategories == ResultCategories.OK_NG_NOPRODUCT)
            {
                var alignTool = (CogPMAlignTool)_toolBlock.Tools["判断有无料"];
                if (alignTool.Results.Count == 0)
                {
                    return(ResultType.NOPORDUCT);
                }
            }

            return(_toolBlock.RunStatus.Result == CogToolResultConstants.Accept ? ResultType.OK : ResultType.NG);
        }
Esempio n. 9
0
 public void RunOnce()
 {
     // Get the next image
     if (!bUseCamera)
     {
         mIFTool.Run();
         mToolBlockProcess.Inputs["Image"].Value = mIFTool.OutputImage as CogImage8Grey;
     }
     else
     {
         //FIXME: check output image of mToolBockAcq
         mToolBlockAcq.Run();
         Console.WriteLine("Test step process when using camera 1....");
         mToolBlockProcess.Inputs["Image"].Value = mToolBlockAcq.Outputs["Image"].Value;
     }
     // Run the toolblock
     mToolBlockProcess.Run();
 }
Esempio n. 10
0
        private void btn_Run_Click(object sender, EventArgs e)
        {
            if (true)
            {
                m_tb.Inputs["OutputImage"].Value = m_Image;
                //m_tb.Inputs["InputImage"].Value = m_Image;
                m_tb.Run();

                cogRecordDisplay1.Image = m_Image;

                cogRecordDisplay1.Record = m_tb.CreateLastRunRecord().SubRecords[0];
                cogRecordDisplay1.Fit();

                textBox1.Text = m_tb.Outputs["Results_Item_0_Score"].Value.ToString();
                double angle = (double)m_tb.Outputs["Results_Item_0_GetPose_Rotation"].Value;
                //  angle = angle * 180 / Math.PI;
            }
        }
Esempio n. 11
0
        public int Calc_PixelSize(double ActualDist, ICogImage CalibImage) // Image 에서 Pixel Size 를 계산  
        {
            try
            {
                ToolBlock_Calib_CalcPixelSize.Inputs["InputImage1"].Value = CalibImage;
                ToolBlock_Calib_CalcPixelSize.Inputs["ActualDist"].Value = ActualDist;


                ToolBlock_Calib_CalcPixelSize.Run();

                this.PixelSize = (double)ToolBlock_Calib_CalcPixelSize.Outputs["PixelSize"].Value;


                return 1;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        private void buttonF8_Click(object sender, EventArgs e)
        {
            CogToolBlock tbTemp = MyGlobal.tbDown2;

            tbTemp.Run();
            //disp[index].Record = tbTemp.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"];
            if (CogToolResultConstants.Accept == tbTemp.RunStatus.Result)
            {
                double x = Math.Round((double)tbTemp.Outputs["X"].Value, 3);
                double y = Math.Round((double)tbTemp.Outputs["Y"].Value, 3);
                double r = Math.Round((double)tbTemp.Outputs["R"].Value, 3);
                this.dataGridView2.Rows[0].Cells[7].Value = x;
                this.dataGridView2.Rows[1].Cells[7].Value = y;
                this.dataGridView2.Rows[2].Cells[7].Value = r;
            }
            else
            {
                MessageBox.Show("获取点失败");
            }
        }
Esempio n. 13
0
        public static void RunOnce()
        {
            _block.Run();
            var ImageAcqTool = (CogAcqFifoTool)_block.Tools["CogAcqFifoTool1"];

            _formMain.Invoke((MethodInvoker)(() =>
            {
                _formMain.cogRecordDisplay1.Record =
                    _block.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"];
            }));

            string runResult;

            if (CogToolResultConstants.Accept == _block.RunStatus.Result)
            {
                runResult = resultOK;
            }
            else if (ImageAcqTool.RunStatus.Result != CogToolResultConstants.Accept)
            {
                runResult = resultImageAcqFailed;
            }
            else
            {
                var pma = (CogPMAlignTool)_block.Tools["主定位"];
                runResult = pma.Results.Count == 0 ? resultNoProduct : resultNG;
            }

            // 反馈信号
            SubmitResult(runResult);
            // 将结果显示到屏幕
            DisplayResult_Invoke(runResult);
            // 根据结果判断是否保存图片
            saveImage(_formMain.cogRecordDisplay1, 0, runResult);

            var blockOutputs = DataLogger.ExtractOutputsFromToolBlock(ref _block, _blockOutputNames);

            SaveLog(0, runResult, blockOutputs);
        }
Esempio n. 14
0
        public static void run()
        {
            f1.Invoke(new Action(() =>
            {
                block.Run();

                f1.cogRecordDisplay1.StaticGraphics.Clear();
                f1.cogRecordDisplay1.InteractiveGraphics.Clear();
                f1.cogRecordDisplay1.Image = null;

                var icg = block.CreateLastRunRecord();
                f1.cogRecordDisplay1.Record  = icg.SubRecords["CogIPOneImageTool1.OutputImage"];
                f1.cogRecordDisplay1.AutoFit = true;
            }));

            del del2 = Light;

            // f1.label4.Invoke(del2, "2", f1.label4);


            if (block.RunStatus.Result == CogToolResultConstants.Accept)
            {
                f1.label4.Invoke(del2, "1", f1.label4);
                GCF(f1.cogRecordDisplay1, "#", "微软雅黑", 20, 100, 100, "OK", CogColorConstants.Green,
                    CogGraphicLabelAlignmentConstants.TopLeft);
                IOC0640.ioc_write_outbit(0, out_OK_bit, 0);
                Thread.Sleep(100);
                IOC0640.ioc_write_outbit(0, out_OK_bit, 1);
                f1.label4.Invoke(del2, "2", f1.label4);
            }

            if (block.RunStatus.Result != CogToolResultConstants.Accept)
            {
                f1.label4.Invoke(del2, "1", f1.label5);
                GCF(f1.cogRecordDisplay1, "#", "微软雅黑", 20, 100, 100, "NG", CogColorConstants.Red,
                    CogGraphicLabelAlignmentConstants.TopLeft);
                IOC0640.ioc_write_outbit(0, out_NG_bit, 0);
                Thread.Sleep(100);
                IOC0640.ioc_write_outbit(0, out_NG_bit, 1);
                f1.label4.Invoke(del2, "2", f1.label5);
                SaveImage(f1.cogRecordDisplay1, true);
            }

            var pma = (CogPMAlignTool)block.Tools["判断有无料"];

            if (pma.Results.Count == 0)
            {
                f1.label4.Invoke(del2, "1", f1.label7);
                GCF(f1.cogRecordDisplay1, "#", "微软雅黑", 20, 100, 100, "无料", CogColorConstants.Red,
                    CogGraphicLabelAlignmentConstants.TopLeft);
                IOC0640.ioc_write_outbit(0, out_NOPRODUCT_bit, 0);
                Thread.Sleep(100);
                IOC0640.ioc_write_outbit(0, out_NOPRODUCT_bit, 1);
                f1.label4.Invoke(del2, "2", f1.label7);
                SaveImage(f1.cogRecordDisplay1, true);
            }


            Y  = (double)block.Outputs["Y"].Value;
            X1 = (double)block.Outputs["X1"].Value;
            X2 = (double)block.Outputs["X2"].Value;
            X3 = (double)block.Outputs["X3"].Value;
            X4 = (double)block.Outputs["X4"].Value;
            SaveImage(f1.cogRecordDisplay1, true);
            SaveLog();
        }
Esempio n. 15
0
        private void ThreadProcess()
        {
            while (true)
            {
                if (runStart && processEndStatus)
                {
                    processEndStatus = false;
                    try
                    {
                        visionResult           = new VisionResult();
                        visionResult.StartTime = DateTime.Now;

                        //程序运行
                        acqFifoTool.Run();

                        if (acqFifoTool.OutputImage != null)
                        {
                            visionResult.InputImage = acqFifoTool.OutputImage;

                            processToolBlock.Inputs[0].Value = visionResult.InputImage;
                            processToolBlock.Run();

                            if (processToolBlock.RunStatus.Result == CogToolResultConstants.Accept)
                            {
                                CogCalibCheckerboardTool checkerboardTool = (CogCalibCheckerboardTool)processToolBlock.Tools[0];
                                visionResult.OutputImage   = checkerboardTool.OutputImage;
                                visionResult.cogRecord     = processToolBlock.CreateLastRunRecord();
                                visionResult.width1        = (double)processToolBlock.Outputs[0].Value;
                                visionResult.width2        = (double)processToolBlock.Outputs[1].Value;
                                visionResult.CoordX        = (double)processToolBlock.Outputs[4].Value;
                                visionResult.RunStatus     = true;
                                visionResult.RunStatusText = "OK";


                                //判断是否重复
                                if (Math.Abs(visionResult.CoordX - lastCoordX) < 0.05)
                                {
                                    recurCount++;
                                    if (recurCount > 9)
                                    {
                                        toolStrip1.Invoke(new Action(delegate
                                        {
                                            tsbStart_Click(null, null);
                                            MessageBox.Show(string.Format("检测到产品未移动,次数{0},自动停止运行,请适当挪动产品", recurCount));
                                        }));
                                    }
                                }
                                else
                                {
                                    recurCount = 0;
                                }
                                lastCoordX = visionResult.CoordX;


                                //判断处理
                                visionResult.ExamineStatus = true;
                            }
                            else
                            {
                                visionResult.OutputImage   = visionResult.InputImage;
                                visionResult.cogRecord     = null;
                                visionResult.RunStatusText = "未识别";
                                visionResult.RunStatus     = false;
                                visionResult.width1        = 999;
                                visionResult.width2        = 999;
                                visionResult.CoordX        = 0;
                            }



                            //保存原图图片
                            if (isSaveImage && visionResult.RunStatus)
                            {
                                visionResult.ImagePath = string.Format("{0}\\{2}\\{1}", imageSavePath, visionResult.ExamineStatus ? "OK" : "NG", visionResult.StartTime.ToString("yyMMdd"));
                                if (!Directory.Exists(visionResult.ImagePath))
                                {
                                    Directory.CreateDirectory(visionResult.ImagePath);
                                }
                                CogImageFile cogImageFile = new CogImageFile();
                                cogImageFile.Open(visionResult.ImagePath + "\\" + visionResult.StartTime.ToString("HHmmssfff") + ".bmp", CogImageFileModeConstants.Write);
                                cogImageFile.Append(visionResult.InputImage);
                                cogImageFile.Close();
                            }

                            crdResultImage.Invoke(new Action(delegate
                            {
                                crdResultImage.InteractiveGraphics.Clear();
                                crdResultImage.StaticGraphics.Clear();
                                crdResultImage.Image   = null;
                                crdResultImage.Image   = visionResult.OutputImage;
                                crdResultImage.Record  = visionResult.cogRecord;
                                lblRunStatus.Text      = visionResult.RunStatusText;
                                lblRunStatus.ForeColor = visionResult.RunStatus ? Color.Green : Color.Red;
                                lblWidth1.Text         = visionResult.width1.ToString("0.000");
                                lblWidth2.Text         = visionResult.width2.ToString("0.000");

                                //保存画线图
                                if (isSaveImage && visionResult.RunStatus && !visionResult.ExamineStatus)
                                {
                                    Bitmap crdImage = (Bitmap)crdResultImage.CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Image);
                                    crdImage.Save(visionResult.ImagePath + "\\crd_" + visionResult.StartTime.ToString("HHmmssfff") + ".jpeg", ImageFormat.Jpeg);
                                }
                            }));
                        }
                        else
                        {
                            CognexAreaCamera_CameraStatusChange(1, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("图片处理异常:" + ex);
                        tsbStart_Click(null, null);
                    }
                    processEndStatus = true;
                }
                if (!cameraStatus)
                {
                    acqFifoTool.Run();
                    if (acqFifoTool.RunStatus.Result == CogToolResultConstants.Accept)
                    {
                        CognexAreaCamera_CameraStatusChange(1, true);
                    }
                }

                Thread.Sleep(1);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="timeout">处理超时时间,若小于等于0,则无限等待.单位:毫秒</param>
        /// <param name="outputs">输出结果</param>
        public void Execute(int timeout, out ItemCollection outputs)
        {
            outputs = new ItemCollection();

            //全局线程锁(静态),避免不同线程间同时调用VisionPro的资源
            lock (globalThreadLock)
            {
                try
                {
                    //线程锁,避免在不同线程中分别调用init和run,导致isInit变量冲突
                    lock (threadLock)
                    {
                        if (!IsInit)
                        {
                            throw new ArgumentException("VisionFrame is uninit");
                        }
                    }

                    if (cogToolBlock != null)
                    {
                        cogToolBlock.Run();

                        Outputs.Clear();
                        for (int i = 0; i < cogToolBlock.Outputs.Count; i++)
                        {
                            Outputs.Add(new ItemBase(cogToolBlock.Outputs[i].Name, cogToolBlock.Outputs[i].Value, cogToolBlock.Outputs[i].ValueType, string.IsNullOrEmpty(cogToolBlock.Outputs[i].Description) ? cogToolBlock.Outputs[i].Name : cogToolBlock.Outputs[i].Description));
                        }
                        outputs = new ItemCollection(Outputs);

                        EResult result = EResult.Accept;
                        switch (cogToolBlock.RunStatus.Result)
                        {
                        case CogToolResultConstants.Accept:
                            result = EResult.Accept;
                            break;

                        case CogToolResultConstants.Warning:
                            result = EResult.Warning;
                            break;

                        case CogToolResultConstants.Reject:
                            result = EResult.Reject;
                            break;

                        case CogToolResultConstants.Error:
                            result = EResult.Error;
                            break;

                        default:
                            break;
                        }

                        RunStatus = new RunStatus(cogToolBlock.RunStatus.ProcessingTime, result, cogToolBlock.RunStatus.Message, cogToolBlock.RunStatus.Exception);

                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }