Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to saved hashes for future comparison? #45

Open
k0fi opened this issue Nov 13, 2020 · 1 comment
Open

How to saved hashes for future comparison? #45

k0fi opened this issue Nov 13, 2020 · 1 comment

Comments

@k0fi
Copy link

k0fi commented Nov 13, 2020

After I get an image hashed:

	hash1, err := goimagehash.AverageHash(img1)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("hash of image is:", hash1)
	fmt.Println("hash1.ToString():", hash1.ToString())

I get

hash of image is: &{9222170938831798272 1}
hash1.ToString(): a:7ffbbb9b93000000

My problem is how to save hash1 in database, so that later on I can retrive it and compare its distance with newly computed hash2 using:

distance, _ := hash1.Distance(hash2)

@uncopied
Copy link

uncopied commented Dec 8, 2020

Not an authoritative answer, but you can save your hash value as separate columns :


// Golang :
// DigitalAssetSrc data dbmodel (ex. a raw image)
type DigitalAssetSrc struct {
	gorm.Model
	AverageHash uint64
	DifferenceHash uint64
	PerceptionHash uint64
...

// compute thumbnail hashes for similarity indexing
	averageHash, _ := goimagehash.AverageHash(thumbnail)
	differenceHash, _ := goimagehash.DifferenceHash(thumbnail)
	perceptionHash, _ := goimagehash.PerceptionHash(thumbnail)
	asset.AverageHash = averageHash.GetHash()
	asset.DifferenceHash = differenceHash.GetHash()
	asset.PerceptionHash = perceptionHash.GetHash()


// DB :
CREATE TABLE digital_asset_srcs
(
    id bigint NOT NULL DEFAULT nextval('digital_asset_srcs_id_seq'::regclass),
    average_hash bigint,
    difference_hash bigint,
    perception_hash bigint,
...

Then you can either reload those image hashes for comparison, on you can try and use K-nearest neighbour search with Hamming distance if you backend database supports it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants