protected void Button1_Click(object sender, EventArgs e) { if (anh.Length < 0 || anh.Equals("")) { lbDisplay.Text = "Xin hãy upload ảnh rồi mới tìm kiếm!"; return; } Image1.ImageUrl = anh; String strPathImg = Server.MapPath("~/" + anh); DataTable dt = admin.dao.anh_caythuoc.getAllAnh(); DataTable dtNew = new DataTable(); dtNew.Columns.Add("Ma_Anh"); dtNew.Columns.Add("Ma_Cay"); dtNew.Columns.Add("Ten_Anh"); dtNew.Columns.Add("URL"); dtNew.Columns.Add("Percent"); foreach (DataRow r in dt.Rows) { String p = Server.MapPath("~/admin/" + r[3].ToString()); float difference = ImageTool.GetPercentageDifference(strPathImg, p); if ((difference * 100) < 50) { dtNew.Rows.Add(r[0], r[1], r[2], r[3], (difference * 100).ToString()); } } GridView1.DataSource = dtNew; GridView1.DataBind(); }
public IEnumerator screenshotAndCompare(String fileName) { string baseImageCompletePath = baseImageDirectory + fileName; string newImageCompletePath = refactorImageDirectory + fileName; if (isCreateBaseImages) { //Creating base image yield return(new WaitForSeconds(waitingTime)); ScreenCapture.CaptureScreenshot(baseImageCompletePath); yield return(new WaitForSeconds(waitingTime)); Assert.IsTrue(File.Exists(baseImageCompletePath), "Base Image should exist"); } else { yield return(new WaitForSeconds(waitingTime)); ScreenCapture.CaptureScreenshot(newImageCompletePath); yield return(new WaitForSeconds(waitingTime)); float difference = ImageTool.GetPercentageDifference(baseImageCompletePath, newImageCompletePath) * 100; // We don't require image if it is a mtach, so delete it if (difference == 0) { if (File.Exists(newImageCompletePath)) { File.Delete(newImageCompletePath); } } Assert.IsTrue(difference == 0, "Difference of " + difference + " % found in " + baseImageCompletePath + " vs " + newImageCompletePath); } }
private void AnalyzeAll() { var tsk = Task.Factory.StartNew(() => { try { for (int cnt = 0; cnt < aligns.Count; cnt++) { if (cnt == 0) { continue; } cvm.Status = $"Analyzing file {cnt}/{aligns.Count}"; Diffs.Add(cnt, new List <int>()); for (int i = 1; i <= Math.Min(3, cnt + 1); i++) { Diffs[cnt].Add((int)(100.0 * ImageTool.GetPercentageDifference(System.IO.Path.Combine(path, aligns[cnt - 1]), System.IO.Path.Combine(path, aligns[cnt])))); } } } catch (Exception e) { MessageBox.Show($"Problem doing analysis {e.Message}", "Problem", MessageBoxButton.OK, MessageBoxImage.Exclamation); } finally { analysis_complete = true; } return; }); }
private static float Image_Compare(string imgurl1, string imgurl2) { try { int result = (int)((1 - (ImageTool.GetPercentageDifference(imgurl1, imgurl2))) * 10000); float similarity = (float)result / 100; return(similarity); } catch (Exception err) { Console.WriteLine("compare error : " + err.Message); return(0); } }
static int Main(string[] args) { if (args.Length != 2) { return(-1); } else { //get, display and return the difference int difference1 = (int)(ImageTool.GetPercentageDifference(args[0], args[1]) * 100); Console.WriteLine("Similarity is {0}%", 100 - difference1); return(difference1); } }
/// <summary> /// Metoda sprawdzająca czy dwa obrazku sa takie same. W parametrach przyjmuje ścieżki do plików /// </summary> /// <param name="pathFirst"></param> /// <param name="pathSecond"></param> /// <returns></returns> public static bool CheckingImagesAreDifferent(string pathFirst, string pathSecond) { float differencePixels = ImageTool.GetPercentageDifference(pathFirst, pathSecond, 0); bool result = true; if (differencePixels != 0) { return(result); } else { result = false; } return(result); }
private static List <string> FoundDissimilar(List <string> source, string path, ConnectionViewModel cvm) { var most_dis = new List <string>(); most_dis.Add(source.First()); for (int i = 1; i < source.Count; i++) { int difference = (int)(100.0 * ImageTool.GetPercentageDifference(System.IO.Path.Combine(path, source[i - 1]), System.IO.Path.Combine(path, source[i]))); if (difference > 55) { most_dis.Add(source[i]); } cvm.Status = $"Comparing {i}/{source.Count}, found {most_dis.Count}"; } return(most_dis); }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("IMAGE COMPARISON CONSOLE APPLICATION"); Console.WriteLine(" by Kirtesh Wani"); Console.WriteLine(" Compares two images and returns the difference as an errorlevel (0 to 100)"); Console.WriteLine(); Console.WriteLine(@" Usage: 'ImageComparisonConsole.exe [image1 path] [image2 path] [Result path]"); Console.WriteLine(@" Sample usage: 'ImageComparisonConsole.exe ""c:\image1.jpg"" ""c:\image2.bmp"" ""c:\result"""); Console.Read(); return(-1); /* String[] args2 ={"C:/1.png","C:/2.png","C:/1"}; * * int difference = (int)(ImageTool.GetPercentageDifference(args2[0], args2[1]) * 100); * * //display the difference * Console.WriteLine("Difference is {0}%", difference); * * //Save the Matrix Image File at the Location * * ConsoleInterface.getDiifImage(args2[0], args2[1], args2[2]); * * //return the difference as an errorlevel * return difference; */ } else { //get the difference int difference = (int)(ImageTool.GetPercentageDifference(args[0], args[1]) * 100); //display the difference Console.WriteLine("Difference is {0}%", difference); //Save the Matrix Image File at the Location ConsoleInterface.getDiifImage(args[0], args[1], args[2]); //return the difference as an errorlevel return(difference); } }
static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("IMAGE COMPARISON CONSOLE APPLICATION"); Console.WriteLine(" by Jakob 'xnafan' Krarup, January 2013"); Console.WriteLine(" Licensed under The Code Project Open License (CPOL)"); Console.WriteLine(" Compares two images and returns the difference in percent"); Console.WriteLine(" as an errorlevel (0 to 100)"); Console.WriteLine(); Console.WriteLine(@" Usage: 'ImageComparisonConsole.exe [image1 path] [image2 path]"); Console.WriteLine(@" Sample usage: 'ImageComparisonConsole.exe ""c:\image1.jpg"" ""c:\image2.bmp"""); return(-1); } else { //get, display and return the difference int difference = (int)(ImageTool.GetPercentageDifference(args[0], args[1]) * 100); Console.WriteLine("Difference is {0}%", difference); return(difference); } }
public static float CompareImages(string image1Path, string image2Path, byte threshold = 3) { return(ImageTool.GetPercentageDifference(image1Path, image2Path, threshold)); }
public float GetPercentageDifference(string image1Path, string image2Path, byte threshold) { return(ImageTool.GetPercentageDifference(image1Path, image2Path, threshold)); }
private void ShowImage() { var vl = pairs.ElementAt(current_image_index).Value; current_image = pairs.ElementAt(current_image_index).Key; tbFileName.Text = current_image; elements_displayed = new Dictionary <string, string>(); // setting previously chosen image to be the 1st one if (alignments_reviewed.ContainsKey(current_image) && alignments_reviewed[current_image] != "stop") { var vl_new = new List <string>() { alignments_reviewed[current_image] }; foreach (var v in vl.Where(r => !r.Equals(alignments_reviewed[current_image]))) { vl_new.Add(v); } vl = vl_new; } else // sort by doing histogram comparison if (!string.IsNullOrEmpty(last_image)) { var cmp = new Dictionary <string, int>(); foreach (var v in vl) { int difference = (int)(100.0 * ImageTool.GetPercentageDifference(last_image, System.IO.Path.Combine(path, v))); cmp.Add(v, difference); } var vl_new = new List <string>(); foreach (var kvp in cmp.OrderBy(r => r.Value)) { vl_new.Add(kvp.Key); } vl = vl_new; } var index = 0; foreach (var image in alignments) { if (index == vl.Count) { using (MemoryStream memory = new MemoryStream()) { stop.Save(memory, ImageFormat.Png); memory.Position = 0; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); image.Source = bitmapImage; } elements_displayed.Add(image.Name, "stop"); } else if (index > vl.Count) { image.Source = null; } else { // ... Create a new BitmapImage. b1 = new BitmapImage(); b1.BeginInit(); b1.CacheOption = BitmapCacheOption.OnLoad; b1.UriSource = new Uri(System.IO.Path.Combine(path, vl[index])); b1.EndInit(); image.Source = b1; elements_displayed.Add(image.Name, vl[index]); } index++; } DisplayOverlay(); }