Spaces:
Runtime error
Runtime error
| import cv2 | |
| import numpy as np | |
| import gradio as gr | |
| # Farklı filtre fonksiyonları | |
| def apply_gaussian_blur(frame): | |
| return cv2.GaussianBlur(frame, (15, 15), 0) | |
| def apply_sharpening_filter(frame): | |
| kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) | |
| return cv2.filter2D(frame, -1, kernel) | |
| def apply_edge_detection(frame): | |
| return cv2.Canny(frame, 100, 200) | |
| def apply_invert_filter(frame): | |
| return cv2.bitwise_not(frame) | |
| def adjust_brightness_contrast(frame, alpha=1.0, beta=50): | |
| return cv2.convertScaleAbs(frame, alpha=alpha, beta=beta) | |
| def apply_grayscale_filter(frame): | |
| return cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
| def apply_sepia_filter(frame): | |
| sepia_filter = np.array([[0.272, 0.534, 0.131], | |
| [0.349, 0.686, 0.168], | |
| [0.393, 0.769, 0.189]]) | |
| sepia_image = cv2.transform(frame, sepia_filter) | |
| return np.clip(sepia_image, 0, 255).astype(np.uint8) | |
| def apply_fall_filter(frame): | |
| fall_filter = np.array([[0.393, 0.769, 0.189], | |
| [0.349, 0.686, 0.168], | |
| [0.272, 0.534, 0.131]]) | |
| fall_image = cv2.transform(frame, fall_filter) | |
| return np.clip(fall_image, 0, 255).astype(np.uint8) | |
| def apply_emboss_filter(frame): | |
| emboss_filter = np.array([[-2, -1, 0], | |
| [-1, 1, 1], | |
| [0, 1, 2]]) | |
| embossed_image = cv2.filter2D(frame, -1, emboss_filter) | |
| return np.clip(embossed_image + 128, 0, 255).astype(np.uint8) | |
| def Engin_deneme_fitresi(frame): | |
| deneme=np.array([[0.202, 0.504, 0.101], | |
| [0.309, 0.606, 0.118], | |
| [0.393, 0.709, 0.109]]) | |
| return frame | |
| def karnel_sharpening(frame): | |
| karnel=np.array(1/9*[[-1,-1,-1], [-1,9,-1], [-1,-1,-1]]) | |
| return frame | |
| # Filtre uygulama fonksiyonu | |
| def apply_filter(filter_type, input_image=None): | |
| if input_image is None: | |
| return "Görüntü yüklenmedi." | |
| frame = input_image | |
| # Filtre türüne göre işlemi seç | |
| if filter_type == "Gaussian Blur": | |
| return apply_gaussian_blur(frame) | |
| elif filter_type == "Sharpen": | |
| return apply_sharpening_filter(frame) | |
| elif filter_type == "Edge Detection": | |
| return apply_edge_detection(frame) | |
| elif filter_type == "Invert": | |
| return apply_invert_filter(frame) | |
| elif filter_type == "Brightness": | |
| return adjust_brightness_contrast(frame, alpha=1.0, beta=50) | |
| elif filter_type == "Grayscale": | |
| return apply_grayscale_filter(frame) | |
| elif filter_type == "Sepia": | |
| return apply_sepia_filter(frame) | |
| elif filter_type == "Sonbahar": | |
| return apply_fall_filter(frame) | |
| elif filter_type == "Emboss Filter": | |
| return apply_emboss_filter(frame) | |
| elif filter_type == "Engin Deneme": | |
| return Engin_deneme_fitresi(frame) | |
| elif filter_type == "Karnel Sharpening": | |
| return karnel_sharpening(frame) | |
| else: | |
| return frame | |
| # Gradio arayüzü | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Web Kameradan Canlı Filtreleme") | |
| # Filtre seçenekleri | |
| filter_type = gr.Dropdown( | |
| label="Filtre Seçin", | |
| choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar", "Emboss Filter", "Engin Deneme", "Karnel Sharpening"], | |
| value="Gaussian Blur" | |
| ) | |
| # Görüntü yükleme alanı | |
| input_image = gr.Image(label="Resim Yükle", type="numpy") | |
| # Çıktı için görüntü | |
| output_image = gr.Image(label="Filtre Uygulandı") | |
| # Filtre uygula butonu | |
| apply_button = gr.Button("Filtreyi Uygula") | |
| # Butona tıklanınca filtre uygulama fonksiyonu | |
| apply_button.click(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image) | |
| # Gradio arayüzünü başlat | |
| demo.launch() |