Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Filtre uygulama fonksiyonu
|
| 26 |
+
def apply_filter(filter_type, input_image=None):
|
| 27 |
+
if input_image is not None:
|
| 28 |
+
frame = input_image
|
| 29 |
+
else:
|
| 30 |
+
cap = cv2.VideoCapture(0)
|
| 31 |
+
ret, frame = cap.read()
|
| 32 |
+
cap.release()
|
| 33 |
+
if not ret:
|
| 34 |
+
return "Web kameradan görüntü alınamadı"
|
| 35 |
+
|
| 36 |
+
if filter_type == "Gaussian Blur":
|
| 37 |
+
return apply_gaussian_blur(frame)
|
| 38 |
+
elif filter_type == "Sharpen":
|
| 39 |
+
return apply_sharpening_filter(frame)
|
| 40 |
+
elif filter_type == "Edge Detection":
|
| 41 |
+
return apply_edge_detection(frame)
|
| 42 |
+
elif filter_type == "Invert":
|
| 43 |
+
return apply_invert_filter(frame)
|
| 44 |
+
elif filter_type == "Brightness":
|
| 45 |
+
return adjust_brightness_contrast(frame, alpha=1.0, beta=50)
|
| 46 |
+
elif filter_type == "Grayscale":
|
| 47 |
+
return apply_grayscale_filter(frame)
|
| 48 |
+
|
| 49 |
+
# Gradio arayüzü
|
| 50 |
+
with gr.Blocks() as demo:
|
| 51 |
+
gr.Markdown("# Web Kameradan Canlı Filtreleme")
|
| 52 |
+
|
| 53 |
+
# Filtre seçenekleri
|
| 54 |
+
filter_type = gr.Dropdown(
|
| 55 |
+
label="Filtre Seçin",
|
| 56 |
+
choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale"],
|
| 57 |
+
value="Gaussian Blur"
|
| 58 |
+
)
|
| 59 |
+
interactive=True
|
| 60 |
+
# Görüntü yükleme alanı
|
| 61 |
+
input_image = gr.Image(label="Resim Yükle", type="numpy")
|
| 62 |
+
|
| 63 |
+
# Çıktı için görüntü
|
| 64 |
+
output_image = gr.Image(label="Filtre Uygulandı")
|
| 65 |
+
|
| 66 |
+
# Filtre uygula butonu
|
| 67 |
+
apply_button = gr.Button("Filtreyi Uygula")
|
| 68 |
+
|
| 69 |
+
# Butona tıklanınca filtre uygulama fonksiyonu
|
| 70 |
+
apply_button.click(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image)
|
| 71 |
+
|
| 72 |
+
# Gradio arayüzünü başlat
|
| 73 |
+
demo.launch()
|