-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store fingerprint of all images
used for near-duplicate image detection
- Loading branch information
1 parent
dd6d81e
commit ed8fd38
Showing
6 changed files
with
203 additions
and
55 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pathlib import Path | ||
|
||
from PIL import Image | ||
|
||
from robotoff.images import generate_image_fingerprint | ||
|
||
IMAGE_DATA_DIR = Path(__file__).parent / "data/upc_image" | ||
|
||
|
||
def load_test_image(file_name: str) -> Image.Image: | ||
file_path = IMAGE_DATA_DIR / file_name | ||
return Image.open(file_path) | ||
|
||
|
||
def test_generate_image_fingerprint(): | ||
image_1 = load_test_image("no_upc1.jpg") | ||
image_2 = load_test_image("no_upc2.jpg") | ||
image_1_rescaled = image_1.copy() | ||
image_1_rescaled.thumbnail((400, 400)) | ||
|
||
fingerprint_1 = generate_image_fingerprint(image_1) | ||
fingerprint_2 = generate_image_fingerprint(image_2) | ||
fingerprint_rescaled_1 = generate_image_fingerprint(image_1_rescaled) | ||
|
||
# two different images should have different fingerprints | ||
assert fingerprint_1 != fingerprint_2 | ||
# fingerprints should be invariant to rescaling | ||
assert fingerprint_1 == fingerprint_rescaled_1 |