2017-07-29 02:18:24 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image/jpeg"
|
|
|
|
"os"
|
2024-04-05 17:29:03 -06:00
|
|
|
|
2024-05-01 18:06:48 -07:00
|
|
|
"gitea.narnian.us/lordwelch/goimagehash"
|
2017-07-29 02:18:24 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-03-17 11:34:56 +09:00
|
|
|
hash1, _ = goimagehash.PerceptionHash(img1)
|
|
|
|
hash2, _ = goimagehash.PerceptionHash(img2)
|
|
|
|
distance, _ = hash1.Distance(hash2)
|
|
|
|
fmt.Printf("Distance between images: %v\n", distance)
|
2024-04-05 17:29:03 -06:00
|
|
|
fmt.Println(hash1.String())
|
|
|
|
fmt.Println(hash2.String())
|
2019-03-17 15:42:07 +09:00
|
|
|
fmt.Println(hash1.Bits())
|
|
|
|
fmt.Println(hash2.Bits())
|
2017-07-29 02:18:24 +09:00
|
|
|
}
|