public void DeleteImage(Topic topic, string imageFileName) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageFileName)) { throw new ArgumentNullException(nameof(imageFileName)); } #endregion ImageLabel imageLabel = CreateTemporaryImageLabel(topic, imageFileName); // remove all labels LabelService.DeleteLabels(topic, imageLabel); // remove image ImageFileRepository.DeleteImageFile(topic, imageFileName); ImageRepository.DeleteImage(topic, imageFileName); }
static void Main(string[] args) { string imgFolderPath = GetImageFolderPath(); IImageFileRepository repository = new ImageFileRepository(new ImageContext()); Connection connection = new Connection(ACCESS_KEY_ID, SECRET_ACCESS_KEY, URL); var imageFiles = connection.GetItems(BUCKET); repository.Clear(); repository.SaveChanges(); foreach (var image in imageFiles) { string imgFilePath = Path.Combine(imgFolderPath, image.FileName); connection.DownloadImage(BUCKET, image.FileName, imgFilePath); var pixels = Image.GetImagePixels(imgFilePath); repository.Add(image); for (int i = 0; i < pixels.Count; i++) { image.Pixels.Add(pixels[i]); if (i != 0 && i % 100 == 0) { repository.SaveChanges(); } } Console.WriteLine(string.Format("Finish processing {0} file", image.FileName)); } Console.WriteLine(string.Format("There are {0} file(s) have been processed.", imageFiles.Count)); Console.ReadLine(); }
public IEnumerable <Label> GetBoundingBoxes(Topic topic, string imageId) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageId)) { throw new ArgumentNullException(nameof(imageId)); } #endregion var modelId = LoadModel(); MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent(); using (Stream imageFileStream = ImageFileRepository.GetImageFile(topic, imageId)) { multipartFormDataContent.AddFileAsByteContent(imageFileStream, "image", imageId); } multipartFormDataContent.Add(new StringContent(modelId), "model"); HttpClient httpClient = HttpClientFactory.GetInferenceContainerHttpClient(); Uri uri = UriUtil.GetUri(httpClient.BaseAddress, "detect"); using MemoryStream memoryStream = new MemoryStream(httpClient.PostReadByteArray(uri, multipartFormDataContent)); using StreamReader streamReader = new StreamReader(memoryStream); return(ParseLabelResult(streamReader.ReadToEnd())); }
public UploadImageCommand(ImageFileRepository imageFileRepository, AssetDocumentRepository assetDocumentRepository, UploadAssetNotifier notifier) : base(notifier) { _assetRootPath = ConfigurationManager.AppSettings["ImageRootPath"]; _imageFileRepository = imageFileRepository; _assetDocumentRepository = assetDocumentRepository; }
public Stream GetImage(Topic topic, string imageFileName) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageFileName)) { throw new ArgumentNullException(nameof(imageFileName)); } #endregion return(ImageFileRepository.GetImageFile(topic, imageFileName)); }
private static void UploadAsset(FileMetadata file) { var assetFileRepository = new ImageFileRepository(); var assetDocumentRepository = new AssetDocumentRepository(); var notifier = new MessageBusClient(); var assetRootPath = ConfigurationManager.AppSettings["ImageRootPath"]; var id = Guid.NewGuid().ToString(); var fileInfo = FileReader.GetFileInfo(file.FileLocation); var fileContents = FileReader.ReadFile(file.FileLocation); var fileName = $"original{fileInfo.Extension}"; var storageMetadata = assetFileRepository.StoreAsset(id, fileName, "image/jpeg", fileContents); if (storageMetadata == null) { return; } var imageMetadata = FileReader.GetImageMetadata(file.FileName); var imageDescription = imageMetadata.GetValue("Exif IFD0", "Image Description"); var assetMetadata = new AssetMetadata { Id = id, Name = file.FileName, Description = imageDescription ?? string.Empty, Category = file.Category, ContentType = "image/jpeg", Author = file.Photographer, Url = $"{assetRootPath}/{storageMetadata.StorageId}", StorageMetadata = storageMetadata, Type = "image" }; assetDocumentRepository.Create(assetMetadata); notifier.SendMessage(new NewImageAdded { ImageName = storageMetadata.StorageId, Id = id }); }
public ImageLabel AddImage(Topic topic, string imageName, System.IO.Stream imageStream) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageName)) { throw new ArgumentNullException(nameof(imageName)); } if (imageStream == null) { throw new ArgumentNullException(nameof(imageStream)); } #endregion // check if image isn't corrupted // try to open image ImageUtil.TryOpenImage(imageStream); string[] topicImageFileName = ImageFileRepository.AddImageFile(topic, imageName, imageStream); Rect imageDimension = ImageUtil.GetDimensionFromImage(imageStream); ImageLabel imageLabel = new ImageLabel() { Id = topicImageFileName.Last(), Height = imageDimension.Height, Width = imageDimension.Width, }; return(ImageRepository.AddImage(topic, imageLabel)); }
public GenerateThumbnail(ImageFileRepository fileRepository, AssetDocumentRepository documentRepository) { _fileRepository = fileRepository; _documentRepository = documentRepository; }
public GetAssetFileQuery(ImageFileRepository repository) { _repository = repository; }