feat: initialize full-stack architecture with backend routes, database schema, and glassmorphic frontend UI
This commit is contained in:
20
backend/utils/image_utils.py
Normal file
20
backend/utils/image_utils.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from PIL import Image
|
||||
import imagehash
|
||||
import os
|
||||
|
||||
def calculate_image_hash(image_path):
|
||||
"""Вычисляет перцептивный хеш изображения."""
|
||||
try:
|
||||
img = Image.open(image_path)
|
||||
hash_val = imagehash.phash(img)
|
||||
return str(hash_val)
|
||||
except Exception as e:
|
||||
print(f"Hashing Error: {e}")
|
||||
return None
|
||||
|
||||
def compare_hashes(hash1, hash2, threshold=5):
|
||||
"""Сравнивает два хеша. Если разница меньше порога, изображения считаются похожими."""
|
||||
h1 = imagehash.hex_to_hash(hash1)
|
||||
h2 = imagehash.hex_to_hash(hash2)
|
||||
diff = h1 - h2
|
||||
return diff <= threshold
|
||||
Reference in New Issue
Block a user