void DrawLandmark(VNFaceLandmarkRegion2D feature, CGRect scaledBoundingBox, bool closed, UIColor color) { if (feature == null) { return; } var mappedPoints = feature.NormalizedPoints.Select(o => new CGPoint(x: o.X * scaledBoundingBox.Width + scaledBoundingBox.X, y: o.Y * scaledBoundingBox.Height + scaledBoundingBox.Y)); using (var newLayer = new CAShapeLayer()) { newLayer.Frame = _view.Frame; newLayer.StrokeColor = color.CGColor; newLayer.LineWidth = 2; newLayer.FillColor = UIColor.Clear.CGColor; using (UIBezierPath path = new UIBezierPath()) { path.MoveTo(mappedPoints.First()); foreach (var point in mappedPoints.Skip(1)) { path.AddLineTo(point); } if (closed) { path.AddLineTo(mappedPoints.First()); } newLayer.Path = path.CGPath; } _shapeLayer.AddSublayer(newLayer); } }
// Uses VNUtils to calculate the points, just to test the native API void ConvertPoints2(VNFaceLandmarkRegion2D landmark, CGRect boundingBox, nuint imgWidth, nuint imgHeight) { var points = landmark.Points; var faceLandmarkPoints = points.Select(p => VNUtils.GetImagePoint(p, boundingBox, imgWidth, imgHeight) ); DispatchQueue.MainQueue.DispatchAsync(() => { Draw(faceLandmarkPoints.ToArray()); }); }
void ConvertPoints(VNFaceLandmarkRegion2D landmark, CGRect boundingBox) { var points = landmark.Points; var faceLandmarkPoints = points.Select(p => { return(new CGPoint( x: ((nfloat)p.X) * boundingBox.Width + boundingBox.X, y: ((nfloat)p.Y) * boundingBox.Height + boundingBox.Y )); }); DispatchQueue.MainQueue.DispatchAsync(() => { Draw(faceLandmarkPoints.ToArray()); }); }