disgo

package module
v0.0.0-...-1d3adef Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Duplicate Image Search in GO

Build Status GoDoc Coverage Status

This package is still a work in progress, but it works well in my own testing.

Example
package main

import "fmt"

import "github.com/abates/disgo"

func main() {
  // Create a disgo database with the default radix index
  db, _ := disgo.New()

  // load an image into the database and get the hash back
  file, _ := os.Open("test.png")
  hash, _ := db.AddFile(file)
  fmt.Printf("Image Hash: %08x\n", hash)

  // search for all hashes with a Hamming distance of 3
  // or less
  matches, _ := db.SearchByHash(hash, 3)
  fmt.Printf("Matches: %v\n", matches)
}

TODO
  • make radix index save/load functions thread safe
  • add record storage (e.g. file path) to database

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("Image not found")
	ErrNotSupported = errors.New("Underlying index does not support loading or saving")
)

Functions

This section is empty.

Types

type DB

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

func New

func New() *DB

func NewDB

func NewDB(index Index) *DB

func (*DB) Add

func (db *DB) Add(img image.Image) (PHash, error)

func (*DB) AddFile

func (db *DB) AddFile(reader io.Reader) (hash PHash, err error)

func (*DB) AddHash

func (db *DB) AddHash(hash PHash) error

func (*DB) Load

func (db *DB) Load(reader io.Reader) error

func (*DB) MarshalBinary

func (db *DB) MarshalBinary() ([]byte, error)

func (*DB) Save

func (db *DB) Save(writer io.Writer) error

func (*DB) Search

func (db *DB) Search(img image.Image, maxDistance int) (matches []PHash, err error)

func (*DB) SearchByFile

func (db *DB) SearchByFile(reader io.Reader, maxDistance int) (matches []PHash, err error)

func (*DB) SearchByHash

func (db *DB) SearchByHash(hash PHash, maxDistance int) ([]PHash, error)

func (*DB) UnmarshalBinary

func (db *DB) UnmarshalBinary(buf []byte) error

type ImageInfo

type ImageInfo struct {
	Hash     PHash  `json:"hash"`
	Location string `json:"location"`
}

type Index

type Index interface {
	Insert(PHash) error
	Search(PHash, int) ([]PHash, error)
}

type LinearIndex

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

func NewLinearIndex

func NewLinearIndex() *LinearIndex

func (*LinearIndex) Insert

func (li *LinearIndex) Insert(phash PHash) error

func (*LinearIndex) MarshalBinary

func (li *LinearIndex) MarshalBinary() ([]byte, error)

func (*LinearIndex) Search

func (li *LinearIndex) Search(phash PHash, maxDistance int) ([]PHash, error)

func (*LinearIndex) UnmarshalBinary

func (li *LinearIndex) UnmarshalBinary(buf []byte) error

type Node

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

func (*Node) Decode

func (n *Node) Decode(reader io.Reader) error

func (*Node) Encode

func (n *Node) Encode(writer io.Writer) error

func (*Node) Equal

func (n *Node) Equal(other *Node) bool

func (*Node) Insert

func (n *Node) Insert(value *Node)

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

func (*Node) Match

func (n *Node) Match(value PHash) (length uint8)

func (*Node) Search

func (n *Node) Search(search PHash, match PHash, distance int) []PHash

func (*Node) String

func (n *Node) String() string

type PHash

type PHash uint64

func Hash

func Hash(img image.Image) (PHash, error)

func (PHash) Distance

func (p1 PHash) Distance(p2 PHash) (distance int)

func (PHash) MarshalBinary

func (h PHash) MarshalBinary() ([]byte, error)

func (PHash) String

func (h PHash) String() string

type RadixIndex

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

func NewRadixIndex

func NewRadixIndex() *RadixIndex

func (*RadixIndex) Insert

func (ri *RadixIndex) Insert(hash PHash) error

func (*RadixIndex) MarshalBinary

func (ri *RadixIndex) MarshalBinary() ([]byte, error)

func (*RadixIndex) Search

func (ri *RadixIndex) Search(hash PHash, distance int) ([]PHash, error)

func (*RadixIndex) UnmarshalBinary

func (ri *RadixIndex) UnmarshalBinary(buf []byte) error

type SearchCriteria

type SearchCriteria struct {
	Hash     PHash `json:"hash"`
	Distance uint  `json:"distance"`
}

Jump to

Keyboard shortcuts

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