コード例 #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\tool.vpp"))
     {
         blob = CogSerializer.LoadObjectFromFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\tool.vpp") as CogBlobTool;
     }
 }
コード例 #2
0
ファイル: CogForm.cs プロジェクト: XianheCode/Repair
        //toolNum和Pattern两个参数决定结果的来源
        //Blob工具的结果获取函数
        private bool getBlobToolResult(out double[] item_x, out double[] item_y, out int item_number, int toolNum)
        {
            CogBlobTool blobTool = null;

            item_x      = null;
            item_y      = null;
            item_number = 0;

            switch (toolNum)
            {
            case 1:
                blobTool = blobTool_1;
                break;

            case 2:
                blobTool = blobTool_2;
                break;

            case 3:
                blobTool = blobTool_3;
                break;

            default:
                return(false);
            }
            if (blobTool.Results == null)
            {
                return(false);
            }

            CogBlobResultCollection blobResult = blobTool.Results.GetBlobs();

            if (blobResult == null)
            {
                return(false);
            }
            item_number = blobResult.Count;

            if (item_number <= 0)
            {
                item_x = new double[0];
                item_y = new double[0];
                return(false);
            }


            item_x = new double[item_number];
            item_y = new double[item_number];



            for (int i = 0; i < item_number; i++)
            {
                item_x[i] = blobResult[i].CenterOfMassX;
                item_y[i] = blobResult[i].CenterOfMassY;
            }

            return(true);
        }
コード例 #3
0
        private void AssignToolResult(CogBlobTool cogBlob)
        {
            CogBlobResults cogBlobResults = cogBlob.Results;

            if (cogBlobResults != null)
            {
                AssignToolResult(cogBlob.Name, cogBlobResults);
            }
        }
コード例 #4
0
        void Subject_Ran(object sender, EventArgs e)
        {
            // This method executes each time the TB runs

            // Update the CogDisplayRecord with the image and the lastRunRecord
            cogRecordDisplay1.Image = cogToolBlockEditV21.Subject.Inputs["Image"].Value as CogImage8Grey;
            CogBlobTool mBlobTool = cogToolBlockEditV21.Subject.Tools["CogBlobTool1"] as CogBlobTool;

            cogRecordDisplay1.Record = mBlobTool.CreateLastRunRecord();
            cogRecordDisplay1.Fit(true);
        }
コード例 #5
0
        /// <summary>
        /// Do a run on current displayed Image
        /// </summary>
        public bool RunToolBlock(int cameraModule)
        {
            bool   runStatus = true;
            String colResult;
            CogToolResultConstants toolColResult;
            int i;

            if (this.cogToolRun[cameraModule] != null)
            {
                this.cogToolRun[cameraModule].Inputs["InputImage"].Value = grabImage[cameraModule] as CogImage8Grey;

                this.cogToolRun[cameraModule].Run();

                ICogRunStatus cogStatus = this.cogToolRun[cameraModule].RunStatus;

                if (cogStatus.Result == CogToolResultConstants.Error)
                {
                    runStatus = false;
                    // error default all to invalid
                    for (i = 0; i < MAX_RESULT; i++)
                    {
                        this.inspectResult[cameraModule, i] = HGAStatus.Unknown;
                    }
                }
                else
                {
                    double[] blob           = { 0, 0, 0, 0, 0, 0 };
                    double[] centerofmass_X = { 0, 0, 0, 0, 0, 0 };
                    CommonCogToolBlock = (CogBlobTool)this.cogToolRun[cameraModule].Tools["blobtool"];

                    CogBlobResultCollection resultcollection = CommonCogToolBlock.Results.GetBlobs();
                    for (int x = 0; x < resultcollection.Count; x++)
                    {
                        blob[x]           = resultcollection[x].Area;
                        centerofmass_X[x] = resultcollection[x].CenterOfMassX;
                    }
                }
            }
            else
            {
                runStatus = false;
            }

            return(runStatus);
        }
