Fixed path error

This commit is contained in:
Profitroll 2023-06-23 12:09:36 +02:00
parent 5cc10367b2
commit b003712358
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2

View File

@ -1,3 +1,6 @@
from pathlib import Path
from typing import Union
import cv2
import numpy as np
from numpy.typing import NDArray
@ -27,8 +30,8 @@ def get_duplicates_cache(album: str) -> dict:
return output
async def get_phash(filepath: str) -> str:
img = cv2.imread(filepath)
async def get_phash(filepath: Union[str, Path]) -> str:
img = cv2.imread(str(filepath))
# resize image and convert to gray scale
img = cv2.resize(img, (64, 64))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@ -49,14 +52,14 @@ async def get_phash(filepath: str) -> str:
return hash_array_to_hash_hex(dct_block.flatten())
async def get_duplicates(hash: str, album: str) -> list:
async def get_duplicates(hash_string: str, album: str) -> list:
duplicates = []
cache = get_duplicates_cache(album)
for image_name in cache.keys():
for image_name, image_value in cache.items():
try:
distance = spatial.distance.hamming(
hash_hex_to_hash_array(cache[image_name][1]),
hash_hex_to_hash_array(hash),
hash_hex_to_hash_array(hash_string),
)
except ValueError:
continue