goimagehash/_examples/examples.go
Dong-hee Na 84eb1859d0
imagehash: Add new serialization API dump/load. (#24)
Create a new APIs for serializing purpose which can use
standard io.Reader/io.Writer APIs.

ToString() API will be remain for debugging purpose and
ExtImageHashFromString, ImageHashFromString will be removed after next
version.

- New APIs are added: LoadExtImageHash, LoadImageHash, xxxHash.Dump
- These APIs are deprecated: ExtImageHashFromString, ImageHashFromString
2019-03-17 11:34:56 +09:00

33 lines
826 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)
}