コード例 #6
0
        private void mToolBlockProcess_Ran(object sender, EventArgs e)
        {
            // This method executes each time the TB runs
            bool result = (bool)(objectManager.mToolBlockProcess.Outputs["InspectionPassed"].Value);

            if (result)
            {
                objectManager.numPass++;
            }
            else
            {
                objectManager.numFail++;
            }
            // Update the label with pass and fail
            nPass.Text = objectManager.numPass.ToString();
            nFail.Text = objectManager.numFail.ToString();

            CogBlobTool mBlobTool = objectManager.mToolBlockProcess.Tools["CogBlobTool1"] as CogBlobTool;

            //get result
            var blobResult = mBlobTool.Results;
            var all_blob   = blobResult.GetBlobs();

            Console.WriteLine($"number blob detected = {all_blob.Count}");
            for (int i = 0; i < all_blob.Count; i++)
            {
                interfaceManager.SendMessage(Blob_Packet(all_blob[i]));
            }

            //var blobRunParam = mBlobTool.RunParams;

            //Assign picture to display
            ICogRecord temp = mBlobTool.CreateLastRunRecord();

            //temp = temp.SubRecords["BlobImage"];
            temp = temp.SubRecords["InputImage"];
            cogRecordDisplay1.Record = temp;
            cogRecordDisplay1.Fit(true);

            Display(result);
            Console.WriteLine("Ran done!, time processing = {0} ms", objectManager.mToolBlockProcess.RunStatus.TotalTime);
        }
コード例 #7
0
 public ABlob(Object oTool)
 {
     m_cogBlobTool = oTool as CogBlobTool;
     Init();
 }
コード例 #8
0
 public ABlob()
 {
     m_cogBlobTool = new CogBlobTool();
     Init();
     m_cogBlobTool.RunParams.SegmentationParams.Mode = CogBlobSegmentationModeConstants.HardFixedThreshold;
 }
