Skip to content

e621ng/iqdb

 
 

Repository files navigation

s# IQDB: Image Query Database System

IQDB is a reverse image search system. It lets you search a database of images to find images that are visually similar to a given image.

This version of IQDB is a fork of the original IQDB used by https://iqdb.org. This version powers the reverse image search for E621.

Quickstart

# Run IQDB in Docker on port 5588. This will create a database file in the current directory called `iqdb.sqlite`.
docker run --rm -it -p 5588:5588 -v $PWD:/mnt evazion/iqdb http 0.0.0.0 5588 /mnt/iqdb.sqlite

# Test that IQDB is running
curl -v http://localhost:5588/status

# Add `test.jpg` to IQDB with ID 1234. You will need to generate a unique ID for every image you add.
curl -F [email protected] http://localhost:5588/images/1234

# Find images visually similar to `test.jpg`.
curl -F [email protected] http://localhost:5588/query

Usage

IQDB is a simple HTTP server with a JSON API. It has commands for adding images, removing images, and searching for similar images. Image hashes are stored on disk in an SQLite database.

Adding images

To add an image to the database, POST a file to /images/:id where :id is an ID number for the image. On e621, the IDs used are post IDs, but they can be any number to identify the image.

curl -F [email protected] http://localhost:5588/images/1234
{
  "hash": "3fe4c6d513c538413fadbc7235383ab23f97674a40909b92f27ff97af97df980fcfdfd00fd71fd77fd7efdfffe00fe7dfe7ffe80fee7fefeff00ff71ff7aff7fff80ffe7fff1fff4fffa00020008001d009d02830285028803020381038304850701078208000801f97df9fffb7afcfdfd77fe00fe7dfe80fefaff00ff7aff7ffffaffff00030007000e000f0010002000830087008e008f009000a0010c010e018202810283028502860290030203810383058306000b83f67afafdfb7ffcf7fcfefcfffd7dfef3fefafeffff7afffa00030007000e001000200080008400870088008e0090010001030107010e018001810183020d02810282029003030483048d0507050e0680",
  "post_id":1234
}

The signature is the raw IQDB signature of the image. Two images are similar if their signatures are similar. The hash is the signature encoded as a hex string.

Removing images

To remove an image to the database, do DELETE /images/:id where :id is the ID number of the image.

curl -X DELETE http://localhost:5588/images/1234
{ "post_id": 1234 }

Searching for images

To search for an image, POST a file to /query?limit=N, where N is the maximum number of results to return (default 10).

curl -F [email protected] 'http://localhost:5588/query?limit=10'
[
  {
    "hash":"3fe4c6d513c538413fadbc7235383ab23f97674a40909b92f27ff97af97df980fcfdfd00fd71fd77fd7efdfffe00fe7dfe7ffe80fee7fefeff00ff71ff7aff7fff80ffe7fff1fff4fffa00020008001d009d02830285028803020381038304850701078208000801f97df9fffb7afcfdfd77fe00fe7dfe80fefaff00ff7aff7ffffaffff00030007000e000f0010002000830087008e008f009000a0010c010e018202810283028502860290030203810383058306000b83f67afafdfb7ffcf7fcfefcfffd7dfef3fefafeffff7afffa00030007000e001000200080008400870088008e0090010001030107010e018001810183020d02810282029003030483048d0507050e0680",
    "post_id":1234,
    "score":100
  }
]

The response will contain the top N most similar images. The score field is the similarity rating, from 0 to 100. The post_id is the ID of the image, chosen when you added the image.

You will have to determine a good cutoff score yourself. Generally, 90+ is a strong match, 70+ is weak match (possibly a false positive), and <50 is no match.

Compiling

IQDB requires the following dependencies to build:

Run make to compile the project. The binary will be at ./build/release/src/iqdb.

Run make debug to compile in debug mode. The binary will be at ./build/debug/src/iqdb.

You can also run cmake --preset release then cmake --build --preset release --verbose to build the project. make is simply a wrapper for these commands.

You can run make docker to build the docker image.

See the Dockerfile for an example of which packages to install.

History

This version of IQDB is a fork of the Danbooru IQDB with improvements from evazion which is in turn a fork of the original IQDB, written by piespy. IQDB is based on code from imgSeek, written by Ricardo Niederberger Cabral. The IQDB algorithm is based on the paper Fast Multiresolution Image Querying by Charles E. Jacobs, Adam Finkelstein, and David H. Salesin.

IQDB is distributed under the terms of the GNU General Public License. See COPYING for details.

Further reading

Releases

No releases published

Packages

 
 
 

Languages

  • C++ 90.0%
  • CMake 9.0%
  • Other 1.0%