robotix67 commited on
Commit
e8a8a4e
·
verified ·
1 Parent(s): 0384250

Upload gradio-filtreleme-huggıng-face.py

Browse files
Files changed (1) hide show
  1. gradio-filtreleme-huggıng-face.py +120 -0
gradio-filtreleme-huggıng-face.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ sepia_image = cv2.transform(frame, sepia_filter)
30
+ return np.clip(sepia_image, 0, 255).astype(np.uint8)
31
+
32
+ def apply_fall_filter(frame):
33
+ fall_filter = np.array([[0.393, 0.769, 0.189],
34
+ [0.349, 0.686, 0.168],
35
+ [0.272, 0.534, 0.131]])
36
+ fall_image = cv2.transform(frame, fall_filter)
37
+ return np.clip(fall_image, 0, 255).astype(np.uint8)
38
+
39
+ def apply_emboss_filter(frame):
40
+ emboss_filter = np.array([[-2, -1, 0],
41
+ [-1, 1, 1],
42
+ [0, 1, 2]])
43
+ embossed_image = cv2.filter2D(frame, -1, emboss_filter)
44
+ return np.clip(embossed_image + 128, 0, 255).astype(np.uint8)
45
+
46
+
47
+ def Engin_deneme_fitresi(frame):
48
+ deneme=np.array([[0.202, 0.504, 0.101],
49
+ [0.309, 0.606, 0.118],
50
+ [0.393, 0.709, 0.109]])
51
+ return frame
52
+
53
+
54
+ def karnel_sharpening(frame):
55
+ karnel=np.array(1/9*[[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
56
+ return frame
57
+
58
+
59
+
60
+
61
+
62
+ # Filtre uygulama fonksiyonu
63
+ def apply_filter(filter_type, input_image=None):
64
+ if input_image is None:
65
+ return "Görüntü yüklenmedi."
66
+
67
+ frame = input_image
68
+
69
+ # Filtre türüne göre işlemi seç
70
+ if filter_type == "Gaussian Blur":
71
+ return apply_gaussian_blur(frame)
72
+ elif filter_type == "Sharpen":
73
+ return apply_sharpening_filter(frame)
74
+ elif filter_type == "Edge Detection":
75
+ return apply_edge_detection(frame)
76
+ elif filter_type == "Invert":
77
+ return apply_invert_filter(frame)
78
+ elif filter_type == "Brightness":
79
+ return adjust_brightness_contrast(frame, alpha=1.0, beta=50)
80
+ elif filter_type == "Grayscale":
81
+ return apply_grayscale_filter(frame)
82
+ elif filter_type == "Sepia":
83
+ return apply_sepia_filter(frame)
84
+ elif filter_type == "Sonbahar":
85
+ return apply_fall_filter(frame)
86
+ elif filter_type == "Emboss Filter":
87
+ return apply_emboss_filter(frame)
88
+ elif filter_type == "Engin Deneme":
89
+ return Engin_deneme_fitresi(frame)
90
+ elif filter_type == "Karnel Sharpening":
91
+ return karnel_sharpening(frame)
92
+
93
+ else:
94
+ return frame
95
+
96
+ # Gradio arayüzü
97
+ with gr.Blocks() as demo:
98
+ gr.Markdown("# Web Kameradan Canlı Filtreleme")
99
+
100
+ # Filtre seçenekleri
101
+ filter_type = gr.Dropdown(
102
+ label="Filtre Seçin",
103
+ choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar", "Emboss Filter", "Engin Deneme", "Karnel Sharpening"],
104
+ value="Gaussian Blur"
105
+ )
106
+
107
+ # Görüntü yükleme alanı
108
+ input_image = gr.Image(label="Resim Yükle", type="numpy")
109
+
110
+ # Çıktı için görüntü
111
+ output_image = gr.Image(label="Filtre Uygulandı")
112
+
113
+ # Filtre uygula butonu
114
+ apply_button = gr.Button("Filtreyi Uygula")
115
+
116
+ # Butona tıklanınca filtre uygulama fonksiyonu
117
+ apply_button.click(fn=apply_filter, inputs=[filter_type, input_image], outputs=output_image)
118
+
119
+ # Gradio arayüzünü başlat
120
+ demo.launch()