コード例 #1
0
        /// <summary>
        /// Get and notify new ball coordinates
        /// </summary>
        public override void Job()
        {
            //Detach from streamer
            _publisher.Dettach(this);

            //get current ball coordinates
            BallCoordinates coordinates = SampleCoordinates();

            //show current ball coordinates on screen and GUI
            System.Drawing.PointF p = Transformation.InvertTransform(new System.Drawing.PointF(_x, _y));
            UpdateMarkup(Helpers.eMarkupKey.BALL_CIRCLE_MARK, new Point(p.X, p.Y), _ballRadius * 2);
            UpdateStatistics(Helpers.eStatisticsKey.BasicImageProcessingInfo,
                             String.Format("Generated coordinates: {0}x{1}", _x, _y));

            //set current coordinates to update
            _coordinatesUpdater.LastBallCoordinates = coordinates;

            //publish new ball coordinates
            BallLocationPublisher.UpdateAndNotify();

            //attach back to streamer
            _publisher.Attach(this);
        }
コード例 #2
0
        /// <summary>
        /// Demo Image Processing Unit constructor
        /// </summary>
        /// <param name="streamer">DemoStreamer instance</param>
        /// <param name="onUpdateMarkup">On Update Markup delegate</param>
        /// <param name="onUpdateStatistics">On Update Statistics delegate</param>
        public DemoImageProcessingUnit(DemoStreamer streamer,
                                       Helpers.UpdateMarkupCircleDelegate onUpdateMarkup, Helpers.UpdateStatisticsDelegate onUpdateStatistics) :
            base(streamer, onUpdateMarkup, onUpdateStatistics)
        {
            //Set Foosbot world sizes - axe X x axe Y
            _rightBorder  = Configuration.Attributes.GetValue <double>(Configuration.Names.FOOSBOT_AXE_X_SIZE);
            _buttomBorder = Configuration.Attributes.GetValue <double>(Configuration.Names.FOOSBOT_AXE_Y_SIZE);

            //Create Transfomation Matrix - to present coordinates of a Ball in GUI
            InitializeTransformation(Convert.ToSingle(streamer.FrameWidth),
                                     Convert.ToSingle(streamer.FrameHeight), Convert.ToSingle(_rightBorder),
                                     Convert.ToSingle(_buttomBorder));

            //Set this Demo Image Processing Unit as observer for Demo Streamer
            streamer.DemoImageProcessingUnit = this;

            //Create Ball Location Publisher for Observers
            _coordinatesUpdater   = new DemoLastBallCoordinatesUpdater();
            BallLocationPublisher = new BallLocationPublisher(_coordinatesUpdater);

            //Set borders of frame to include ball radius
            _rightBorder  -= _ballRadius;
            _buttomBorder -= _ballRadius;
            _leftBorder   += _ballRadius;
            _upeerBorder  += _ballRadius;

            //Set start ball coordinates
            _x = Convert.ToInt32(_rightBorder / 2);
            _y = Convert.ToInt32(_buttomBorder / 2);

            //Instantiate random generator
            _random = new Random();

            //Start Generating Locations in separate Thread
            BeginInvokeGenerateLocation();
        }