Editar

Compartir a través de


VNDetectedObjectObservation.BoundingBox Property

Definition

The bounding box of the detected feature, in normalized coordinates.

public virtual CoreGraphics.CGRect BoundingBox { [Foundation.Export("boundingBox", ObjCRuntime.ArgumentSemantic.UnsafeUnretained)] get; }
member this.BoundingBox : CoreGraphics.CGRect

Property Value

Attributes

Remarks

As with other rectangles in the Vision namespace, the CGRect uses normalized coordinates in the range 0..1.

The following example shows how bounding boxes might be drawn over an existing UIImageView. Note that the Y values are adjusted relative to the normalized coordinates origin in the lower-left, not the upper-left:

var frs = request as VNDetectFaceRectanglesRequest;
// Assert frs == findFacesRequest ? 
var rs = frs.GetResults<VNFaceObservation>();
foreach (var fo in rs)
{
   var aFaceRectangle = fo.BoundingBox;
   InvokeOnMainThread(() =>
  {
	  var x = aFaceRectangle.Left * faceContainingImage.Frame.Width;
	  var y = faceContainingImage.Frame.Height - aFaceRectangle.Top * faceContainingImage.Frame.Height;
	  var w = aFaceRectangle.Width * faceContainingImage.Frame.Width;
	  var h = -aFaceRectangle.Height * faceContainingImage.Frame.Height;

	  var scaledRect = new CGRect(x, y, w, h);
	  var rectView = new UIView(scaledRect);
	  rectView.Layer.BorderColor = UIColor.Green.CGColor;
	  rectView.Layer.BorderWidth = 2;
	  rectView.Layer.Opacity = 1;
	  faceContainingImage.AddSubview(rectView);
  });
}

Applies to