14aa1e136f
* hashcompute_test: Add benchmark * dct: Improve DCT1D to O(nlogn) algorithm AS-IS: BenchmarkPerceptionHash-8 500 2893930 ns/op 456698 B/op 4455 allocs/op TO-BE: BenchmarkPerceptionHash-8 2000 890306 ns/op 456382 B/op 4455 allocs/op reference: DCT type II, unscaled. Algorithm by Byeong Gi Lee, 1984.
37 lines
942 B
Go
37 lines
942 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/corona10/goimagehash"
|
|
"image/jpeg"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
file1, _ := os.Open("sample1.jpg")
|
|
file2, _ := os.Open("sample2.jpg")
|
|
defer file1.Close()
|
|
defer file2.Close()
|
|
|
|
img1, _ := jpeg.Decode(file1)
|
|
img2, _ := jpeg.Decode(file2)
|
|
hash1, _ := goimagehash.AverageHash(img1)
|
|
hash2, _ := goimagehash.AverageHash(img2)
|
|
distance, _ := hash1.Distance(hash2)
|
|
fmt.Printf("Distance between images: %v\n", distance)
|
|
|
|
hash1, _ = goimagehash.DifferenceHash(img1)
|
|
hash2, _ = goimagehash.DifferenceHash(img2)
|
|
distance, _ = hash1.Distance(hash2)
|
|
fmt.Printf("Distance between images: %v\n", distance)
|
|
|
|
hash1, _ = goimagehash.PerceptionHash(img1)
|
|
hash2, _ = goimagehash.PerceptionHash(img2)
|
|
distance, _ = hash1.Distance(hash2)
|
|
fmt.Printf("Distance between images: %v\n", distance)
|
|
fmt.Println(hash1.ToString())
|
|
fmt.Println(hash2.ToString())
|
|
fmt.Println(hash1.Bits())
|
|
fmt.Println(hash2.Bits())
|
|
}
|