Spaces:
Sleeping
Sleeping
AKA Math commited on
Commit ·
aad4f32
1
Parent(s): 4405143
Prepare for Hugging Face Spaces deployment
Browse files- .gitattributes +22 -0
- README.md +13 -1
- template-matching-demo.py → app.py +14 -41
- requirements.txt +2 -1
.gitattributes
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.bmp filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.tiff filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.avi filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.mov filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# template-matching
|
| 2 |
|
| 3 |
This is a demonstration of how template matching works by computing correlation between the search space and the template.
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
## What is Template Matching?
|
| 8 |
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Template Matching Demo
|
| 3 |
+
emoji: 🔍
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.40.1"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
# template-matching
|
| 14 |
|
| 15 |
This is a demonstration of how template matching works by computing correlation between the search space and the template.
|
| 16 |
|
| 17 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 18 |
|
| 19 |
## What is Template Matching?
|
| 20 |
|
template-matching-demo.py → app.py
RENAMED
|
@@ -2,45 +2,10 @@
|
|
| 2 |
Inspired by https://www.loginradius.com/blog/engineering/guest-post/opencv-web-app-with-streamlit/
|
| 3 |
and https://medium.com/analytics-vidhya/finding-waldo-feature-matching-for-opencv-9bded7f5ab10
|
| 4 |
"""
|
| 5 |
-
import hmac
|
| 6 |
import numpy as np
|
| 7 |
import cv2 as cv
|
| 8 |
import streamlit as st
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def check_password():
|
| 12 |
-
"""Returns `True` if the user had a correct password."""
|
| 13 |
-
|
| 14 |
-
def login_form():
|
| 15 |
-
"""Form with widgets to collect user information"""
|
| 16 |
-
with st.form("Credentials"):
|
| 17 |
-
st.text_input("Username", key="username")
|
| 18 |
-
st.text_input("Password", type="password", key="password")
|
| 19 |
-
st.form_submit_button("Log in", on_click=password_entered)
|
| 20 |
-
|
| 21 |
-
def password_entered():
|
| 22 |
-
"""Checks whether a password entered by the user is correct."""
|
| 23 |
-
if st.session_state["username"] in st.secrets[
|
| 24 |
-
"passwords"
|
| 25 |
-
] and hmac.compare_digest(
|
| 26 |
-
st.session_state["password"],
|
| 27 |
-
st.secrets.passwords[st.session_state["username"]],
|
| 28 |
-
):
|
| 29 |
-
st.session_state["password_correct"] = True
|
| 30 |
-
del st.session_state["password"] # Don't store the username or password.
|
| 31 |
-
del st.session_state["username"]
|
| 32 |
-
else:
|
| 33 |
-
st.session_state["password_correct"] = False
|
| 34 |
-
|
| 35 |
-
# Return True if the username + password is validated.
|
| 36 |
-
if st.session_state.get("password_correct", False):
|
| 37 |
-
return True
|
| 38 |
-
|
| 39 |
-
# Show inputs for username + password.
|
| 40 |
-
login_form()
|
| 41 |
-
if "password_correct" in st.session_state:
|
| 42 |
-
st.error("😕 User not known or password incorrect")
|
| 43 |
-
return False
|
| 44 |
|
| 45 |
|
| 46 |
def compute_correlation(scene: np.array, template: np.array):
|
|
@@ -63,16 +28,19 @@ def main_loop():
|
|
| 63 |
"""
|
| 64 |
MAIN_LOOP is the main loop (duh) for this streamlit App.
|
| 65 |
"""
|
| 66 |
-
if not check_password():
|
| 67 |
-
st.stop()
|
| 68 |
-
|
| 69 |
st.set_page_config(layout="wide")
|
| 70 |
|
| 71 |
st.title("Template Matching Demo")
|
| 72 |
st.subheader(
|
| 73 |
"This app demonstrates how a template matching algorithm works: by sliding the template across the scene!")
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
template_image = cv.cvtColor(template_image, cv.COLOR_BGR2RGB)
|
| 77 |
|
| 78 |
st.markdown(
|
|
@@ -84,7 +52,12 @@ def main_loop():
|
|
| 84 |
st.markdown(
|
| 85 |
"Now for the fun bit - can you find Waldo in the scene below? Most of us will take about 20 seconds, if not more!")
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
scene_image = cv.cvtColor(scene_image, cv.COLOR_BGR2RGB)
|
| 89 |
|
| 90 |
st.text("Can you find Waldo?")
|
|
|
|
| 2 |
Inspired by https://www.loginradius.com/blog/engineering/guest-post/opencv-web-app-with-streamlit/
|
| 3 |
and https://medium.com/analytics-vidhya/finding-waldo-feature-matching-for-opencv-9bded7f5ab10
|
| 4 |
"""
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import cv2 as cv
|
| 7 |
import streamlit as st
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def compute_correlation(scene: np.array, template: np.array):
|
|
|
|
| 28 |
"""
|
| 29 |
MAIN_LOOP is the main loop (duh) for this streamlit App.
|
| 30 |
"""
|
|
|
|
|
|
|
|
|
|
| 31 |
st.set_page_config(layout="wide")
|
| 32 |
|
| 33 |
st.title("Template Matching Demo")
|
| 34 |
st.subheader(
|
| 35 |
"This app demonstrates how a template matching algorithm works: by sliding the template across the scene!")
|
| 36 |
|
| 37 |
+
# Load images from Hugging Face dataset
|
| 38 |
+
template_path = hf_hub_download(
|
| 39 |
+
repo_id="amithjkamath/exampleimages",
|
| 40 |
+
filename="waldo-template.jpeg",
|
| 41 |
+
repo_type="dataset"
|
| 42 |
+
)
|
| 43 |
+
template_image = cv.imread(template_path)
|
| 44 |
template_image = cv.cvtColor(template_image, cv.COLOR_BGR2RGB)
|
| 45 |
|
| 46 |
st.markdown(
|
|
|
|
| 52 |
st.markdown(
|
| 53 |
"Now for the fun bit - can you find Waldo in the scene below? Most of us will take about 20 seconds, if not more!")
|
| 54 |
|
| 55 |
+
scene_path = hf_hub_download(
|
| 56 |
+
repo_id="amithjkamath/exampleimages",
|
| 57 |
+
filename="waldo-scene.jpeg",
|
| 58 |
+
repo_type="dataset"
|
| 59 |
+
)
|
| 60 |
+
scene_image = cv.imread(scene_path)
|
| 61 |
scene_image = cv.cvtColor(scene_image, cv.COLOR_BGR2RGB)
|
| 62 |
|
| 63 |
st.text("Can you find Waldo?")
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
opencv-python-headless
|
| 2 |
streamlit
|
| 3 |
Pillow
|
| 4 |
-
numpy
|
|
|
|
|
|
| 1 |
opencv-python-headless
|
| 2 |
streamlit
|
| 3 |
Pillow
|
| 4 |
+
numpy
|
| 5 |
+
huggingface_hub
|