Scalable reverse image search
Match makes it easy to search for images that look similar to each other. Using a state-of-the-art perceptual hash, it is invariant to scaling and 90 degree rotations. Its HTTP API is quick to integrate and flexible for a number of reverse image search applications. Kubernetes and Elasticsearch allow Match to scale to billions of images with ease while giving you full control over where your data is stored. Match uses ascribe/image-match under the hood for most of the image search legwork which, in turn, is based on the paper An image signature for any kind of image, Goldberg et al.
- Python 3.6
- pip
- docker
Clone the repo
$ git clone https://github.com/TRUEPIC/match.git
Install in development mode
$ cd match
$ pip install -e .
Initialize the pre-commit hooks
$ pre-commit install
(Optional) Set up Elasticsearch in docker
$ docker run --name elastic -p 9200:9200 -t elasticsearch:6.4.2
Set ELASTICSEARCH_URL variable
$ export ELASTICSEARCH_URL=http://localhost:9200
Start the development web server
$ flask run --debugger --reload --port 5000
Once the flask server is running, the http endpoints are exposed on localhost:5000. The webserver will hot reload if any changes are made to the python files it depends on.
Example Call:
$ curl -X GET http://localhost:5000/count
{"status": "ok", "error": [], "method": "count", "result": [1]}
Build the docker image
docker build -t truepic/match:0.0.5
Start compose
docker-compose up
See API for usage.
Match has a simple HTTP API. All request parameters are specified via application/x-www-form-urlencoded
or multipart/form-data
.
Adds an image signature to the database.
-
url or image (required)
The image to add to the database. It may be provided as a URL via
url
or as amultipart/form-data
file upload viaimage
. -
filepath (required)
The path to save the image to in the database. If another image already exists at the given path, it will be overwritten.
-
metadata (default: None)
An arbitrary JSON object featuring meta data to attach to the image.
{
"status": "ok",
"error": [],
"method": "add",
"result": []
}
Deletes an image signature from the database.
-
filepath (required)
The path of the image signature in the database.
{
"status": "ok",
"error": [],
"method": "delete",
"result": []
}
Searches for a similar image in the database. Scores range from 0 to 100, with 100 being a perfect match.
-
url or image (required)
The image to add to the database. It may be provided as a URL via
url
or as amultipart/form-data
file upload viaimage
. -
all_orientations (default: true)
Whether or not to search for similar 90 degree rotations of the image.
{
"status": "ok",
"error": [],
"method": "search",
"result": [
{
"score": 99.0,
"filepath": "http://static.wixstatic.com/media/0149b5_345c8f862e914a80bcfcc98fcd432e97.jpg_srz_614_709_85_22_0.50_1.20_0.00_jpg_srz"
}
]
}
Compares two images, returning a score for their similarity. Scores range from 0 to 100, with 100 being a perfect match.
-
url1 or image1, url2 or image2 (required)
The images to compare. They may be provided as a URL via
url1
/url2
or as amultipart/form-data
file upload viaimage1
/image2
.
{
"status": "ok",
"error": [],
"method": "compare",
"result": [
{
"score": 99.0
}
]
}
Count the number of image signatures in the database.
{
"status": "ok",
"error": [],
"method": "list",
"result": [420]
}
Lists the file paths for the image signatures in the database.
-
offset (default: 0)
The location in the database to begin listing image paths.
-
limit (default: 20)
The number of image paths to retrieve.
{
"status": "ok",
"error": [],
"method": "list",
"result": [
"http://img.youtube.com/vi/iqPqylKy-bY/0.jpg",
"https://i.ytimg.com/vi/zbjIwBggt2k/hqdefault.jpg",
"https://s-media-cache-ak0.pinimg.com/736x/3d/67/6d/3d676d3f7f3031c9fd91c10b17d56afe.jpg"
]
}
Check for the health of the server.
{
"status": "ok",
"error": [],
"method": "ping",
"result": []
}