A toy Flask app for having fun with some simple images comparision algorithms.
Make sure you have installed:
docker(tested with v18.09.7)docker-compose(tested with v1.17.1)
- First time setup
$ docker-compose run --rm app /bin/bash -c "cd /opt/services/image_compare && python -c 'from app.web import db; db.create_all()'"- Fire up the cluster
$ docker-compose up -d- Browse to localhost:9009 to interact with the app.
To run the tests in a virtual env:
- Create a virtual env with
virtualenv:mkvirtualenv -p /usr/bin/python3 image-compare
- Install the dependencies:
pip install -r requirements.txt
Code quality checks:
inv checkRun the tests:
- Install the dev requirements with:
inv deps
- Run the tests with coverage report:
inv test - Run the tests without coverage report:
inv test --no-coverage
It's a dead simple Flask web app with a very simple Bootstrap based UI.
The image matching algorithm uses imageio to read the image files and OpenCV and SciPy to do the image
processing.
After trying (and failing) to come up with my own "homebrew" algorithm, I ended up using a feature detection based approach described here:
I did some minor tweaks (switching from KAZE to AKAZE and making it work with the latest lib versions). In essence the image matching works like this:
-
When an image is uploaded, a 64 keypoints based feature vector is extracted from it and stored in a database (with some other basic image info)
-
After the image is saved, the feature vector of the newly uploaded image is compared to all other existing feature vectors in the database (by measuring the "spatial" cosine distance between the feature vectors), and the 3 best matches are shown on the UI.
The results are pretty average at best, but it was a fun ride!