Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 39 additions & 55 deletions projects/detection/Signature_Verification_Portal/Dashboard.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import streamlit as st
from PIL import Image
import os
import cv2
import numpy as np
import tensorflow as tf
from skimage.metrics import structural_similarity as ssim
from fastdtw import fastdtw
# Load your Siamese model
# siamese_model = tf.keras.models.load_model('siamese_net.h5', compile=False) # Use compile=False

try:
import cv2
except ImportError:
cv2 = None

try:
import tensorflow as tf
except ImportError:
tf = None

try:
from skimage.metrics import structural_similarity as ssim
except ImportError:
ssim = None

try:
from fastdtw import fastdtw
except ImportError:
fastdtw = None


class SessionState:
def __init__(self):
self.reset_form_open = False

# Create a SessionState object

session_state = SessionState()


def render_dashboard(session_state):
st.success('Successfully logged in')
st.title("Dashboard")
Expand All @@ -25,11 +43,9 @@ def render_dashboard(session_state):
path2 = st.file_uploader("Signature 2", type=["png", "jpg"])
submitted = st.button(label="Submit")
if path1 is not None and path2 is not None and submitted:
# Load and preprocess the uploaded images
img1 = preprocess_image(path1)
img2 = preprocess_image(path2)

# Perform signature verification using your Siamese model
similarity_score = verify_signature(img1, img2)

if similarity_score < 110000000:
Expand All @@ -40,10 +56,13 @@ def render_dashboard(session_state):
logout_button = st.button("Logout")
if logout_button:
session_state.is_authenticated = False
st.experimental_rerun()
if hasattr(st, "rerun"):
st.rerun()
elif hasattr(st, "experimental_rerun"):
st.experimental_rerun()

reset_password_button = st.button("Reset Password")
if reset_password_button:
# Display a form to reset the password
session_state.reset_form_open = True
if session_state.reset_form_open:
new_password = st.text_input("New Password", type="password")
Expand All @@ -52,65 +71,30 @@ def render_dashboard(session_state):

if new_password and confirm_password and reset_button:
if new_password == confirm_password:
# Update the user's password in the database
st.success("Password reset successful!")
session_state.reset_form_open = False
else:
st.warning("Passwords do not match. Please make sure they match.")



def preprocess_image(image_path):
# Load and preprocess the image
img = Image.open(image_path).convert("L") # Convert to grayscale

# Resize to match the input size (adjust as needed)
img = Image.open(image_path).convert("L")
img = img.resize((551, 1117))

# Convert the image to a NumPy array
img_array = np.array(img)

# Convert the image to sequences of points (coordinates)
points = np.argwhere(img_array > 128) # Adjust the threshold as needed

points = np.argwhere(img_array > 128)
return points





# def preprocess_image(image_path):
# # Load and preprocess the image
# img = Image.open(image_path).convert("L") # Convert to grayscale
# img = img.resize((551, 1117)) # Resize to match the input size

# # Convert the image to a NumPy array
# img = np.array(img)

# # Normalize the image to [0, 1] if needed
# img = img / 255.0

# return img




def verify_signature(image1, image2):
# Perform signature verification using DTW
distance, _ = fastdtw(image1, image2)
return distance





if fastdtw is not None:
distance, _ = fastdtw(image1, image2)
return distance
min_len = min(len(image1), len(image2))
if min_len == 0:
return float('inf')
return float(np.sum(np.abs(image1[:min_len] - image2[:min_len])))

# def verify_signature(image1, image2):
# # Perform signature verification using structural similarity
# similarity_score = ssim(image1, image2, data_range=1)
# return similarity_score

# Usage example
if __name__ == "__main__":
session_state = st.session_state
render_dashboard(session_state)
Loading
Loading