import cv2 import numpy as np import gradio as gr # Türler at fonksiyonlar def ag_blur(frame): return cv2.GaussianBlur(frame, (15, 15), 0) def bileteral (frame): return cv2.bilateralFilter(frame, 9, 75, 75) def median_blur(frame): return cv2.medianBlur(frame, 5) def sharpen(frame): kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) return cv2.filter2D(frame, -1, kernel) def ad_detection(frame): return cv2.Canny(frame, 100, 200) def brightness(frame): return cv2.convertScaleAbs(frame, alpha=1.0, beta=50) def invert(frame): return cv2.bitwise_not(frame) def emboss(frame): kernel = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]) return cv2.filter2D(frame, -1, kernel) def ab_contrast(frame, alpha=1.0, beta=50): return cv2.convertScaleAbs(frame, alpha=alpha, beta=beta) def ag_filter(frame): return cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) def 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]]) return cv2.transform(frame, sepia_filter) 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]]) return cv2.transform(frame, fall_filter) # Filtre uygulama fonksiyonu def apply_filter(filter_type, input_image): frame = input_image if input_image is not None else None if frame is None: cap = cv2.VideoCapture(0) ret, frame = cap.read() cap.release() if not ret: return "Kameradan görüntü alınamadı" if filter_type == "Gaussian Blur": return ag_blur(frame) elif filter_type == "Median Blur": return median_blur(frame) elif filter_type == "Brightness": return brightness(frame) elif filter_type == "Bileteral Blur": return bileteral(frame) elif filter_type == "Sharpen": return sharpen(frame) elif filter_type == "Edge Detection": return ad_detection(frame) elif filter_type == "Emboss": return emboss(frame) elif filter_type == "Invert": return invert(frame) elif filter_type == "Contrast": return ab_contrast(frame, alpha=1.0, beta=50) elif filter_type == "Grayscale": return ag_filter(frame) elif filter_type == "Sepia": return sepia_filter(frame) elif filter_type == "Sonbahar": return apply_fall_filter(frame) # Gradio with gr.Blocks() as demo: gr.Markdown("Canlı Kamera ve Resim Yükleyerek Filtre Uygulaması ") # Dropdownd filtre seçimi filter_type = gr.Dropdown( label="1. Filtreyi Seçin", choices=["Gaussian Blur","Brightness", "Median Blur", "Bileteral Blur","Emboss", "Sharpen", "Edge Detection", "Invert", "Contrast", "Grayscale", "Sepia", "Sonbahar"], value="Gaussian Blur" ) # İkinci filtre seçimi filter_type2 = gr.Dropdown( label="2. Filtreyi Seçin", choices=["Gaussian Blur","Brightness","Median Blur", "Bileteral Blur" ,"Emboss", "Sharpen", "Edge Detection", "Invert", "Contrast", "Grayscale", "Sepia", "Sonbahar"], value="Gaussian Blur" ) # Girdi resmi input_image = gr.Image(label="Resim Yükle", type="numpy") # Çıktı resimleri output_image = gr.Image(label="1. Filtre Uygulandı") output_image2 = gr.Image(label="2. Filtre Uygulandı") # Seçilen filtre türlerini gösteren metin alanları selected_filter_text = gr.Textbox(label="Seçilen Filtre 1", interactive=False) selected_filter_text2 = gr.Textbox(label="Seçilen Filtre 2", interactive=False) # Mesaj alanı message = gr.Markdown("") message2 = gr.Markdown("") # Filtre uygula butonu apply_button = gr.Button("Filtreleri Uygula") # Butona tıklanınca filtre uygulama fonksiyonu def update_output(f1, f2, img): out1 = apply_filter(f1, img) out2 = apply_filter(f2, img) # Mesajı güncelle msg = f"Filtreler uygulandı. Teşekkür ederim " msg2 = f"Gökay GÖKÇE" return out1, out2, f1, f2, msg, msg2 apply_button.click( update_output, inputs=[filter_type, filter_type2, input_image], outputs=[output_image, output_image2, selected_filter_text, selected_filter_text2, message, message2] ) demo.launch()