public void UseImageTest1() { Bitmap bmp = new Bitmap(200, 200); var cCell = _IImageWorker.UseImage(bmp, 10); Assert.Equal(4, cCell); Assert.Equal(cCell * cCell, _IImageWorker.Count()); }
/// <summary> /// Split image into cells /// </summary> /// <param name="path">Path of image</param> /// <param name="scale">Scale of image</param> /// <returns>Matrix of path to cell images</returns> public string[,] SplitImage(string path, int scale) { int count = _imageWorkerService.UseImage(Image.FromFile(path), scale); var imageSplitPatches = new string[count, count]; var filePathes = _fileService.GetNextFilesPath(count * count, DirectoryType.Recognize); int i = 0; foreach (var cell in _imageWorkerService) { //nowPath = Path.Combine("images", $"{cell.X}_{cell.Y}.bmp"); //TODO: DB imageSplitPatches[cell.Y, cell.X] = filePathes[i].Remove(0, filePathes[i].LastIndexOf("\\images\\")); using (var streamSave = new FileStream(filePathes[i], FileMode.Create)) { cell.CellImage.Save(streamSave, System.Drawing.Imaging.ImageFormat.Bmp); } i++; } return(imageSplitPatches); }
/// <summary> /// [NOT CONNECTED TO RECOGNIZE MODULE] Split image on cells and send it to recognize /// </summary> /// <param name="model">Images to recognize</param> /// <returns>Object`s in cells</returns> public async Task <RecognizeResultViewModel[, ]> StartRecognize(RecognizeViewModel model) { var imgUrl = model.SatelliteURL .Remove(0, model.SatelliteURL.LastIndexOf("/images/")) .Replace("/", "\\"); var img = await _applicationDbContext.Images .SingleOrDefaultAsync(a => a.URL == imgUrl); if (img != null) { var count = _imageWorkerService .UseImage(Image.FromFile(_env.WebRootPath + imgUrl), img.Scale); var cellsPath = _fileService .GetNextFilesPath(_imageWorkerService.Count(), DirectoryType.Recognize); int i = 0; var retMatrix = new RecognizeResultViewModel[count, count]; img.Cells = new List <Models.CellDB>(); foreach (var cell in _imageWorkerService) { cell.CellImage.Save(cellsPath[i]); //Send to recognize and mark image img.Cells.Add(new Models.CellDB { URL = cellsPath[i] // Add aditional recognized data }); //Replace to recognized retMatrix[cell.X, cell.Y] = new RecognizeResultViewModel { Class = "Not Recognized", Height = 0, CellURL = cellsPath[i].Remove(0, cellsPath[i].LastIndexOf("\\images\\")) }; i++; } await _applicationDbContext.SaveChangesAsync(); return(retMatrix); } return(null); }