コード例 #9
0
        public bool Run(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogEllipseAlgo _CogEllipseAlgo, ref CogEllipseResult _CogEllipseResult, double _OffsetX = 0, double _OffsetY = 0, int _NgNumber = 0)
        {
            bool _Result = true;

            #region Caliper Center XY 구하기 -> Blob으로 Center 위치 Search
            #region GetAutoThresholdValue
            CogHistogramTool _HistoTool = new CogHistogramTool();
            _HistoTool.InputImage = _SrcImage;
            _HistoTool.Region     = _InspRegion;
            _HistoTool.Run();

            int[]  _HistoValue     = _HistoTool.Result.GetHistogram();
            double _TotSize        = _InspRegion.Width * _InspRegion.Height;
            double _ThresholdSum   = 0;
            int    _ThresholdValue = 0;
            for (int iLoopCount = 0; iLoopCount < 256; ++iLoopCount)
            {
                _ThresholdSum += iLoopCount * _HistoValue[iLoopCount];
            }

            double _ThresholdSum2 = 0;
            double _WeightBack = 0, _WeightFore = 0, _VarMax = 0;
            for (int iLoopCount = 0; iLoopCount < 256; ++iLoopCount)
            {
                _WeightBack += _HistoValue[iLoopCount];
                if (0 == _WeightBack)
                {
                    continue;
                }

                _WeightFore = _TotSize - _WeightBack;
                if (0 == _WeightFore)
                {
                    break;
                }

                _ThresholdSum2 += (double)(iLoopCount * _HistoValue[iLoopCount]);

                double _MeanBack = _ThresholdSum2 / _WeightBack;
                double _MeanFore = (_ThresholdSum - _ThresholdSum2) / _WeightFore;

                double _VarBetween = _WeightBack * _WeightFore * Math.Pow((_MeanBack - _MeanFore), 2);

                if (_VarBetween > _VarMax)
                {
                    _VarMax         = _VarBetween;
                    _ThresholdValue = iLoopCount;
                }
            }
            #endregion

            #region Blob Search
            CogBlobTool _BlobTool = new CogBlobTool();
            _BlobTool.InputImage = _SrcImage;
            _BlobTool.Region     = _InspRegion;
            _BlobTool.RunParams.SegmentationParams.Mode               = CogBlobSegmentationModeConstants.HardFixedThreshold;
            _BlobTool.RunParams.SegmentationParams.Polarity           = CogBlobSegmentationPolarityConstants.LightBlobs;
            _BlobTool.RunParams.ConnectivityMode                      = CogBlobConnectivityModeConstants.GreyScale;
            _BlobTool.RunParams.ConnectivityCleanup                   = CogBlobConnectivityCleanupConstants.Fill;
            _BlobTool.RunParams.SegmentationParams.HardFixedThreshold = _ThresholdValue;
            _BlobTool.RunParams.ConnectivityMinPixels                 = 10000;
            _BlobTool.Run();

            CogBlobResults _BlobResults    = _BlobTool.Results;
            double         _MaxSize        = 0;
            double         _CaliperCenterX = 0;
            double         _CaliperCenterY = 0;
            if (_BlobResults.GetBlobs().Count > 0)
            {
                for (int iLoopCount = 0; iLoopCount < _BlobResults.GetBlobs().Count; ++iLoopCount)
                {
                    CogBlobResult _BlobResult = _BlobResults.GetBlobByID(iLoopCount);
                    if (_BlobResult.Area > _MaxSize)
                    {
                        _MaxSize        = _BlobResult.Area;
                        _CaliperCenterX = _BlobResult.CenterOfMassX;
                        _CaliperCenterY = _BlobResult.CenterOfMassY;
                    }
                }
            }

            else
            {
                _CaliperCenterX = _CogEllipseAlgo.ArcCenterX - _OffsetX;
                _CaliperCenterY = _CogEllipseAlgo.ArcCenterY - _OffsetY;
            }
            //CogSerializer.SaveObjectToFile(_BlobTool, string.Format(@"D:\CircleBlob.vpp"));
            #endregion
            #endregion

            SetCaliperDirection(_CogEllipseAlgo.CaliperSearchDirection, _CogEllipseAlgo.CaliperPolarity);
            SetCaliper(_CogEllipseAlgo.CaliperNumber, _CogEllipseAlgo.CaliperSearchLength, _CogEllipseAlgo.CaliperProjectionLength, _CogEllipseAlgo.CaliperIgnoreNumber);

            //LJH 2019.05.23 Caliper Center 기준점 변경
            //SetEllipticalArc(_CogEllipseAlgo.ArcCenterX - _OffsetX, _CogEllipseAlgo.ArcCenterY - _OffsetY, _CogEllipseAlgo.ArcRadiusX, _CogEllipseAlgo.ArcRadiusY, _CogEllipseAlgo.ArcAngleSpan);
            SetEllipticalArc(_CaliperCenterX, _CaliperCenterY, _CogEllipseAlgo.ArcRadiusX, _CogEllipseAlgo.ArcRadiusY, _CogEllipseAlgo.ArcAngleSpan);

            if (true == Inspection(_SrcImage))
            {
                GetResult();
            }

            if (FindEllipseResults != null && FindEllipseResults.Count > 0)
            {
                _CogEllipseResult.IsGood = true;
            }
            else
            {
                _CogEllipseResult.IsGood = false;
            }

            if (!_CogEllipseResult.IsGood)
            {
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Find Fail!!", CLogManager.LOG_LEVEL.MID);
                _CogEllipseResult.CenterX  = _CogEllipseAlgo.ArcCenterX;
                _CogEllipseResult.CenterY  = _CogEllipseAlgo.ArcCenterY;
                _CogEllipseResult.RadiusX  = _CogEllipseAlgo.ArcRadiusX;
                _CogEllipseResult.RadiusY  = _CogEllipseAlgo.ArcRadiusY;
                _CogEllipseResult.OriginX  = 0;
                _CogEllipseResult.OriginY  = 0;
                _CogEllipseResult.Rotation = 0;
                _CogEllipseResult.NgNumber = _NgNumber;
            }

            else
            {
                if (FindEllipseResults.GetEllipse() != null)
                {
                    CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Complete", CLogManager.LOG_LEVEL.MID);

                    _CogEllipseResult.PointFoundCount = FindEllipseResults.NumPointsFound;
                    _CogEllipseResult.CenterX         = FindEllipseResults.GetEllipse().CenterX;
                    _CogEllipseResult.CenterY         = FindEllipseResults.GetEllipse().CenterY;
                    _CogEllipseResult.RadiusX         = FindEllipseResults.GetEllipse().RadiusX;
                    _CogEllipseResult.RadiusY         = FindEllipseResults.GetEllipse().RadiusY;
                    _CogEllipseResult.OriginX         = FindEllipseResults.GetEllipse().CenterX;
                    _CogEllipseResult.OriginY         = FindEllipseResults.GetEllipse().CenterY;
                    _CogEllipseResult.Rotation        = FindEllipseResults.GetEllipse().Rotation;
                    _CogEllipseResult.NgNumber        = _NgNumber;

                    _CogEllipseResult.PointPosXInfo   = new double[FindEllipseResults.Count];
                    _CogEllipseResult.PointPosYInfo   = new double[FindEllipseResults.Count];
                    _CogEllipseResult.PointStatusInfo = new bool[FindEllipseResults.Count];
                    for (int iLoopCount = 0; iLoopCount < FindEllipseResults.Count; ++iLoopCount)
                    {
                        if (true == FindEllipseResults[iLoopCount].Found)
                        {
                            _CogEllipseResult.PointPosXInfo[iLoopCount] = FindEllipseResults[iLoopCount].X;
                            _CogEllipseResult.PointPosYInfo[iLoopCount] = FindEllipseResults[iLoopCount].Y;
                        }
                        _CogEllipseResult.PointStatusInfo[iLoopCount] = FindEllipseResults[iLoopCount].Used;
                    }

                    _CogEllipseResult.DiameterMinAlgo = _CogEllipseAlgo.DiameterSize - _CogEllipseAlgo.DiameterMinus;
                    _CogEllipseResult.DiameterMaxAlgo = _CogEllipseAlgo.DiameterSize + _CogEllipseAlgo.DiameterPlus;

                    CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - Center X : {0}, Y : {1}", _CogEllipseResult.CenterX.ToString("F2"), _CogEllipseResult.CenterY.ToString("F2")), CLogManager.LOG_LEVEL.MID);
                    CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, String.Format(" - Radius X : {0}, Y : {1}", _CogEllipseResult.RadiusX.ToString("F2"), _CogEllipseResult.RadiusY.ToString("F2")), CLogManager.LOG_LEVEL.MID);
                }

                else
                {
                    CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Ellipse Find Fail!!", CLogManager.LOG_LEVEL.MID);

                    _CogEllipseResult.CenterX  = _CogEllipseAlgo.ArcCenterX;
                    _CogEllipseResult.CenterY  = _CogEllipseAlgo.ArcCenterY;
                    _CogEllipseResult.RadiusX  = _CogEllipseAlgo.ArcRadiusX;
                    _CogEllipseResult.RadiusY  = _CogEllipseAlgo.ArcRadiusY;
                    _CogEllipseResult.OriginX  = 0;
                    _CogEllipseResult.OriginY  = 0;
                    _CogEllipseResult.NgNumber = _NgNumber;

                    _CogEllipseResult.IsGood = false;
                }
            }

            CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.INFO, " - Result : " + _CogEllipseResult.IsGood.ToString(), CLogManager.LOG_LEVEL.MID);

            return(_Result);
        }
