// Add New Image public int AddNewImage(Image image) { // Check if image exist,change path image = CheckDbIfExist(image); context.Images.Add(image); context.SaveChanges(); return(image.Id); }
public ActionResult Create([Bind(Include = "ImageId,ImageUrl")] Image image) { if (ModelState.IsValid) { db.Images.Add(image); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(image)); }
public IActionResult Delete(int id) { var ImageDelete = _context.Images .FirstOrDefault(t => t.Id == id); if (ImageDelete == null) { return(NotFound()); } _context.Images.Remove(ImageDelete); _context.SaveChanges(); return(new NoContentResult()); }
public ActionResult <IEnumerable <string> > Get() { if (_userImageContext.UsersImages.ToList().Count == 0) { List <UserImage> uimages = new List <UserImage>(); uimages.Add(new UserImage { Path = "C:\\Photo.jpg" }); uimages.Add(new UserImage { Path = "C:\\Photo.jpg" }); uimages.Add(new UserImage { Path = "C:\\Photo.jpg" }); _userImageContext.UsersImages.AddRange(uimages); _userImageContext.SaveChanges(); } var usersImages = _userImageContext.UsersImages.ToList(); return(Ok(usersImages)); }
public void ProcessFile(float[] image) { int resNumb = -1; if (DataBaseContains(image, ref resNumb)) { results.Enqueue(new Tuple <string, int>(imgDir[images.IndexOf(image)], resNumb)); return; } SessionOptions options = new SessionOptions(); options.SetSessionGraphOptimizationLevel(0); using (var session = new InferenceSession(modelPath)) { var inputMeta = session.InputMetadata; var container = new List <NamedOnnxValue>(); foreach (var name in inputMeta.Keys) { var tensor = new DenseTensor <float>(image, inputMeta[name].Dimensions); container.Add(NamedOnnxValue.CreateFromTensor <float>(name, tensor)); } foreach (var res in session.Run(container)) { var maxVal = res.AsTensor <float>().Max(); var prob = Softmax(res.AsTensor <float>().ToList <float>()); resNumb = res.AsTensor <float>().ToList <float>().IndexOf(maxVal); results.Enqueue(new Tuple <string, int>(imgDir[images.IndexOf(image)], resNumb)); var hash = ((IStructuralEquatable)image).GetHashCode(EqualityComparer <float> .Default); using (var db = new ImagesContext()) { db.Images.Add(new DataBase.Image() { Name = imgDir[images.IndexOf(image)], Class = resNumb, FileHash = hash, FileContent = ImageToByteArray(imgDir[images.IndexOf(image)]) }); db.SaveChanges(); } } } }
public MainWindow() { InitializeComponent(); var comboImgBinding = ImgCombo.Bind(ComboBox.ItemsProperty, sourcePath); var carousBinding = ImagesCar.Bind(Carousel.ItemsProperty, sourceImg); var comboClassBinding = NumCombo.Bind(ComboBox.ItemsProperty, sourceNum); var listBocBinding = ImagesListBox.Bind(ListBox.ItemsProperty, sourceLB); sourceNum.OnNext(new List <int> { 0, 1, 2, 3, 4, 5 }); ImgCombo.SelectionChanged += (s, e) => { sourceImg.OnNext(new List <Avalonia.Controls.Image> { Images[ImgCombo.SelectedIndex] }); }; NumCombo.SelectionChanged += (s, e) => { UpdateResults(); }; ClassButton.Click += (s, e) => { StopButton.IsEnabled = true; ProccText.IsVisible = true; NumCombo.IsEnabled = true; if (!isProcessing) { BeginSession(); } }; StopButton.Click += (s, e) => { if (myRec != null) { myRec.Stop(); } isProcessing = false; StopButton.IsEnabled = false; ProccText.IsVisible = false; }; DBButton.Click += (s, e) => { int count; using (var db = new ImagesContext()) { var imgs = db.Images.ToList(); foreach (var im in imgs) { db.Images.Remove(im); } db.SaveChanges(); count = db.Images.ToList().Count; } DBAmountText.Text = "Pictures in database amount: " + count; }; this.FindControl <Button>("ChooseDir").Click += async(s, e) => { var dialog = new OpenFolderDialog(); var res = await dialog.ShowAsync(GetWindow()); if (res != null) { imgDir = res.ToString(); UpdateImages(imgDir); ClassButton.IsEnabled = true; } }; }