prtm's picture
Upload 8 files
b083177
raw
history blame
No virus
1.42 kB
import cv2
import numpy as np
import streamlit as st
from Code import apply_effects
# Load cascade classifiers and images
glassesCasc = cv2.CascadeClassifier('Train/third-party/frontalEyes35x16.xml')
noseCasc = cv2.CascadeClassifier('Train/third-party/Nose18x15.xml')
glasses = cv2.imread('Train/glasses.png', cv2.IMREAD_UNCHANGED)
mustache = cv2.imread('Train/mustache.png', cv2.IMREAD_UNCHANGED)
def main():
st.title("Snapchat Filter App")
st.write("Upload an image or use your webcam to apply face effects!")
option = st.selectbox("Choose an option", ("Upload Image", "Use Webcam"))
if option == "Upload Image":
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_image is not None:
image = cv2.imdecode(np.fromstring(uploaded_image.read(), np.uint8), 1)
image_with_effects = apply_effects(image)
st.image(image_with_effects, channels="BGR", use_column_width=True)
else: # Use Webcam
cap = cv2.VideoCapture(0)
st.write("Webcam is active.")
frame_placeholder = st.empty()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
image_with_effects = apply_effects(frame)
frame_placeholder.image(image_with_effects, channels="BGR", use_column_width=True)
if __name__ == "__main__":
main()