コード例 #10
0
ファイル: BlobScript.cs プロジェクト: Robofish2/Ziggy
    //#region "when the tool group is run"

    // The GroupRun function is called when the tool group is run.  The default
    // implementation provided here is equivalent to the normal behavior of the
    // tool group.  Modifying this function will allow you to change the behavior
    // when the tool group is run.
    public override bool GroupRun(ref string message, ref CogToolResultConstants result)
    {
        // To let the execution stop in this script when a debugger is attached, uncomment the following lines.
#if DEBUG
        if (System.Diagnostics.Debugger.IsAttached)
        {
            System.Diagnostics.Debugger.Break();
        }
#endif

        histCntr = 0;
        CogGraphicLabel myBaslerLabel = new CogGraphicLabel();
        CogGraphicLabel myFlirLabel   = new CogGraphicLabel();
        CogPointMarker  baslerMarker; //= new CogPointMarker();
        double          blobAngle        = 0;
        double          blobAngleRadians = 0;

        //Get references to the tools
        CogBlobTool      blobBaslerTool   = (CogBlobTool)toolGroup.Tools["FindWrappersInBasler"];
        CogBlobTool      blobFlirTool     = (CogBlobTool)toolGroup.Tools["PopsicleBlobFinder"];
        CogHistogramTool popsicleHistTool = (CogHistogramTool)toolGroup.Tools["PopsicleHistogramTool"];

        //Define the regions
        CogRectangleAffine popsicleRegion  = blobFlirTool.Region as CogRectangleAffine;
        CogRectangleAffine histogramRegion = blobFlirTool.Region as CogRectangleAffine;


        //Define the fonts
        System.Drawing.Font myBaslerFont = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        System.Drawing.Font myFlirFont   = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));


        //Reset stats
        angleFailures   = 0;
        thermalFailures = 0;

        //Reset any labels and rectangles from previous runs
        BaslerLabels.Clear();
        FlirLabels.Clear();
        FlirRectangles.Clear();


        //***** Run the tools to perform the search in the basler image *****

        //Update status strings for Visual Studio. Do not popup a message box for errors, this causes confusion with the operators.
        toolGroup.SetScriptTerminalData("BaslerStatus", "OK");
        toolGroup.SetScriptTerminalData("FlirStatus", "OK");

        bool acquireException = false;
        try
        {
            //Aquire an image from the Basler, send Exception to Visual Studio
            toolGroup.RunTool(toolGroup.Tools["BaslerAcqFifo"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Check power connections and communication cables.");
            acquireException = true;
        }

        try
        {
            //Aquire an image from the Flir, send Exception to Visual Studio
            toolGroup.RunTool(toolGroup.Tools["FlirAcqFifo"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Check power connections and communication cables.");
            acquireException = true;
        }
        if (acquireException)
        {
            return(false);
        }

        try
        {
            // Scale the Flir image to zoom in to smaller temperature range
            toolGroup.RunTool(toolGroup.Tools["ScaleFlirImagePmap"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: ScaleFlirImagePmap");
            return(false);
        }


        try
        {
            // Transform the images to calibrated space
            toolGroup.RunTool(toolGroup.Tools["CalBasler"], ref message, ref result);
            toolGroup.RunTool(toolGroup.Tools["CalFlir"], ref message, ref result);
        }
        catch (Exception ex)
        {
            //MessageBox.Show("Calibration tool error: " + ex.Message, "Script Exception");
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CalBasler");
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: CalFlir");
            return(false);
        }

        try
        {
            toolGroup.RunTool(toolGroup.Tools["CogPixelMapBasler"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogPixelMapBasler");
            return(false);
        }

        try
        {
            toolGroup.RunTool(toolGroup.Tools["CogIPOneImageTool1"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: CogIPOneImageTool1");
            return(false);
        }

        try
        {
            // Run the Flir hist tool
            toolGroup.RunTool(toolGroup.Tools["PopsicleHistogramTool"], ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("FlirStatus", "Script Error: " + ex.Message + " Failed: PopsicleHistogramTool");
            return(false);
        }

        try
        {
            // Run the blob tool and get a reference to the results.
            toolGroup.RunTool(blobBaslerTool, ref message, ref result);
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error: " + ex.Message + " Failed: Basler blobBaslerTool");
            return(false);
        }

        CogBlobResultCollection blobResults = blobBaslerTool.Results.GetBlobs();


        // Clear list before starting loop
        malBlobPoses.Clear();
        Crosshairs.Clear();

        // Get group input terminal data
        try
        {
            disableHist          = (bool)toolGroup.GetScriptTerminalData("DisableHistogramInspection");
            minPickAngle         = (double)toolGroup.GetScriptTerminalData("MinPickAngle");
            maxPickAngle         = (double)toolGroup.GetScriptTerminalData("MaxPickAngle");
            minPopsicleHistCount = (double)toolGroup.GetScriptTerminalData("MinPopsicleHistCount");
            VisStudio_Running    = (bool)toolGroup.GetScriptTerminalData("VS_Running");
            showArea             = (bool)toolGroup.GetScriptTerminalData("ShowArea");
            showHist             = (bool)toolGroup.GetScriptTerminalData("ShowHistCount");
            visSideXLength       = (double)toolGroup.GetScriptTerminalData("VisSideXLength");
            visSideYLength       = (double)toolGroup.GetScriptTerminalData("VisSideYLength");
            visFlirRegionXadj    = (double)toolGroup.GetScriptTerminalData("VisFlirRegionXadj");
            visFlirRegionYadj    = (double)toolGroup.GetScriptTerminalData("VisFlirRegionYadj");
        }
        catch (Exception ex)
        {
            //MessageBox.Show("Getting terminal data exception: ", ex.Message);
            toolGroup.SetScriptTerminalData("BaslerStatus", "Getting script data: " + ex.Message);
        }

        // Set run variables for manual triggering
        if (!VisStudio_Running)
        {
            minPopsicleHistCount = 0;
            minPickAngle         = -20;
            maxPickAngle         = 20;
            showArea             = true;
            showHist             = true;
            visSideXLength       = 200;
            visSideYLength       = 70;
            visFlirRegionXadj    = 0;
            visFlirRegionYadj    = 0;
        }


        // ***************************************
        // ******** Process the blobs *********
        // ***************************************
        try
        {
            foreach (CogBlobResult blob in blobResults)
            {
                // Set the transform for collections
                CogTransform2DLinear l2d = new CogTransform2DLinear();
                l2d.TranslationX = blob.GetBoundingBoxAtAngle(blob.Angle).CenterX;
                l2d.TranslationY = blob.GetBoundingBoxAtAngle(blob.Angle).CenterY;
                l2d.Rotation     = blob.Angle;
                blobAngleRadians = blob.Angle;

                // Crosshair setup for the Basler
                baslerMarker             = new CogPointMarker();
                baslerMarker.X           = l2d.TranslationX;
                baslerMarker.Y           = l2d.TranslationY;
                baslerMarker.Color       = CogColorConstants.Green;
                baslerMarker.GraphicType = CogPointMarkerGraphicTypeConstants.Crosshair;

                // Flir region
                CogRectangleAffine myFlirRegion = new CogRectangleAffine();
                myFlirRegion.CenterX     = l2d.TranslationX + visFlirRegionXadj;
                myFlirRegion.CenterY     = l2d.TranslationY + visFlirRegionYadj;
                myFlirRegion.Rotation    = l2d.Rotation;
                myFlirRegion.SideXLength = visSideXLength;
                myFlirRegion.SideYLength = visSideYLength;

                blobFlirTool.Region = myFlirRegion;
                toolGroup.RunTool(blobFlirTool, ref message, ref result);

                popsicleHistTool.Region = myFlirRegion;
                toolGroup.RunTool(popsicleHistTool, ref message, ref result);

                // Get the histogram results from the bin
                binHist = popsicleHistTool.Result.GetHistogram();

                // Count total pixels
                histCntr = 1;
                for (int i = 0; i < blobFlirTool.RunParams.SegmentationParams.HardFixedThreshold; i++)
                {
                    histCntr = histCntr + binHist[i];
                }

                myBaslerLabel = new CogGraphicLabel();
                myBaslerLabel.SetXYText(0, 0, "");
                myFlirLabel = new CogGraphicLabel();

                myBaslerLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                myFlirLabel.Font   = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                myFlirRegion.Visible = true;

                myBaslerLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter;
                myFlirLabel.Alignment   = CogGraphicLabelAlignmentConstants.BaselineCenter;

                // Decide to add the popsicle blob to the collection list
                if ((histCntr < minPopsicleHistCount) && (!disableHist))
                {
                    myBaslerLabel.Color = CogColorConstants.Red;
                    myFlirRegion.Color  = CogColorConstants.Red;


                    // Show the hist count in the Flir image
                    myFlirLabel.Color = CogColorConstants.Red;
                    if (showHist)
                    {
                        myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString());
                    }
                    thermalFailures++;
                }
                else
                {
                    myBaslerLabel.Color = CogColorConstants.Green;


                    // If histogram check is disabled, draw rectangle in yellow, else green
                    if (disableHist)
                    {
                        myFlirLabel.Color  = CogColorConstants.Red;
                        myFlirRegion.Color = CogColorConstants.Yellow;
                    }
                    else
                    {
                        myFlirLabel.Color  = CogColorConstants.Green;
                        myFlirRegion.Color = CogColorConstants.Green;
                    }

                    if (showHist)
                    {
                        myFlirLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Size: " + histCntr.ToString());
                    }


                    // Convert blob angle to degrees
                    blobAngle = blob.Angle * 180 / Math.PI;

                    if ((blobAngle > (double)minPickAngle) && (blobAngle < (double)maxPickAngle))
                    {
                        malBlobPoses.Add(l2d);

                        if (showArea)
                        {
                            myBaslerLabel.Color = CogColorConstants.Green;
                            myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY - 15, "Size: " + blob.Area.ToString("0"));
                        }
                    }
                    else
                    {
                        myBaslerLabel.Color = CogColorConstants.Red;
                        myBaslerLabel.SetXYText(l2d.TranslationX, l2d.TranslationY, "Angle: " + blobAngle.ToString("0"));
                        myFlirLabel.Color  = CogColorConstants.Red;
                        myFlirRegion.Color = CogColorConstants.Red;
                        angleFailures++;
                    }
                }

                myBaslerLabel.Rotation = blobAngleRadians;

                BaslerLabels.Add(myBaslerLabel);
                FlirLabels.Add(myFlirLabel);
                FlirRectangles.Add(myFlirRegion);
                Crosshairs.Add(baslerMarker);

                // Update group output terminals
                toolGroup.SetScriptTerminalData("AngleFailures", angleFailures);
                toolGroup.SetScriptTerminalData("ThermalFailures", thermalFailures);
                toolGroup.SetScriptTerminalData("BlobCollection", malBlobPoses);
            }
        }
        catch (Exception ex)
        {
            toolGroup.SetScriptTerminalData("BaslerStatus", "Script Error during blob processing: " + ex.Message);
            malBlobPoses.Clear(); // Clear positional data for this frame
        }

        // Returning False indicates we ran the tools in script, and they should not be
        // run by VisionPro
        return(false);
    }
コード例 #11
0
ファイル: CogForm.cs プロジェクト: XianheCode/Repair
        //初始化函数2
        private void initToolEdit()
        {
            //JobManagerEdit.Subject = m_JobManager;

            //一级视觉
            CogToolGroup m_ToolGroup_1 = (CogToolGroup)m_Job_1.VisionTool;

            cogToolGroupEditV21.Subject = m_ToolGroup_1;



            if (m_ToolGroup_1 == null)
            {
                MessageBox.Show("toolgroup1工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }


            blobTool_1 = (CogBlobTool)m_ToolGroup_1.Tools["CogBlobTool1"];
            if (blobTool_1 == null)
            {
                MessageBox.Show("blob1工具读取失败,请退出软件");
            }



            pmaTool_1 = (CogPMAlignTool)m_ToolGroup_1.Tools["caliPMATool"];
            if (pmaTool_1 == null)
            {
                MessageBox.Show("pma1工具读取失败,请退出软件");
            }

            calibTool_1 = (CogCalibNPointToNPointTool)m_ToolGroup_1.Tools["CogCalibNPointToNPointTool1"];
            if (calibTool_1 == null)
            {
                MessageBox.Show("calib1工具读取失败,请退出软件");
            }

            acqFifoTool_1 = (CogAcqFifoTool)m_ToolGroup_1.Tools["CogAcqFifoTool1"];
            if (acqFifoTool_1 == null)
            {
                MessageBox.Show("acqfifo1工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }

            mAcqFifo_1 = acqFifoTool_1.Operator;

            if (mAcqFifo_1 == null)
            {
                MessageBox.Show("macqfifo1为 null,窗口将自动关闭");
                this.Close();
                return;
            }


            mAcqFifo_1.Timeout = 1000;



            //二级视觉
            CogToolGroup m_ToolGroup_2 = (CogToolGroup)m_Job_2.VisionTool;

            cogToolGroupEditV22.Subject = m_ToolGroup_2;



            if (m_ToolGroup_2 == null)
            {
                MessageBox.Show("toolgroup2工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }

            blobTool_2 = (CogBlobTool)m_ToolGroup_2.Tools["CogBlobTool1"];
            if (blobTool_2 == null)
            {
                MessageBox.Show("blob2工具读取失败,请退出软件");
            }

            pmaTool_2 = (CogPMAlignTool)m_ToolGroup_2.Tools["caliPMATool"];
            if (pmaTool_2 == null)
            {
                MessageBox.Show("pma2工具读取失败,请退出软件");
            }

            calibTool_2 = (CogCalibNPointToNPointTool)m_ToolGroup_2.Tools["CogCalibNPointToNPointTool1"];
            if (calibTool_2 == null)
            {
                MessageBox.Show("calib2工具读取失败,请退出软件");
            }


            acqFifoTool_2 = (CogAcqFifoTool)m_ToolGroup_2.Tools["CogAcqFifoTool1"];
            if (acqFifoTool_2 == null)
            {
                MessageBox.Show("acqfifo2工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }

            mAcqFifo_2 = acqFifoTool_2.Operator;

            if (mAcqFifo_2 == null)
            {
                MessageBox.Show("macqfifo2为 null,窗口将自动关闭");
                this.Close();
                return;
            }



            mAcqFifo_2.Timeout = 1000;



            ////对比度Test
            //ICogAcqContrast mContrast = mAcqFifo_2.OwnedContrastParams;
            //double val = mContrast.Contrast;
            //Console.WriteLine(val);



            //三级视觉
            CogToolGroup m_ToolGroup_3 = (CogToolGroup)m_Job_3.VisionTool;

            cogToolGroupEditV23.Subject = m_ToolGroup_3;


            if (m_ToolGroup_3 == null)
            {
                MessageBox.Show("toolgroup3工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }

            blobTool_3 = (CogBlobTool)m_ToolGroup_3.Tools["CogBlobTool1"];
            if (blobTool_3 == null)
            {
                MessageBox.Show("blob3工具读取失败,请退出软件");
            }
            pmaTool_3 = (CogPMAlignTool)m_ToolGroup_3.Tools["caliPMATool"];
            if (pmaTool_3 == null)
            {
                MessageBox.Show("pma3工具读取失败,请退出软件");
            }

            calibTool_3 = (CogCalibNPointToNPointTool)m_ToolGroup_3.Tools["CogCalibNPointToNPointTool1"];
            if (calibTool_3 == null)
            {
                MessageBox.Show("calib3工具读取失败,请退出软件");
            }


            acqFifoTool_3 = (CogAcqFifoTool)m_ToolGroup_3.Tools["CogAcqFifoTool1"];
            if (acqFifoTool_3 == null)
            {
                MessageBox.Show("acqfifo3工具读取失败,窗口将自动关闭");
                this.Close();
                return;
            }

            mAcqFifo_3 = acqFifoTool_3.Operator;

            if (mAcqFifo_3 == null)
            {
                MessageBox.Show("macqfifo3为 null,窗口将自动关闭");
                this.Close();
                return;
            }



            mAcqFifo_3.Timeout = 1000;
        }
コード例 #12
0
ファイル: CogForm.cs プロジェクト: XianheCode/Repair
        private bool getBlobBoundary(out double[] pos_x, out double[] pos_y, out int pos_number, int toolNum, int index)
        {
            CogBlobTool blobTool = null;

            pos_x      = null;
            pos_y      = null;
            pos_number = 0;

            switch (toolNum)
            {
            case 1:
                blobTool = blobTool_1;
                break;

            case 2:
                blobTool = blobTool_2;
                break;

            case 3:
                blobTool = blobTool_3;
                break;

            default:
                return(false);
            }

            if (blobTool.Results == null)
            {
                return(false);
            }

            CogBlobResultCollection blobResult = blobTool.Results.GetBlobs();

            if (blobResult == null)
            {
                return(false);
            }
            int number = blobResult.Count;

            if (index >= number || index < 0)
            {
                return(false);
            }

            CogPolygon blobBoundary = blobResult[index].GetBoundary();


            int verticesNum = blobBoundary.NumVertices;

            pos_x = new double[verticesNum];
            pos_y = new double[verticesNum];

            for (int i = 0; i < verticesNum; i++)
            {
                pos_x[i] = blobBoundary.GetVertexX(i);
                pos_y[i] = blobBoundary.GetVertexY(i);
            }

            pos_number = verticesNum;

            return(true);
        }