public bool MatchTemplate(Rectangle rect, ulong targetHash, double similarity = DEFAULT_RECT_TOLERANCE) { if (CurrentFrame == null) { return(false); } var cropped = CropFrame(rect); var hash = ImageHashing.AverageHash(cropped); return(ImageHashing.Similarity(hash, targetHash) >= similarity); }
private void OnImageChanged(Image image, PictureBox pictureBox) { if (pictureBox == imageAPictureBox) { var hash = ImageHashing.AverageHash(imageAPictureBox.Image); imageAHashTextBox.Text = hash.ToString(); } else if (pictureBox == imageBPictureBox) { var hash = ImageHashing.AverageHash(imageBPictureBox.Image); imageBHashTextBox.Text = hash.ToString(); } }
private void CompareImages() { if (imageAPictureBox.Image == null || imageBPictureBox.Image == null) { return; } var hashA = ImageHashing.AverageHash(imageAPictureBox.Image); var hashB = ImageHashing.AverageHash(imageBPictureBox.Image); //var similarity = ImageHashing.Similarity(imageAPictureBox.Image, imageBPictureBox.Image); var similarity = ImageHashing.Similarity(hashA, hashB); var message = String.Format("SIMILARITY: {0}%", similarity); //MessageBox.Show(message); compareButton.Text = message; }
public static bool MatchTemplate(this ScriptBase script, MatchedValue matchedValue) { bool matched = script.MatchTemplate(matchedValue.Position, matchedValue.Hash, matchedValue.Similarity); #if DEBUG if (Settings.Default.CreateDebugScreenshots) { var cropped = script.CropFrame(script.CurrentFrame, matchedValue.Position); var hash = ImageHashing.AverageHash(cropped); var similarity = ImageHashing.Similarity(hash, matchedValue.Hash); if (!matched) { cropped.Save($"lastnotmatch_{matchedValue.ID}.png"); } } #endif return(matched); }