-
Notifications
You must be signed in to change notification settings - Fork 21
/
Examples.cs
46 lines (36 loc) · 1.85 KB
/
Examples.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
namespace CoenM.ImageHash.Test
{
using System.IO;
using CoenM.ImageHash.HashAlgorithms;
// These examples are used to generate snippets for markdown documentation.
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1123:Do not place regions within elements", Justification = "Source is used for generating markdown docs.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1515:Single-line comment should be preceded by blank line", Justification = "Source is used for generating markdown docs.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1512:Single-line comments should not be followed by blank line", Justification = "Source is used for generating markdown docs.")]
public class Examples
{
public void CalculateImageHashDemo()
{
#region CalculateImageHash
var hashAlgorithm = new AverageHash();
// or one of the other available algorithms:
// var hashAlgorithm = new DifferenceHash();
// var hashAlgorithm = new PerceptualHash();
string filename = "your filename";
using var stream = File.OpenRead(filename);
ulong imageHash = hashAlgorithm.Hash(stream);
#endregion
}
public void CalculateSimilarityDemo()
{
var hashAlgorithm = new AverageHash();
var imageStream1 = new MemoryStream();
var imageStream2 = new MemoryStream();
#region CalculateSimilarity
// calculate the two image hashes
ulong hash1 = hashAlgorithm.Hash(imageStream1);
ulong hash2 = hashAlgorithm.Hash(imageStream2);
double percentageImageSimilarity = CompareHash.Similarity(hash1, hash2);
#endregion
}
}
}