public void calculateGradientImage(Data.Image image) { if (swingSharpness == null) { swingSharpness = new double[image.width(), image.height()]; /* for (int x = 0; x < image.width(); x++) * for (int y = 0; y < image.height(); y++) * swingSharpness[x, y] = -255;*/ } curentImage = image.image; curentImage = changeImage.translateToMonochrome(curentImage); matematical.setImage(curentImage); /* * for (int x = 0; x < image.width(); x++) * for (int y = 0; y < image.height(); y++) * { * double gradient = matematical.gradientAtPoint(x, y); * if (gradient > swingSharpness[x, y]) * swingSharpness[x, y] = gradient; * } */ if (step == 0) { step = (curentImage.Width * curentImage.Height) / 640000; } Parallel.For(0, 4, calculateGradientImage); }
public async Task <ActionResult> SubmitRegister(RegisterViewModel model, HttpPostedFileBase ProfilePhoto) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(user.Id, model.UserType.ToString()); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); Session["UserId"] = UserManager.FindByEmail(model.Email).Id; Session["Role"] = UserManager.GetRoles(UserManager.FindByEmail(model.Email).Id).FirstOrDefault(); string id = Session["UserId"].ToString(); Data.Image fileToSave = new Data.Image(); AspNetUser aspNetUser = entities.AspNetUsers.Find(id); if (ProfilePhoto != null) { var fileName = Path.GetFileName(ProfilePhoto.FileName); var directoryToSave = Server.MapPath(Url.Content(ContentPath)); string GuidFileName = Guid.NewGuid().ToString() + ".jpg"; var pathToSave = Path.Combine(directoryToSave, GuidFileName); ProfilePhoto.SaveAs(pathToSave); fileToSave.Name = GuidFileName; fileToSave.Path = pathToSave; fileToSave.Id = Guid.NewGuid().ToString(); entities.Images.Add(fileToSave); aspNetUser.Image = fileToSave; } entities.Entry(aspNetUser).State = EntityState.Modified; entities.SaveChanges(); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); string role = Session["Role"].ToString(); if (role == "Student") { return(RedirectToAction("Create", "StudentsAccountDetails")); } return(RedirectToAction("Create", "RecruitersAccountDetails")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(RedirectToAction("Register", "Account")); }
private void GetMissedQuestions() { int numOfMissedQuestions = 0; for (int i = 0; i < this.lenght; i++) { if (QuizData.qaData[i, 3] != QuizData.qaData[i, 4]) { this.missedQuestions.Add(QuizData.qaData[i, 0]); questions.Items.Add(QuizData.qaData[i, 0]); numOfMissedQuestions++; } } resultText.Text = $"Правилни отговори {this.lenght - numOfMissedQuestions}/{this.lenght}"; if (numOfMissedQuestions > 0) { text.Text = "Грешни отговори на въпроси:"; } this.Result = this.missedQuestions; if (numOfMissedQuestions == 0) { this.image = new Data.Image { Path = "/MathGame;component/Resources/success_image.png" }; } }
protected void btnImageInsert_OnClick(object sender, EventArgs e) { if (txtImage.Text == string.Empty || FileUploadImage.FileName == string.Empty) { Label.Text = "Lütfen Tüm Alanları Doldurunuz."; Label.Visible = true; } else { //FileUploadThumbnail.SaveAs(MapPath("~/images/thumbnail/")+FileUploadThumbnail.FileName); FileUploadImage.SaveAs(MapPath("~/images/image/") + FileUploadImage.FileName); System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("~/images/image/") + FileUploadImage.FileName); System.Drawing.Image thumbnail = img.GetThumbnailImage(364, 273, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); thumbnail.Save(MapPath("~/images/thumbnail/") + FileUploadImage.FileName); var db = new EmerseDbEntities(); var image = new Data.Image(); image.name = txtImage.Text; image.category = Convert.ToInt32(dropDownList.SelectedValue); image.thumbnailUrl = "~/images/thumbnail/" + FileUploadImage.FileName; image.url = "~/images/image/" + FileUploadImage.FileName; image.createDate = DateTime.Now; db.Image.Add(image); db.SaveChanges(); Response.Redirect("~/Admin/GalleryContent.aspx"); } }
public void calculateGradientImage(Data.Image image) { if (width == 0) { width = image.width(); hight = image.height(); } }
protected void btnSave_Click(object sender, EventArgs e) { Westgate.Data.Image image = new Data.Image(); SetImage(image); DatabaseContext.AddToImages(image); DatabaseContext.SaveChanges(); Response.Redirect("~/Admin/AddImage.aspx?imageId=" + image.ImageId); }
/// <summary> /// A toggle that has no content and is drawn only using textures. /// </summary> public static bool Toggle(this Data.Image image, ref bool isBeingPressed, bool isActiveSelection, Event e, Texture2D normal, Texture2D active, Texture2D pressed) { Texture2D current = normal; bool wasPressed = false; image.immediate.rect.Draw().Selection().Area(ref isBeingPressed, isActiveSelection, out wasPressed, e, () => { current = normal; }, () => { current = active; }, () => { current = pressed; }); GUI.DrawTexture(image.immediate.rect, current); return(wasPressed); }
/// <summary> /// A button that has no content and is drawn only using textures. /// </summary> public static bool Button(this Data.Image image, ref bool isBeingPressed, Event e, Texture2D normal, Texture2D pressed, Texture2D hovering) { Texture2D current = normal; bool wasPressed = false; image.immediate.rect.Draw().Selection().Area(ref isBeingPressed, false, out wasPressed, e, () => { current = normal; }, () => { current = hovering; }, () => { current = pressed; }); GUI.DrawTexture(image.immediate.rect, current); return(wasPressed); }
/// <summary> /// A button that has no content and is drawn only using textures. /// </summary> public static bool TintedButton(this Data.Image image, ref bool isBeingPressed, Event e, Texture2D texture, Color active, Color pressed) { Texture2D current = texture.Copy(); bool wasPressed = false; image.immediate.rect.Draw().Selection().Area(ref isBeingPressed, false, out wasPressed, e, () => { }, () => { current = current.Tint(active, 0.5f); }, () => { current = current.Tint(pressed, 0.5f); }); GUI.DrawTexture(image.immediate.rect, current); return(wasPressed); }
private string SaveImageAndReturnKey(ImageType type, string fileName, Stream inputStream, Guid?userId, string key, bool cropCenter = false) { var ext = Path.GetExtension(fileName); var format = ext.GetImageFormat(); var image = new Data.Image(); image.Id = Guid.NewGuid(); image.Name = fileName; image.UserId = userId; image.Type = type; if (string.IsNullOrEmpty(key)) { image.Key = Data.Image.GenerateKey(type, image.Id, format); } var folder = AppContext.GetImageOriginalFolder(userId); var physicalFolder = AppContext.RootFolder + folder.Replace("/", "\\"); IoHelper.CreateDirectoryIfNotExists(physicalFolder); image.OriginalPath = folder + image.Id + ext; var physicalPath = physicalFolder + image.Id + ext; try { using (var inputImage = System.Drawing.Image.FromStream(inputStream)) { this.TryRotateImage(inputImage); var sizedImage = cropCenter ? inputImage.CropCenter(500) : inputImage.ToSize(new Size(1024, 768)); using (sizedImage) { sizedImage.SaveToFileInQuality(physicalPath, format); image.Width = sizedImage.Width; image.Height = sizedImage.Height; } } } catch { throw new KnownException("Invalid image file"); } if (image.Width == 0 || image.Height == 0) { throw new KnownException("Invalid image file"); } using (var db = base.NewDB()) { db.Images.Add(image); db.SaveChanges(); } return(image.Key); }
protected void btnSave_Click(object sender, EventArgs e) { Westgate.Data.Image image = new Data.Image(); bool imageAdd = SetImage(image); if (imageAdd) { DatabaseContext.AddToImages(image); DatabaseContext.SaveChanges(); Response.Redirect("~/Admin/addNewImage.aspx?imageId=" + image.ImageId); } else { //Response.Redirect("~/Admin/addNewImage.aspx"); } }
public async Task <IActionResult> OnGetAsync(Guid?id) { if (id == null) { return(NotFound()); } Image = await _context.Images.SingleOrDefaultAsync(m => m.Id == id); if (Image == null) { return(NotFound()); } return(Page()); }
private string SaveImageAndReturnKey(ImageType type, string fileName, Stream inputStream, Guid? userId, string key, bool cropCenter = false) { var ext = Path.GetExtension(fileName); var format = ext.GetImageFormat(); var image = new Data.Image(); image.Id = Guid.NewGuid(); image.Name = fileName; image.UserId = userId; image.Type = type; if (string.IsNullOrEmpty(key)) { image.Key = Data.Image.GenerateKey(type, image.Id, format); } var folder = AppContext.GetImageOriginalFolder(userId); var physicalFolder = AppContext.RootFolder + folder.Replace("/", "\\"); IoHelper.CreateDirectoryIfNotExists(physicalFolder); image.OriginalPath = folder + image.Id + ext; var physicalPath = physicalFolder + image.Id + ext; try { using (var inputImage = System.Drawing.Image.FromStream(inputStream)) { this.TryRotateImage(inputImage); var sizedImage = cropCenter ? inputImage.CropCenter(500) : inputImage.ToSize(new Size(1024, 768)); using (sizedImage) { sizedImage.SaveToFileInQuality(physicalPath, format); image.Width = sizedImage.Width; image.Height = sizedImage.Height; } } } catch { throw new KnownException("Invalid image file"); } if (image.Width == 0 || image.Height == 0) { throw new KnownException("Invalid image file"); } using (var db = base.NewDB()) { db.Images.Add(image); db.SaveChanges(); } return image.Key; }
public async Task <IActionResult> OnPostAsync(Guid?id) { if (id == null) { return(NotFound()); } Image = await _context.Images.FindAsync(id); if (Image != null) { _context.Images.Remove(Image); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
private Data.Image AddGetImage(string name) { // Добавить картинку в БД if (name.Length == 0) { return(null); } ImageSourceConverter imageSourceConverter = new ImageSourceConverter(); byte[] imageBin = (byte[])imageSourceConverter.ConvertTo(ImageBox.Source, typeof(byte[])); Data.Image pic = new Data.Image { ImageName = ImageNameText.Text, Bin = imageBin }; pic = Global.DB.Images.Add(pic); Global.DB.SaveChanges(); UpdateImageItems(); return(pic); }
private void imageContainer_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (imageContainer.SelectedIndex >= 0) { if (selectedImage?.Place != images[imageContainer.SelectedIndex].Place) { selectedImage = images[imageContainer.SelectedIndex]; polygonHelper.loadSavedPolygons(selectedImage, maskToolImage.ActualWidth, maskToolImage.ActualHeight); selectedCameraName.Text = "Camera: " + selectedImage.Place; } removeCarsGroup.Clear(); resultsGroup.Clear(); removeCarsGroup.Add(images[imageContainer.SelectedIndex]); } }
private void ImageIDBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Data.Image pic = ImageIDBox.SelectedItem as Data.Image; ImageBox.Source = LoadImage(pic?.Bin); ImageNameText.Text = pic?.ImageName; }
private void Clear_Button_Click(object sender, RoutedEventArgs e) { // Bilder entfernen downloadedImages.Clear(); differenceImages.Clear(); shownImages.Clear(); candidate = null; candidateMask = null; polygons.Clear(); maskedImages.Clear(); // Counter zurücksetzen counter = 0; ProgressBar.Value = 0; ProcessButton.Content = "Play"; timer.Stop(); }
private void GetLivePicture() { // Livebild herunterladen string downloadedFilePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_" + counter + ".jpg"; // Live webClient.DownloadFile("http://www.astramobcam.ch/kamera/" + selectedCamera + "/live.jpg", downloadedFilePath); // Offline // File.Copy(Directory.GetFiles(sourcefolderName + "\\live\\" + selectedCamera + "\\20160113\\")[counter], downloadedFilePath); // Heruntergeladenes Bild hinzufügen Data.Image downloadedImage = new Data.Image(downloadedFilePath); downloadedImage.Counter = counter; downloadedImage.Brush = Brushes.Green; downloadedImages.Add(downloadedImage); shownImages.Add(downloadedImage); counter++; ProcessPictures(); }
private void ProcessPictures() { if (downloadedImages.Count > 1) { // Letzte 2 Bilder auswählen Data.Image image0 = downloadedImages[downloadedImages.Count - 2]; Data.Image image1 = downloadedImages.Last(); string differencePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_" + image0.Counter + "+" + image1.Counter + ".png"; // Differenz ausrechnen openCVHelper.CalculateAbsoluteDifference(image0.FilePath, image1.FilePath, differencePath); // Differenz speichern Data.Image difference = new Data.Image(differencePath); difference.Coverage = openCVHelper.CountBlackArea(differencePath); difference.Brush = Brushes.Yellow; differenceImages.Add(difference); shownImages.Add(difference); if (candidate == null || candidateMask == null) { // Kandidat speichern string candidatePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_C.png"; openCVHelper.GetMaskedImage(downloadedImages.First().FilePath, differenceImages.First().FilePath, candidatePath); candidate = new Data.Image(candidatePath); candidate.Coverage = openCVHelper.CountBlackArea(candidatePath); candidate.Brush = Brushes.Cyan; shownImages.Add(candidate); // 1. Kandidaten Maske speichern string candidateMaskPath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_M.png"; File.Copy(differenceImages.First().FilePath, candidateMaskPath); candidateMask = new Data.Image(candidateMaskPath); candidateMask.Coverage = openCVHelper.CountBlackArea(candidateMask.FilePath); candidateMask.Brush = Brushes.Magenta; shownImages.Add(candidateMask); } if (differenceImages.Count > 1) { // Löcher im ersten Bild auffüllen Data.Image lastDifference = differenceImages.Last(); string filledNewImagePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_C.png"; openCVHelper.FillMaskHoles(candidateMask.FilePath, lastDifference.FilePath, downloadedImages.Last().FilePath, candidate.FilePath, filledNewImagePath); candidate = new Data.Image(filledNewImagePath); candidate.Coverage = openCVHelper.CountBlackArea(filledNewImagePath); candidate.Brush = Brushes.Cyan; shownImages.Add(candidate); // Kandidaten Maske aktualisieren string candidateMaskPath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_M.png"; openCVHelper.GetBlackArea(candidate.FilePath, candidateMask.FilePath, candidateMaskPath); candidateMask = new Data.Image(candidateMaskPath); candidateMask.Coverage = openCVHelper.CountBlackArea(candidateMask.FilePath); candidateMask.Brush = Brushes.Magenta; shownImages.Add(candidateMask); } if (candidateMask.Coverage < 1) { ProgressBar.Value = 0; timer.Stop(); DetectSnow(); } } }
private void DetectSnow() { // Bild in Regionen aueinanderschneiden foreach (Polygon polygon in polygons) { PointCollection pointCollection = JsonConvert.DeserializeObject<PointCollection>(polygon.PolygonPointCollection); string maskedImagePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_C_" + polygon.ImageArea + ".png"; openCVHelper.GetMaskedImage(candidate.FilePath, pointCollection, maskedImagePath); Data.Image maskedImage = new Data.Image(maskedImagePath); maskedImage.Brush = Brushes.RosyBrown; if (!string.IsNullOrEmpty(polygon.BgrSnow) && !string.IsNullOrEmpty(polygon.BgrNormal)) { maskedImage.Snow = openCVHelper.Calculate(maskedImage.FilePath, polygon, pointCollection); maskedImage.ShowResult = true; } maskedImages.Add(maskedImage); shownImages.Add(maskedImage); } string resultFilePath = folderName + "\\" + selectedCamera + "_" + DateTime.Now.ToString("yyyMMdd_HHmmss") + "_result.jpg"; File.Copy(candidate.FilePath, resultFilePath); Data.Image result = new Data.Image(resultFilePath); result.Brush = Brushes.Gold; int snow = maskedImages.Count(i => i.Snow == 1); int notSnow = maskedImages.Count(i => i.Snow == 0); int dontKnow = maskedImages.Count(i => i.Snow == -1); if (snow > notSnow && snow >= dontKnow) result.Snow = 1; if (notSnow > snow && notSnow >= dontKnow) result.Snow = -1; result.ShowResult = true; shownImages.Add(result); }
protected void Update_Click(object sender, EventArgs e) { if (Page.IsValid){ Data.Image obj = new Data.Image(); obj.Id = Id; obj.Name = txtName.Text; obj.Tag = Common.StringClass.NameToTag(txtName.Text); obj.Title = txtTitle.Text; obj.Description = txtDescription.Text; obj.Keyword = txtKeyword.Text; obj.Ord = txtOrd.Text != "" ? txtOrd.Text : "1"; obj.Active = chkActive.Checked ? "1" : "0"; obj.Lang = Lang; obj.Index = rbtUutien.SelectedValue; obj.GroupImageId = drlNhomanh.SelectedValue; obj.File = txtFile.Text; if (Insert == true){ Business.ImageService.Image_Insert(obj); } else{ Business.ImageService.Image_Update(obj); } BindGrid(); pnView.Visible = true; pnUpdate.Visible = false; Level= ""; Insert = false; } }