public async Task <IActionResult> UploadAsync(IFormFile file) { IPainter painter = new RectangleMarker(); CompareFacesResponse response; try { var sourceImg = Request.Form.Files[0]; var targetImg = Request.Form.Files[1]; var srcImg = ImageHelper.ConvertFormFileToMemoryStream(sourceImg); var trgtImg = ImageHelper.ConvertFormFileToMemoryStream(targetImg); if (sourceImg != null) // && targetImg != null) { response = await _compareFaces.CompareAsync(srcImg, trgtImg); string markedImg = ""; if (response.FaceMatches.Count > 0) { System.Drawing.Image output = System.Drawing.Image.FromStream(trgtImg); foreach (var box in response.FaceMatches) { var boundingBox = box.Face.BoundingBox; output = painter.DrawOnImage(output, targetImg.FileName, boundingBox.Height, boundingBox.Width, boundingBox.Top, boundingBox.Left, Color.LightGreen); } foreach (var box in response.UnmatchedFaces) { var boundingBox = box.BoundingBox; output = painter.DrawOnImage(output, targetImg.FileName, boundingBox.Height, boundingBox.Width, boundingBox.Top, boundingBox.Left, Color.Red); } markedImg = ImageHelper.ConvertImageToBase64(output); } return(Ok(new { response, markedImg })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> UploadAsync(IFormFile[] imgs) { IPainter painter = new RectangleMarker(); try { var file = Request.Form.Files[0]; var stream = ImageHelper.ConvertFormFileToMemoryStream(file); if (stream != null) { var response = new RecognizeCelebritiesResponse(); response = await _recognizeCelibrities.Recognize(stream); string markedImg = ""; if (response.CelebrityFaces.Count > 0) { System.Drawing.Image output = System.Drawing.Image.FromStream(stream); foreach (var box in response.CelebrityFaces) { var boundingBox = box.Face.BoundingBox; output = painter.DrawOnImage(output, file.FileName, boundingBox.Height, boundingBox.Width, boundingBox.Top, boundingBox.Left, Color.LightGreen); } markedImg = ImageHelper.ConvertImageToBase64(output); } return(Ok(new { response, markedImg })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
private void Vision_OnRectanglesRecognized(object sender, RectanglesRecognizedArgs e) { var rectangles = e.rectangles.OrderByDescending(entry => entry.area).ToList(); var found = false; foreach (var rect in rectangles) { ARHitTest.CastRectangle(rect, onHit: (topLeft, topRight, bottomRight, bottomLeft) => { if (_marker == null) { _marker = Instantiate(_rectangleMarkerPrefab); Debug.Assert(_marker != null, "Could not instantiate rectangle marker prefab."); // Reset transform _marker.transform.position = Vector3.zero; _marker.transform.rotation = Quaternion.identity; _marker.transform.localScale = Vector3.one; } // Assign the corners of the marker game object to the surface hit points _marker.TopLeft = topLeft; _marker.TopRight = topRight; _marker.BottomRight = bottomRight; _marker.BottomLeft = bottomLeft; // Closure is synchronous found = true; }); if (found) { break; } } if (_marker != null) { // Hide the marker if no rectangles were found _marker.gameObject.SetActive(found); } }
private MarkerBase CreateArrowMarker(double x, double y, double angle, ShapeStyleViewModel shapeStyleViewModel, ArrowStyleViewModel style) { switch (style.ArrowType) { default: case ArrowType.None: { var marker = new NoneMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Point = new SKPoint((float)x, (float)y); return(marker); } case ArrowType.Rectangle: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new RectangleMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = MatrixHelper.Rotation(angle, new SKPoint((float)x, (float)y)); marker.Point = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)(x - sx), (float)y)); var rect2 = new Rect2(x - sx, y - ry, sx, sy); marker.Rect = SKRect.Create((float)rect2.X, (float)rect2.Y, (float)rect2.Width, (float)rect2.Height); return(marker); } case ArrowType.Ellipse: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new EllipseMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = MatrixHelper.Rotation(angle, new SKPoint((float)x, (float)y)); marker.Point = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)(x - sx), (float)y)); var rect2 = new Rect2(x - sx, y - ry, sx, sy); marker.Rect = SKRect.Create((float)rect2.X, (float)rect2.Y, (float)rect2.Width, (float)rect2.Height); return(marker); } case ArrowType.Arrow: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new ArrowMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = MatrixHelper.Rotation(angle, new SKPoint((float)x, (float)y)); marker.Point = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)x, (float)y)); marker.P11 = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)(x - sx), (float)(y + sy))); marker.P21 = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)x, (float)y)); marker.P12 = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)(x - sx), (float)(y - sy))); marker.P22 = MatrixHelper.TransformPoint(marker.Rotation, new SKPoint((float)x, (float)y)); return(marker); } } }
private MarkerBase CreateArrowMarker(double x, double y, double angle, ShapeStyleViewModel shapeStyleViewModel, ArrowStyleViewModel style) { switch (style.ArrowType) { default: { var marker = new NoneMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Point = new A.Point(x, y); return(marker); } case ArrowType.Rectangle: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new RectangleMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y)); marker.Point = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y)); var rect2 = new Rect2(x - sx, y - ry, sx, sy); marker.Rect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height); return(marker); } case ArrowType.Ellipse: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new EllipseMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y)); marker.Point = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y)); var rect2 = new Rect2(x - sx, y - ry, sx, sy); var rect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height); marker.EllipseGeometry = new AM.EllipseGeometry(rect); return(marker); } case ArrowType.Arrow: { double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; var marker = new ArrowMarker(); marker.ShapeViewModel = Line; marker.ShapeStyleViewModel = shapeStyleViewModel; marker.Style = style; marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y)); marker.Point = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y)); marker.P11 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y + sy)); marker.P21 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y)); marker.P12 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y - sy)); marker.P22 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y)); return(marker); } } }