public async Task <IActionResult> RunAnnotateImage(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "images/annotate")] HttpRequest req,
            [AccessToken] AccessTokenResult accessTokenResult,
            ILogger log
            )
        {
            log.LogInformation("Annotate Image");

            var options = new JsonSerializerOptions
            {
                IgnoreNullValues            = true,
                PropertyNameCaseInsensitive = true
            };

            var body = await new StreamReader(req.Body).ReadToEndAsync();
            ImageAnnotationBoundingBoxResult imgBBox = JsonSerializer.Deserialize <ImageAnnotationBoundingBoxResult>(body, options);
            var result = await _imageService.AnnotateImage(imgBBox);

            if (result)
            {
                return(new StatusCodeResult(200));
            }
            else
            {
                return(new StatusCodeResult(500));
            }
        }
        public async Task <bool> AnnotateImage(ImageAnnotationBoundingBoxResult aBbox)
        {
            try
            {
                using (var conn = new Npgsql.NpgsqlConnection(_configService.GetValue(ConfigurationServiceWellKnownKeys.PostgresqlDbConnectionString)))
                {
                    await conn.OpenAsync();

                    Guid id          = Guid.NewGuid();
                    var  insertQuery = "INSERT INTO label.\"bounding_boxes\" (id, id_creator_fk, createdon, id_ref_trash_type_fk, id_ref_images_for_labelling, location_x, location_y, width, height) VALUES ( @Id, @CreatorId, current_timestamp, @TrashId, @ImageId, @Location_x, @Location_y, @Width, @Height)";

                    var result = await conn.ExecuteAsync(insertQuery,
                                                         new
                    {
                        Id         = id,
                        CreatorId  = aBbox.CreatorId,
                        TrashId    = aBbox.TrashId,
                        ImageId    = aBbox.ImageId,
                        Location_x = aBbox.Location_x,
                        Location_y = aBbox.Location_y,
                        Width      = aBbox.Width,
                        Height     = aBbox.Height
                    }
                                                         );

                    return(result > 0);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
 public async Task <bool> AnnotateImage(ImageAnnotationBoundingBoxResult aBbox)
 {
     return(await _imageStore.AnnotateImage(aBbox));
 }