Exemplo n.º 1
0
        /// <summary>
        /// Called by `ViewController.OnFrameCaptured` once per frame with the buffer processed by the image-processing pipeline in
        /// `VideoCaptureDelegate.DidOutputSampleBuffer`
        /// </summary>
        /// <param name="buffer">The captured video frame.</param>
        public void OnFrameCaptured(CVPixelBuffer buffer)
        {
            // Run the tracker
            var request = new VNTrackObjectRequest(trackedRectangle, ObjectTracked);

            request.TrackingLevel = VNRequestTrackingLevel.Accurate;
            NSError error;
            var     requests = new[] { request };

            overlay.InvokeOnMainThread(() => overlay.Clear());
            trackingHandler.Perform(requests, buffer, out error);
            if (error != null)
            {
                InvokeOnMainThread(() => overlay.Message = error.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asynchronously called by the Vision subsystem subsequent to `Perform` in `OnFrameCaptured`
        /// </summary>
        /// <param name="request">The request sent to the Vision subsystem.</param>
        /// <param name="err">If not null, describes an error in Vision.</param>
        private void RectanglesDetected(VNRequest request, NSError err)
        {
            if (err != null)
            {
                overlay.Message = err.ToString();
                Console.Error.WriteLine(err);
                return;
            }
            overlay.Clear();

            observations        = request.GetResults <VNRectangleObservation>();
            overlay.StrokeColor = UIColor.Blue.CGColor;

            //Draw all detected rectangles in blue
            foreach (var o in observations)
            {
                var quad = new[] { o.TopLeft, o.TopRight, o.BottomRight, o.BottomLeft };
                RectangleDetected(quad);
            }
        }