コード例 #1
0
 protected void Start()
 {
     RangeDetector        = RangeDetector ?? GetComponentInChildren <TagDetector>();
     parentTowerComponent = parentTowerComponent ?? GetComponentInParent <TowerComponent>() ?? null;
     ParentTowerLegacy    = ParentTowerLegacy ?? GetComponentInParent <TowerControllerLegacy>() ?? null;
     ParentTowerSlot      = parentTowerSlot ?? GetComponentInParent <TowerSlotController>() ?? null;
 }
コード例 #2
0
    void Start()
    {
        rb = GetComponent <Rigidbody>();

        //Get  Scripts
        tagDetectorScript = gameObject.GetComponentInChildren <TagDetector>();

        //Set the jump timer
        jumpTimer = DefaultJumpTime + JumpBoosterDelay;
    }
コード例 #3
0
ファイル: PoliceAI.cs プロジェクト: nevin123/Smuggler
    void Start()
    {
        playerDetector = transform.GetChild(0).gameObject.GetComponent <TagDetector>();

        startPosition = transform.position;

        motor    = GetComponent <PlayerMotor>();
        path     = new NavMeshPath();
        lastPath = new NavMeshPath();
    }
コード例 #4
0
 public override void InitBehavior()
 {
     Detector = Detector ?? UnitObject.RangeDetector;
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: zmechanic/Stub_EmguCV
        private void FindTags(Mat frame)
        {
            Debug.WriteLine("");

            using (var frameImage = frame.ToPipelineImage())
            {
                var imageRGB = frameImage.RgbImage.Clone();

                var cropImageSize              = new Size(128, 128);
                var detectSubrectArea          = 25 * ((cropImageSize.Width * cropImageSize.Height) / (64 * 64));
                var tagDetector                = new TagDetector(cropImageSize);
                var frameOneColorImageFiltered = frameImage.IsolateColorBlack(100);
                var rects = frameOneColorImageFiltered.Clone().FindRectangles(1000);

                foreach (var rect in rects.OrderByDescending(_ => _.BoundingBoxArea))
                {
                    var rectBoundingBox = rect.BoundingBox;

                    // Ignore largest rectangles detected at the edge of image due to contrasting area.
                    if (rectBoundingBox.Left < 5 || rectBoundingBox.Top < 5 ||
                        rectBoundingBox.Right > frameOneColorImageFiltered.Width - 5 || rectBoundingBox.Bottom > frameOneColorImageFiltered.Height - 5)
                    {
                        continue;
                    }

                    // Attempt to detect if there is large inner rectangle. It may only indicate inner boundary of tag,
                    // otherwise it's presence will render tag unusable.
                    var hasLargeInnerRect = false;

                    // ReSharper disable once LoopCanBeConvertedToQuery
                    foreach (var otherRect in rects)
                    {
                        if (otherRect.Equals(rect))
                        {
                            continue;
                        }

                        var otherRectBoundingBox = otherRect.BoundingBox;
                        if (rectBoundingBox.Contains(otherRectBoundingBox))
                        {
                            if ((otherRectBoundingBox.Width * otherRectBoundingBox.Height) / (rectBoundingBox.Width * rectBoundingBox.Height) > 0.7)
                            {
                                hasLargeInnerRect = true;
                                break;
                            }
                        }
                    }

                    // Skip current rectangle if we have detected a large ineer rectangle.
                    if (hasLargeInnerRect)
                    {
                        continue;
                    }

                    imageRGB.Draw(rect.BoundingBoxInt, new Rgb(255, 0, 0));

                    // Extract image part defined by rectangle and normalize it so it's axis aligned.
                    using (var rectImage = frameOneColorImageFiltered
                                           .GetAxisAlignedImagePart(
                               rect,
                               new Quadrilateral(new PointF(0, 0), new PointF(0, cropImageSize.Height), new PointF(cropImageSize.Width, cropImageSize.Height), new PointF(cropImageSize.Width, 0)),
                               cropImageSize))
                    {
                        _viewers[1].Image = rectImage;

                        // Find rectangles within cropped image.
                        var detectedSubrects = rectImage.FindRectangles(detectSubrectArea);

                        // We must have at least two rectangles to proceed with tag detection.
                        if (detectedSubrects.Length >= 2)
                        {
                            for (var cornerIndex = 0; cornerIndex < 4; cornerIndex++)
                            {
                                imageRGB.Draw(cornerIndex.ToString(), new Point((int)rect.Points[cornerIndex].X, (int)rect.Points[cornerIndex].Y), FontFace.HersheyPlain, 1.5D, new Rgb(Color.SpringGreen), 2);
                                imageRGB.Draw(new CircleF(new PointF(rect.Points[cornerIndex].X, rect.Points[cornerIndex].Y), 5), new Rgb(Color.Magenta), 2);
                            }

                            // Check if cropped image contains a tag markers.
                            var tagDetectionResult = tagDetector.IsTag(detectedSubrects, rect);
                            if (tagDetectionResult.IsTagPresent)
                            {
                                Debug.WriteLine("{0} ||| {1} ||| X={2},Y={3}", tagDetectionResult.RotationAngle, tagDetectionResult.Confidence, rect.MinX, rect.MinY);

                                using (var normalizedTagImage = tagDetector.NormalizeTagImage(rectImage, tagDetectionResult, true, true))
                                {
                                    if (_storedImage == null)
                                    {
                                        _storedImage = normalizedTagImage.Copy(new Rectangle(5, 5, normalizedTagImage.Width - 10, normalizedTagImage.Height - 10));
                                    }

                                    using (var matchResult = normalizedTagImage.MatchTemplate(_storedImage, TemplateMatchingType.CcoeffNormed))
                                    {
                                        double[] minValues, maxValues;
                                        Point[]  minLocations, maxLocations;
                                        matchResult.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

                                        if (maxValues[0] > 0.8)
                                        {
                                            Debug.WriteLine("!!!!!!!!!!!!!!! {0}    {1}", maxValues[0], maxLocations[0]);
                                        }
                                    }

                                    //Debug.WriteLine(normalizedTagImage.GetSubRect(new Rectangle(0, 0, cropImageSize.Width, 5)).CountNonzero()[0]);

                                    //normalizedTagImage.Draw(new Rectangle(0, 0, (int)(cropImageSize.Width * 0.2), (int)(cropImageSize.Height * 0.2)), new Gray(255), -1);

                                    _viewers[2].Image = normalizedTagImage;
                                }
                            }
                        }
                    }
                }

                _viewers[0].Image = imageRGB;

                imageRGB.Dispose();
            }
        }