hashcompute: Update Extend API (#28)
* hashcompute: Update Extend API - AverageHashExtend -> ExtAverageHash - PerceptionHashExtend -> ExtPerceptionHash - DiffrenceHashExtend -> ExtDiffrenceHash * imagehash: Update load api
This commit is contained in:
parent
161b6f5676
commit
3e058be50d
@ -40,8 +40,8 @@ func main() {
|
|||||||
distance, _ = hash1.Distance(hash2)
|
distance, _ = hash1.Distance(hash2)
|
||||||
fmt.Printf("Distance between images: %v\n", distance)ls
|
fmt.Printf("Distance between images: %v\n", distance)ls
|
||||||
width, height := 8, 8
|
width, height := 8, 8
|
||||||
hash3, _ = goimagehash.AverageHashExtend(img1, width, height)
|
hash3, _ = goimagehash.ExtAverageHash(img1, width, height)
|
||||||
hash4, _ = goimagehash.AverageHashExtend(img2, width, height)
|
hash4, _ = goimagehash.ExtAverageHash(img2, width, height)
|
||||||
distance, _ = hash3.Distance(hash4)
|
distance, _ = hash3.Distance(hash4)
|
||||||
fmt.Printf("Distance between images: %v\n", distance)
|
fmt.Printf("Distance between images: %v\n", distance)
|
||||||
fmt.Printf("hash3 bit size: %v\n", hash3.Bits())
|
fmt.Printf("hash3 bit size: %v\n", hash3.Bits())
|
||||||
@ -52,7 +52,7 @@ func main() {
|
|||||||
_ = hash4.Dump(foo)
|
_ = hash4.Dump(foo)
|
||||||
foo.Flush()
|
foo.Flush()
|
||||||
bar := bufio.NewReader(&b)
|
bar := bufio.NewReader(&b)
|
||||||
hash5, _ := goimagehash.LoadImageHashExtend(bar)
|
hash5, _ := goimagehash.LoadExtImageHash(bar)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ func main() {
|
|||||||
img1, _ := jpeg.Decode(file1)
|
img1, _ := jpeg.Decode(file1)
|
||||||
img2, _ := jpeg.Decode(file2)
|
img2, _ := jpeg.Decode(file2)
|
||||||
width, height := 15, 15
|
width, height := 15, 15
|
||||||
hash1, _ := goimagehash.AverageHashExtend(img1, width, height)
|
hash1, _ := goimagehash.ExtAverageHash(img1, width, height)
|
||||||
hash2, _ := goimagehash.AverageHashExtend(img2, width, height)
|
hash2, _ := goimagehash.ExtAverageHash(img2, width, height)
|
||||||
hash1024, _ := goimagehash.AverageHashExtend(img2, 32, 32)
|
hash1024, _ := goimagehash.ExtAverageHash(img2, 32, 32)
|
||||||
distance, _ := hash1.Distance(hash2)
|
distance, _ := hash1.Distance(hash2)
|
||||||
fmt.Printf("Distance between images: %v\n", distance)
|
fmt.Printf("Distance between images: %v\n", distance)
|
||||||
err := hash1.Dump(foo)
|
err := hash1.Dump(foo)
|
||||||
@ -31,7 +31,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
foo.Flush()
|
foo.Flush()
|
||||||
bar := bufio.NewReader(&b)
|
bar := bufio.NewReader(&b)
|
||||||
hash3, err := goimagehash.LoadImageHashExtend(bar)
|
hash3, err := goimagehash.LoadExtImageHash(bar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
// http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
// http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
||||||
func AverageHash(img image.Image) (*ImageHash, error) {
|
func AverageHash(img image.Image) (*ImageHash, error) {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
return nil, errors.New("Image object can not be nil.")
|
return nil, errors.New("Image object can not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create 64bits hash.
|
// Create 64bits hash.
|
||||||
@ -42,7 +42,7 @@ func AverageHash(img image.Image) (*ImageHash, error) {
|
|||||||
// http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html
|
// http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html
|
||||||
func DifferenceHash(img image.Image) (*ImageHash, error) {
|
func DifferenceHash(img image.Image) (*ImageHash, error) {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
return nil, errors.New("Image object can not be nil.")
|
return nil, errors.New("Image object can not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
dhash := NewImageHash(0, DHash)
|
dhash := NewImageHash(0, DHash)
|
||||||
@ -84,10 +84,10 @@ func PerceptionHash(img image.Image) (*ImageHash, error) {
|
|||||||
return phash, nil
|
return phash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerceptionHashExtend function returns phash of which the size can be set larger than uint64
|
// ExtPerceptionHash function returns phash of which the size can be set larger than uint64
|
||||||
// Some variable name refer to https://github.com/JohannesBuchner/imagehash/blob/master/imagehash/__init__.py
|
// Some variable name refer to https://github.com/JohannesBuchner/imagehash/blob/master/imagehash/__init__.py
|
||||||
// Support 64bits phash (width=8, height=8) and 256bits phash (width=16, height=16)
|
// Support 64bits phash (width=8, height=8) and 256bits phash (width=16, height=16)
|
||||||
func PerceptionHashExtend(img image.Image, width, height int) (*ExtImageHash, error) {
|
func ExtPerceptionHash(img image.Image, width, height int) (*ExtImageHash, error) {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
return nil, errors.New("Image object can not be nil")
|
return nil, errors.New("Image object can not be nil")
|
||||||
}
|
}
|
||||||
@ -115,9 +115,9 @@ func PerceptionHashExtend(img image.Image, width, height int) (*ExtImageHash, er
|
|||||||
return NewExtImageHash(phash, PHash, imgSize), nil
|
return NewExtImageHash(phash, PHash, imgSize), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AverageHashExtend function returns ahash of which the size can be set larger than uint64
|
// ExtAverageHash function returns ahash of which the size can be set larger than uint64
|
||||||
// Support 64bits ahash (width=8, height=8) and 256bits ahash (width=16, height=16)
|
// Support 64bits ahash (width=8, height=8) and 256bits ahash (width=16, height=16)
|
||||||
func AverageHashExtend(img image.Image, width, height int) (*ExtImageHash, error) {
|
func ExtAverageHash(img image.Image, width, height int) (*ExtImageHash, error) {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
return nil, errors.New("Image object can not be nil")
|
return nil, errors.New("Image object can not be nil")
|
||||||
}
|
}
|
||||||
@ -145,9 +145,9 @@ func AverageHashExtend(img image.Image, width, height int) (*ExtImageHash, error
|
|||||||
return NewExtImageHash(ahash, AHash, imgSize), nil
|
return NewExtImageHash(ahash, AHash, imgSize), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DifferenceHashExtend function returns dhash of which the size can be set larger than uint64
|
// ExtDifferenceHash function returns dhash of which the size can be set larger than uint64
|
||||||
// Support 64bits dhash (width=8, height=8) and 256bits dhash (width=16, height=16)
|
// Support 64bits dhash (width=8, height=8) and 256bits dhash (width=16, height=16)
|
||||||
func DifferenceHashExtend(img image.Image, width, height int) (*ExtImageHash, error) {
|
func ExtDifferenceHash(img image.Image, width, height int) (*ExtImageHash, error) {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
return nil, errors.New("Image object can not be nil")
|
return nil, errors.New("Image object can not be nil")
|
||||||
}
|
}
|
||||||
|
@ -152,72 +152,72 @@ func TestExtImageHashCompute(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
distance int
|
distance int
|
||||||
}{
|
}{
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 42},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 42},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 4},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 4},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 38},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 38},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 40},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 40},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, AverageHashExtend, "AverageHashExtend", 6},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtAverageHash, "ExtAverageHash", 6},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 149},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 149},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 8},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 8},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 152},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 152},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 155},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 155},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, AverageHashExtend, "AverageHashExtend", 27},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtAverageHash, "ExtAverageHash", 27},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, AverageHashExtend, "AverageHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtAverageHash, "ExtAverageHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 32},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 32},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 2},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 2},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 30},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 30},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 34},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 34},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, PerceptionHashExtend, "PerceptionHashExtend", 20},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtPerceptionHash, "ExtPerceptionHash", 20},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 122},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 122},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 12},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 12},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 122},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 122},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 118},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 118},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, PerceptionHashExtend, "PerceptionHashExtend", 104},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtPerceptionHash, "ExtPerceptionHash", 104},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, PerceptionHashExtend, "PerceptionHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtPerceptionHash, "ExtPerceptionHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 43},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 43},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 37},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 37},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 43},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 43},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, DifferenceHashExtend, "DifferenceHashExtend", 16},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 8, 8, ExtDifferenceHash, "ExtDifferenceHash", 16},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 139},
|
{"_examples/sample1.jpg", "_examples/sample2.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 139},
|
||||||
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 14},
|
{"_examples/sample1.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 14},
|
||||||
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 130},
|
{"_examples/sample1.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 130},
|
||||||
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 147},
|
{"_examples/sample2.jpg", "_examples/sample3.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 147},
|
||||||
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, DifferenceHashExtend, "DifferenceHashExtend", 89},
|
{"_examples/sample2.jpg", "_examples/sample4.jpg", 16, 16, ExtDifferenceHash, "ExtDifferenceHash", 89},
|
||||||
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample1.jpg", "_examples/sample1.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample2.jpg", "_examples/sample2.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample3.jpg", "_examples/sample3.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, DifferenceHashExtend, "DifferenceHashExtend", 0},
|
{"_examples/sample4.jpg", "_examples/sample4.jpg", 17, 17, ExtDifferenceHash, "ExtDifferenceHash", 0},
|
||||||
} {
|
} {
|
||||||
file1, err := os.Open(tt.img1)
|
file1, err := os.Open(tt.img1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,8 +212,8 @@ func (h *ExtImageHash) Dump(w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadImageHashExtend method loads a ExtImageHash from io.Reader.
|
// LoadExtImageHash method loads a ExtImageHash from io.Reader.
|
||||||
func LoadImageHashExtend(b io.Reader) (*ExtImageHash, error) {
|
func LoadExtImageHash(b io.Reader) (*ExtImageHash, error) {
|
||||||
type E struct {
|
type E struct {
|
||||||
Hash []uint64
|
Hash []uint64
|
||||||
Kind Kind
|
Kind Kind
|
||||||
@ -232,7 +232,7 @@ const extStrFmt = "%1s:%s"
|
|||||||
|
|
||||||
// ExtImageHashFromString returns a big hash from a hex representation
|
// ExtImageHashFromString returns a big hash from a hex representation
|
||||||
//
|
//
|
||||||
// Deprecated: Use goimagehash.LoadImageHashExtend instead.
|
// Deprecated: Use goimagehash.LoadExtImageHash instead.
|
||||||
func ExtImageHashFromString(s string) (*ExtImageHash, error) {
|
func ExtImageHashFromString(s string) (*ExtImageHash, error) {
|
||||||
var kindStr string
|
var kindStr string
|
||||||
var hashStr string
|
var hashStr string
|
||||||
|
@ -105,13 +105,13 @@ func TestSerialization(t *testing.T) {
|
|||||||
// test for ExtIExtImageHash
|
// test for ExtIExtImageHash
|
||||||
sizeList := []int{8, 16}
|
sizeList := []int{8, 16}
|
||||||
for _, size := range sizeList {
|
for _, size := range sizeList {
|
||||||
hash, err := PerceptionHashExtend(img, size, size)
|
hash, err := ExtPerceptionHash(img, size, size)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
hex := hash.ToString()
|
hex := hash.ToString()
|
||||||
// len(kind) == 1, len(":") == 1
|
// len(kind) == 1, len(":") == 1
|
||||||
if len(hex) != size*size/4+2 {
|
if len(hex) != size*size/4+2 {
|
||||||
t.Errorf("Got invalid hex string '%v'; %v of '%v'", hex, "PerceptionHashExtend", ex)
|
t.Errorf("Got invalid hex string '%v'; %v of '%v'", hex, "ExtPerceptionHash", ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
reHash, err := ExtImageHashFromString(hex)
|
reHash, err := ExtImageHashFromString(hex)
|
||||||
@ -121,7 +121,7 @@ func TestSerialization(t *testing.T) {
|
|||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
if distance != 0 {
|
if distance != 0 {
|
||||||
t.Errorf("Original and unserialized objects should be identical, got distance=%v; %v of '%v'", distance, "PerceptionHashExtend", ex)
|
t.Errorf("Original and unserialized objects should be identical, got distance=%v; %v of '%v'", distance, "ExtPerceptionHash", ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,13 +140,13 @@ func TestDifferentBitSizeHash(t *testing.T) {
|
|||||||
img, _, err := image.Decode(file)
|
img, _, err := image.Decode(file)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
hash1, _ := AverageHashExtend(img, 32, 32)
|
hash1, _ := ExtAverageHash(img, 32, 32)
|
||||||
hash2, _ := DifferenceHashExtend(img, 32, 32)
|
hash2, _ := ExtDifferenceHash(img, 32, 32)
|
||||||
_, err = hash1.Distance(hash2)
|
_, err = hash1.Distance(hash2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Should got error with different kinds of hashes")
|
t.Errorf("Should got error with different kinds of hashes")
|
||||||
}
|
}
|
||||||
hash3, _ := AverageHashExtend(img, 31, 31)
|
hash3, _ := ExtAverageHash(img, 31, 31)
|
||||||
_, err = hash1.Distance(hash3)
|
_, err = hash1.Distance(hash3)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Should got error with different bits of hashes")
|
t.Errorf("Should got error with different bits of hashes")
|
||||||
@ -201,7 +201,7 @@ func TestDumpAndLoad(t *testing.T) {
|
|||||||
|
|
||||||
// test for ExtIExtImageHash
|
// test for ExtIExtImageHash
|
||||||
extMethods := []func(img image.Image, width, height int) (*ExtImageHash, error){
|
extMethods := []func(img image.Image, width, height int) (*ExtImageHash, error){
|
||||||
AverageHashExtend, PerceptionHashExtend, DifferenceHashExtend,
|
ExtAverageHash, ExtPerceptionHash, ExtDifferenceHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeList := []int{8, 16}
|
sizeList := []int{8, 16}
|
||||||
@ -215,7 +215,7 @@ func TestDumpAndLoad(t *testing.T) {
|
|||||||
checkErr(err)
|
checkErr(err)
|
||||||
foo.Flush()
|
foo.Flush()
|
||||||
bar := bufio.NewReader(&b)
|
bar := bufio.NewReader(&b)
|
||||||
reHash, err := LoadImageHashExtend(bar)
|
reHash, err := LoadExtImageHash(bar)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
distance, err := hash.Distance(reHash)
|
distance, err := hash.Distance(reHash)
|
||||||
|
Loading…
Reference in New Issue
Block a user