public async Task <ActionResult> Step2FromSample() { string Url = Request.Url.Scheme + "://" + Request.Url.Authority + "/Content/img/sampledesigns/" + Request.Url.Segments[Request.Url.Segments.Length - 1] + ".jpg"; byte[] buffer; var webRequest = WebRequest.Create(Url); using (var response = webRequest.GetResponse()) using (var content = response.GetResponseStream()) { var img = Image.FromStream(content); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); buffer = ms.ToArray(); } //Optimize size and quality for best performance buffer = ImageHelper.OptimizeImage(buffer, 100, 40); //generate correlationid var correlationID = Guid.NewGuid().ToString(); //save the file on the storage var objectDetector = new ObjectDetectionAppService(); await objectDetector.SaveResults(buffer, correlationID, "original.png"); //Jump directly to progress return(View("step3", new ContentViewModel { CorrelationId = correlationID })); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { //Get image byte array from request var content = await req.Content.ReadAsByteArrayAsync(); if (content == null || content.Length == 0) { return(req.CreateResponse(HttpStatusCode.BadRequest, "Request content is empty.")); } else { log.Info($"found binary content->Size: {content.Length} bytes"); } //Use correlationId to identify each session and results var correlationID = req.GetCorrelationId().ToString(); //Pass byte array to object detector app service var objectDetector = new ObjectDetectionAppService(); var result = await objectDetector.GetPredictionAsync(content); if (result != null) { await objectDetector.SaveResults(result, correlationID); await objectDetector.SaveResults(content, correlationID, "original.png"); await objectDetector.SaveResults(content.DrawRectangle(result), correlationID, "predicted.png"); byte[] jsonContent = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(result)); await objectDetector.SaveResults(jsonContent, correlationID, "results.json"); } return(req.CreateResponse(HttpStatusCode.OK, correlationID)); }
private static async Task saveResults2(string correlationId, ObjectDetectionAppService objectDetector, GroupBox groupBox, string html) { //TODO: Store this as Text await objectDetector.SaveResults(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(groupBox)), correlationId, "groups.json"); await objectDetector.SaveHtmlResults(html, correlationId, "generated.html"); }
private static async Task saveResults(string correlationId, ObjectDetectionAppService objectDetector, byte[] content, System.Collections.Generic.IList <Core.Entities.PredictedObject> result, byte[] jsonContent) { //TODO: Skip this once we generate online slices await objectDetector.SaveResults(result, correlationId); await objectDetector.SaveResults(content.DrawRectangle(result), correlationId, "predicted.png"); //TODO: Store this as Text await objectDetector.SaveResults(jsonContent, correlationId, "results.json"); }
public async Task <JsonResult> SaveFile() { var data = Request["imgBase64"]; var folderId = Request["folderId"]; byte[] content = Convert.FromBase64String(data); var objectDetector = new ObjectDetectionAppService(); await objectDetector.SaveResults(content, folderId, "html.png"); return(Json(new { folderId = folderId })); }
public async Task <ActionResult> Step2() { byte[] buffer = null; HttpPostedFileBase file = Request.Files["imageData"]; //file or base64 content if (file == null) //check if image is submitted as base64 { var image = Request["imageData"]; if (!String.IsNullOrWhiteSpace(image)) { buffer = Convert.FromBase64String(image); } else { throw new ApplicationException("No file or base64 content found"); } } else { buffer = new byte[file.ContentLength]; using (var ms = new MemoryStream()) { await file.InputStream.CopyToAsync(ms); buffer = ms.ToArray(); } } //Optimize size and quality for best performance buffer = ImageHelper.OptimizeImage(buffer, 100, 40); //generate correlationid var correlationID = Guid.NewGuid().ToString(); //save the file on the storage var objectDetector = new ObjectDetectionAppService(); await objectDetector.SaveResults(buffer, correlationID, "original.png"); //Jump directly to progress return(View("step3", new ContentViewModel { CorrelationId = correlationID })); }
public async Task <JsonResult> callBackEnd(string correlationId) { //Pass byte array to object detector app service var objectDetector = new ObjectDetectionAppService(); byte[] content = await objectDetector.GetFile(correlationId, "original.png"); var html = ""; var result = await objectDetector.GetPredictionAsync(content); if (result != null) { byte[] jsonContent = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(result)); await saveResults(correlationId, objectDetector, content, result, jsonContent); var groupBox = await objectDetector.CreateGroupBoxAsync(result); html = this.RenderViewToString2 <GroupBox>("/Views/Layout/RawGroupBox2.cshtml", groupBox); await saveResults2(correlationId, objectDetector, groupBox, html); } return(Json(new { id = correlationId, generatedHtml = html })); }