private void btnsimilar_Click(object sender, RoutedEventArgs e) { if ((imglist == null) || (imglist.Count == 0)) { MessageBox.Show("Please enter the path and click LoadFiles"); } else { Myimage mm = new Myimage(); OpenFileDialog openFileDialog = new OpenFileDialog(); bool? result = openFileDialog.ShowDialog(); if (result == true) { FileInfo fileInfo = new FileInfo(openFileDialog.FileName); mm.ImagePath = fileInfo.FullName; Uri uriSource = new Uri(fileInfo.FullName); bm1 = new BitmapImage(); bm1.BeginInit(); bm1.UriSource = uriSource; bm1.EndInit(); CheckHash(rb1, rb2, rb3, rb4, bm1, mm); FindSimilar(mm); prbar.Value = 0; } else { MessageBox.Show("Please choose a picture"); } } }
public void GetDirectories(string path) { OpenFileDialog openFileDialog = new OpenFileDialog(); bool? result = openFileDialog.ShowDialog(); if (result == true) { FileInfo fileInfo = new FileInfo(openFileDialog.FileName); m = new Myimage { ImagePath = fileInfo.FullName, Hash = 0, DirectoryPath = "" }; Uri uriSource1 = new Uri(fileInfo.FullName); bm1 = new BitmapImage(); bm1.BeginInit(); bm1.CacheOption = BitmapCacheOption.OnLoad; bm1.CreateOptions = BitmapCreateOptions.IgnoreImageCache; bm1.UriSource = uriSource1; bm1.EndInit(); CheckHash(rb1, rb2, rb3, rb4, bm1, m); string[] dirs = Directory.GetDirectories(path); imglist = new List <Myimage>(); foreach (var t in dirs) { string[] fullfilesPath = Directory.GetFiles(t, "*.jpg", SearchOption.AllDirectories); fullfilesPath = fullfilesPath.Concat(Directory.GetFiles(t, "*.png", SearchOption.AllDirectories)).ToArray(); fullfilesPath = fullfilesPath.Concat(Directory.GetFiles(t, "*.bmp", SearchOption.AllDirectories)).ToArray(); fullfilesPath = fullfilesPath.Concat(Directory.GetFiles(t, "*.jpeg", SearchOption.AllDirectories)).ToArray(); List <Myimage> temp = new List <Myimage>(); for (int i = 0; i < fullfilesPath.Length; i++) { temp.Add(new Myimage { ImagePath = fullfilesPath[i], Hash = 0, DirectoryPath = t }); Uri uriSource = new Uri(temp[i].ImagePath); bm1 = new BitmapImage(); bm1.BeginInit(); bm1.CacheOption = BitmapCacheOption.OnLoad; bm1.CreateOptions = BitmapCreateOptions.IgnoreImageCache; bm1.UriSource = uriSource; bm1.EndInit(); CheckHash(rb1, rb2, rb3, rb4, bm1, temp[i]); } imglist.AddRange(temp); } Stolp st = new Stolp(imglist, dirs); st.Check(); // to check quality // st.Quality(); m.DirectoryPath = st.Recognize(m); MessageBox.Show(m.DirectoryPath); } else { MessageBox.Show("Please choose a picture"); } }
static public void Sort(List <Myimage> lst) { Random rnd = new Random(); int n = lst.Count; while (n > 1) { n--; int k = rnd.Next(n + 1); Myimage value = lst[k]; lst[k] = lst[n]; lst[n] = value; } }
public string Recognize(Myimage X) { Myimage k = new Myimage(); double min = PerceptiveHash.hamming(X.Hash, etal1[0].Hash); for (int i = 0; i < etal1.Count; i++) { Int64 h = PerceptiveHash.hamming(X.Hash, etal1[i].Hash); if (min >= h) { min = h; k = etal1[i]; } } return(k.DirectoryPath); }
public void FindSimilar(Myimage m) { wrp.Children.Clear(); string s = Interaction.InputBox("Enter % of similarity"); double perc = int.Parse(s); perc = Math.Round(perc * 0.64); List <Myimage> similarList = new List <Myimage>(); for (int j = 0; j < imglist.Count; j++) { Int64 ham = PerceptiveHash.hamming(m.Hash, imglist[j].Hash); if (ham <= (64 - perc)) { similarList.Add(imglist[j]); } } for (int i = 0; i < similarList.Count; i++) { Uri uriSource = new Uri(similarList[i].ImagePath); bm1 = new BitmapImage(); bm1.BeginInit(); bm1.UriSource = uriSource; bm1.EndInit(); System.Windows.Controls.Image im = new System.Windows.Controls.Image(); im.Source = bm1; im.Width = 100; im.Height = 75; im.MouseEnter += new MouseEventHandler(OnMouseEnterHandler); im.MouseLeave += new MouseEventHandler(OnMouseLeaveHandler); ToolTip tooltip = new ToolTip { Content = similarList[i].ImagePath }; im.ToolTip = tooltip; im.Margin = new Thickness(5, 5, 5, 5); wrp.Children.Add(im); scrollv.ScrollToBottom(); } }
public void CheckHash(RadioButton rb1, RadioButton rb2, RadioButton rb3, RadioButton rb4, BitmapImage bm1, Myimage m) { if (rb1.IsChecked == true) { m.Hash = PerceptiveHash.aHash(bm1); } if (rb2.IsChecked == true) { m.Hash = PerceptiveHash.pHash(bm1); } if (rb3.IsChecked == true) { m.Hash = PerceptiveHash.dHash(bm1); } if (rb4.IsChecked == true) { m.Hash = PerceptiveHash.gHash(bm1); } }