goimagehash

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2018 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Build Status GoDoc Go Report Card Coverage Status

goimagehash

Inspired by imagehash

A image hashing library written in Go. ImageHash supports:

Only support 64bits hash.

Installation

go get github.com/corona10/goimagehash

Special thanks to

Usage

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)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageHash

type ImageHash struct {
	// contains filtered or unexported fields
}

ImageHash is a struct of hash computation.

func AverageHash

func AverageHash(img image.Image) (*ImageHash, error)

AverageHash fuction returns a hash computation of average hash. Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

func DifferenceHash

func DifferenceHash(img image.Image) (*ImageHash, error)

DifferenceHash function returns a hash computation of difference hash. Implementation follows http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html

func ImageHashFromString

func ImageHashFromString(s string) (*ImageHash, error)

ImageHashFromString returns an image hash from a hex representation

func NewImageHash

func NewImageHash(hash uint64, kind Kind) *ImageHash

NewImageHash function creates a new image hash.

func PerceptionHash

func PerceptionHash(img image.Image) (*ImageHash, error)

PerceptionHash function returns a hash computation of phash. Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

func (*ImageHash) Distance

func (h *ImageHash) Distance(other *ImageHash) (int, error)

Distance method returns a distance between two hashes.

func (*ImageHash) GetHash

func (h *ImageHash) GetHash() uint64

GetHash method returns a 64bits hash value.

func (*ImageHash) GetKind

func (h *ImageHash) GetKind() Kind

GetKind method returns a kind of image hash.

func (*ImageHash) Set

func (h *ImageHash) Set(idx int)

Set method sets a bit of index.

func (*ImageHash) ToString

func (h *ImageHash) ToString() string

ToString returns a hex representation of the hash

type Kind

type Kind int

Kind describes the kinds of hash.

const (
	// Unknown is a enum value of the unknown hash.
	Unknown Kind = iota
	// AHash is a enum value of the average hash.
	AHash
	//PHash is a enum value of the perceptual hash.
	PHash
	// DHash is a enum value of the difference hash.
	DHash
	// WHash is a enum value of the wavelet hash.
	WHash
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL