public async Task <IActionResult> Recognize(string photoId) { var photoUrl = _imageStorageService.UriFor(photoId); ImageUrl imgUrl = new ImageUrl { Url = photoUrl }; RecognizeViewModel recognizeViewModel = new RecognizeViewModel() { PhotoURL = photoUrl, ImagePrediction = await endpoint.PredictImageUrlAsync(projectID, imgUrl) }; //// //recognize from current default project //var defaultProject = _context.DefaultProjectHistories.OrderByDescending(x => x.SettingTime).FirstOrDefault(); //Guid projectPredictionID; //if (defaultProject != null) // projectPredictionID = defaultProject.MyProjectId; //else // projectPredictionID = projectID; //RecognizeViewModel recognizeViewModel = new RecognizeViewModel() //{ // PhotoURL = photoUrl, // ImagePrediction = await endpoint.PredictImageUrlAsync(projectPredictionID, imgUrl) //}; //// //RecognizeViewModel recognizeViewModel = new RecognizeViewModel() //{ // PhotoURL = photoUrl, // ImagePrediction = await endpoint.PredictImageUrlAsync(projectID, imgUrl) //}; //RecognizeViewModel recognizeViewModel; //var proj = _context.DefaultProjectHistories.OrderByDescending(x => x.SettingTime).FirstOrDefault(); //if (proj != null) //{ // recognizeViewModel = new RecognizeViewModel() // { // PhotoURL = photoUrl, // ImagePrediction = await endpoint.PredictImageUrlAsync(proj.MyProjectId, imgUrl) // }; //} //else //{ // recognizeViewModel = new RecognizeViewModel() // { // PhotoURL = photoUrl, // ImagePrediction = await endpoint.PredictImageUrlAsync(projectID, imgUrl) // }; //} return(View(recognizeViewModel)); }
/// <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); }
public async Task <IActionResult> StartRecognize([FromBody] RecognizeViewModel model) { var rez = await _recognizeService.StartRecognize(model); return(rez != null?JSON(rez) : JSON("", 400, "Image unavailable")); }