File size: 1,421 Bytes
b083177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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()