Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +89 -0
- gitattributes +35 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Farklı filtre fonksiyonları
|
6 |
+
def apply_gaussian_blur(frame):
|
7 |
+
return cv2.GaussianBlur(frame, (15, 15), 0)
|
8 |
+
|
9 |
+
def apply_sharpening_filter(frame):
|
10 |
+
kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])
|
11 |
+
return cv2.filter2D(frame, -1, kernel)
|
12 |
+
|
13 |
+
def apply_edge_detection(frame):
|
14 |
+
return cv2.Canny(frame, 100, 200)
|
15 |
+
|
16 |
+
def apply_invert_filter(frame):
|
17 |
+
return cv2.bitwise_not(frame)
|
18 |
+
|
19 |
+
def adjust_brightness_contrast(frame, alpha=1.0, beta=50):
|
20 |
+
return cv2.convertScaleAbs(frame, alpha=alpha, beta=beta)
|
21 |
+
|
22 |
+
def apply_grayscale_filter(frame):
|
23 |
+
return cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
24 |
+
|
25 |
+
def apply_sepia_filter(frame):
|
26 |
+
sepia_filter = np.array([[0.272, 0.534, 0.131],
|
27 |
+
[0.349, 0.686, 0.168],
|
28 |
+
[0.393, 0.769, 0.189]])
|
29 |
+
return cv2.transform(frame, sepia_filter)
|
30 |
+
|
31 |
+
def apply_fall_filter(frame):
|
32 |
+
fall_filter = np.array([[0.393, 0.769, 0.189],
|
33 |
+
[0.349, 0.686, 0.168],
|
34 |
+
[0.272, 0.534, 0.131]])
|
35 |
+
return cv2.transform(frame, fall_filter)
|
36 |
+
|
37 |
+
# Filtre uygulama fonksiyonu
|
38 |
+
def apply_filter(filter_type, input_image=None):
|
39 |
+
if input_image is not None:
|
40 |
+
frame = input_image
|
41 |
+
else:
|
42 |
+
cap = cv2.VideoCapture(0)
|
43 |
+
ret, frame = cap.read()
|
44 |
+
cap.release()
|
45 |
+
if not ret:
|
46 |
+
return "Web kameradan görüntü alınamadı"
|
47 |
+
|
48 |
+
if filter_type == "Gaussian Blur":
|
49 |
+
return apply_gaussian_blur(frame)
|
50 |
+
elif filter_type == "Sharpen":
|
51 |
+
return apply_sharpening_filter(frame)
|
52 |
+
elif filter_type == "Edge Detection":
|
53 |
+
return apply_edge_detection(frame)
|
54 |
+
elif filter_type == "Invert":
|
55 |
+
return apply_invert_filter(frame)
|
56 |
+
elif filter_type == "Brightness":
|
57 |
+
return adjust_brightness_contrast(frame, alpha=1.0, beta=50)
|
58 |
+
elif filter_type == "Grayscale":
|
59 |
+
return apply_grayscale_filter(frame)
|
60 |
+
elif filter_type == "Sepia":
|
61 |
+
return apply_sepia_filter(frame)
|
62 |
+
elif filter_type == "Sonbahar":
|
63 |
+
return apply_fall_filter(frame)
|
64 |
+
|
65 |
+
# Gradio arayüzü
|
66 |
+
with gr.Blocks() as demo:
|
67 |
+
gr.Markdown("# Web Kameradan Canlı Filtreleme")
|
68 |
+
|
69 |
+
# Filtre seçenekleri
|
70 |
+
filter_type = gr.Dropdown(
|
71 |
+
label="Filtre Seçin",
|
72 |
+
choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar"],
|
73 |
+
value="Gaussian Blur"
|
74 |
+
)
|
75 |
+
|
76 |
+
# Görüntü yükleme alanı
|
77 |
+
input_image = gr.Image(label="Resim Yükle", type="numpy")
|
78 |
+
|
79 |
+
# Çıktı için görüntü
|
80 |
+
output_image = gr.Image(label="Filtre Uygulandı")
|
81 |
+
|
82 |
+
# Filtre uygula butonu
|
83 |
+
apply_button = gr.Button("Filtreyi Uygula")
|
84 |
+
|
85 |
+
# Butona tıklanınca filtre uygulama fonksiyonu
|
86 |
+
apply_button.click(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image)
|
87 |
+
|
88 |
+
# Gradio arayüzünü başlat
|
89 |
+
demo.launch()
|
gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
opencv-python
|
2 |
+
numpy
|