-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cae90a
commit 393ca17
Showing
10 changed files
with
67 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package avg | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/AskAlexSharov/imgdiff/loader" | ||
"github.com/Nr90/imgsim" | ||
) | ||
|
||
func Distance(ctx context.Context, fileName1, fileName2 string) (int, error) { | ||
ch := loader.ImagesAsync(ctx, fileName1, fileName2) | ||
|
||
// Hashing | ||
r1 := <-ch | ||
if r1.Err != nil { | ||
return 0, r1.Err | ||
} | ||
ahash1 := imgsim.AverageHash(r1.Img) | ||
|
||
r2 := <-ch | ||
if r2.Err != nil { | ||
return 0, r2.Err | ||
} | ||
ahash2 := imgsim.AverageHash(r2.Img) | ||
|
||
fmt.Println(ahash1) | ||
fmt.Println(ahash2) | ||
return imgsim.Distance(ahash1, ahash2) % 64, nil // because 64 bit hash | ||
} | ||
|
||
//func Difference(img1, img2 image.Image) int { | ||
// // Hashing | ||
// ahash1 := imgsim.AverageHash(img1) | ||
// ahash2 := imgsim.AverageHash(img2) | ||
// | ||
// dhash1 := imgsim.DifferenceHash(img1) | ||
// dhash2 := imgsim.DifferenceHash(img2) | ||
// | ||
// // distance | ||
// avgDistance := imgsim.Distance(ahash1, ahash2) | ||
// diffDistance := imgsim.Distance(dhash1, dhash2) | ||
// | ||
// return (avgDistance + diffDistance) % 128 | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
github.com/Nr90/imgsim v0.0.0-20180202144352-5caa057144b0 h1:8cjsGKoi/1QBb0V2ps3iBra9c4o+qY/NaJ15NsdjmQ4= | ||
github.com/Nr90/imgsim v0.0.0-20180202144352-5caa057144b0/go.mod h1:PSWPVD+KeWK3XVt0i/AahAMRw38OZ1k1vJpJLuvIY1w= | ||
github.com/aws/aws-lambda-go v1.8.1 h1:nHBpP6XC30bwF6qWKrw/BrK2A8i4GKmSZzajTBIJS4A= | ||
github.com/aws/aws-lambda-go v1.8.1/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters