Пример #1
0
        private Result DetectAndPaintImage(string imageFilePath)
        {
            //Predict the objects in the image
            _modelScorer.DetectObjectsUsingModel(imageFilePath);
            var img = _modelScorer.PaintImages(imageFilePath);

            using (MemoryStream m = new MemoryStream())
            {
                img.Save(m, img.RawFormat);
                byte[] imageBytes = m.ToArray();

                // Convert byte[] to Base64 String
                base64String = Convert.ToBase64String(imageBytes);
                var result = new Result {
                    imageString = base64String
                };
                return(result);
            }
        }
Пример #2
0
        public async Task <IActionResult> IdentifyObjects(IFormFile imageFile)
        {
            if (imageFile.Length == 0)
            {
                return(BadRequest());
            }

            string imageFilePath = "", fileName = "";

            try
            {
                //Save the temp image into the temp-folder
                fileName = await _imageWriter.UploadImageAsync(imageFile, _imagesTmpFolder);

                imageFilePath = Path.Combine(_imagesTmpFolder, fileName);

                _logger.LogInformation($"Start processing image file { imageFilePath }");

                //Measure execution time
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //Predict the objects in the image
                var objectsNames = _modelScorer.DetectObjectsUsingModel(imageFilePath);
                _modelScorer.PaintImages(imageFilePath);

                //Stop measuring time
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;

                _logger.LogInformation($"Image processed in {elapsedMs} miliseconds");

                return(Ok(objectsNames));
            }
            catch (Exception e)
            {
                _logger.LogInformation("Error is: " + e.Message);
                return(BadRequest());
            }
        }
Пример #3
0
        public Result Get([FromQuery] string url)
        {
            string imageFileRelativePath = @"../../.." + url;
            string imageFilePath         = ModelHelpers.GetAbsolutePath(imageFileRelativePath);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            //Predict the objects in the image
            var objectsNames = _modelScorer.DetectObjectsUsingModel(imageFilePath);
            var img          = _modelScorer.PaintImages(imageFilePath);

            using (MemoryStream m = new MemoryStream())
            {
                img.Save(m, img.RawFormat);
                byte[] imageBytes = m.ToArray();

                // Convert byte[] to Base64 String
                string base64String = Convert.ToBase64String(imageBytes);
                return(new Result {
                    imageString = base64String
                });
            }
        }