-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashes.py
38 lines (32 loc) · 1.32 KB
/
hashes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import scipy.fftpack
import streamlit as st
import os
import glob
from PIL import Image
import imagehash
class hashes:
def __init__(self, path, cont, progMsg):
self.path = path
self.flag = False
self.Files = glob.glob(path + '/**/*.*', recursive=True)
self.images = []
self.hashValues = []
self.cont = cont
self.progMsg = progMsg
for file in self.Files:
if file.endswith((".jpg")):
self.images.append(file)
@st.cache(hash_funcs = {st.delta_generator.DeltaGenerator: lambda _: None}, suppress_st_warning=True)
def generateHash(self):
self.progMsg.text(f"Hashing the images in the given directory...")
progBar = self.cont.progress(0)
for i, imagePath in enumerate(self.images):
image = Image.open(imagePath)
imageName = os.path.basename(imagePath)
hashTemp = imagehash.phash(image)
self.hashValues.append([imageName, str(hashTemp), imagePath])
self.progMsg.text(f"Hashing the images in the given directory... ({i+1}/{len(self.images)})")
progBar.progress((i+1)/len(self.images))
if len(self.images) != 0 and len(self.hashValues) == len(self.images):
self.flag = True
return (self.flag, self.hashValues)