Example #1
0
        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));
        }
        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 }));
        }