Jainam Jain commited on
Commit
7d1cd50
1 Parent(s): 946182c

Initial Commit

Browse files
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os,cv2
2
+ import numpy as np
3
+ import streamlit as st
4
+ from webcam import webcam
5
+ from images import image_transformations
6
+
7
+ title = st.empty()
8
+ title.header("Image Filter")
9
+ img_extensions = ["jpg","png","jpeg"]
10
+
11
+ def show_info():
12
+ st.subheader('''
13
+ Creator Jainam Jain:
14
+ ''')
15
+ st.markdown("### **Filters used:Cartoon")
16
+ st.write("")
17
+ st.sidebar.subheader("Choose the mode of operation: ")
18
+ selected_option = st.sidebar.selectbox("",["Select from below","Image Filters","Video Filters"])
19
+
20
+ if selected_option == "Image Filters":
21
+ title.header("Image Filters")
22
+ img_operation_mode = st.selectbox("Upload Images from: ",["-- Select from below --","Local Storage","Take a snap from Webcam"])
23
+
24
+ if img_operation_mode == "Local Storage":
25
+ uploaded_file = st.file_uploader("Upload images from local storage here",type = img_extensions)
26
+ if uploaded_file is not None:
27
+ img_bytes = uploaded_file.read()
28
+ decoded_img = cv2.imdecode(np.frombuffer(img_bytes, np.uint8), -1)
29
+ result = decoded_img
30
+
31
+ filter = st.selectbox("Choose an Image filter: ",["Basic Image Editing","Thug Life","Green Screen","Moustaches",\
32
+ "Devil-ie","Heart Eyes","John Cena XD","Cartoonie","Face Blur"],0)
33
+ image_transformations(result,filter,uploaded_file.name.split("."))
34
+
35
+ elif img_operation_mode == "Take a snap from Webcam":
36
+ result = webcam()
37
+ if result is None:
38
+ st.write("Waiting for capture...")
39
+ else:
40
+ st.write("Got an image from the webcam :P")
41
+ result = cv2.cvtColor(np.asarray(result,np.uint8),cv2.COLOR_RGB2BGR)
42
+
43
+ filter = st.selectbox("Choose an Image filter: ",["Basic Image Editing","Thug Life","Green Screen","Moustaches",\
44
+ "Devil-ie","Heart Eyes","John Cena XD","Cartoonie","Face Blur"],0)
45
+ image_transformations(result,filter)
46
+
47
+ else:
48
+ st.sidebar.markdown('''
49
+ This section contains filters to be applied on images.
50
+
51
+ Images can be uploaded either from local storage (or) from your webcamera.
52
+ ''')
53
+ st.sidebar.markdown("Choose the source of image, from the drop list on right :point_right:")
54
+ st.sidebar.subheader("Tips for operating on Image Filters: ")
55
+ st.sidebar.markdown('''
56
+ * Un edited pictures provide the best results.
57
+ * Link to download the edited pictures are at the bottom of the page
58
+ ''')
59
+
images.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import os
3
+ import base64
4
+ import numpy as np
5
+ from PIL import ImageFont, ImageDraw, Image
6
+ import streamlit as st
7
+ from modules.Cartoon.main import cartoon
8
+ # from helper.utils import file_checker
9
+ # from helper.descriptor import file_info
10
+ # from helper.rcnn_utils import generate_rcnn_mask
11
+
12
+ img_extensions = ["jpg","png","jpeg"]
13
+
14
+ def get_binary_file_downloader_html(bin_file,file_label='File'):
15
+ with open(bin_file,'rb') as f:
16
+ data = f.read()
17
+ bin_str = base64.b64encode(data).decode()
18
+ href = f'<h3><a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(bin_file)}">Download {file_label}</a></h3>'
19
+ return href
20
+
21
+ def image_transformations(result,filter,img_extension = "jpg"):
22
+ result = result[:,:,:3]
23
+ # filter_info(filter)
24
+ if filter == "Basic Image Editing":
25
+ gamma = st.slider("Gamma Correction",0.0,5.0,1.0,step = 0.1)
26
+ saturation = st.slider("Saturation", 0.0, 2.0, 1.0, step=0.1)
27
+ blurring = st.checkbox("Bluring", False)
28
+ if blurring:
29
+ col1,col2 = st.columns(2)
30
+ blur_area = col1.slider("Blur Area",1,100,1,2)
31
+ blur_intensity = col2.slider("Blur Intensity", 0, 500, 0, 1)
32
+ result = cv2.GaussianBlur(result, (blur_area, 1), blur_intensity)
33
+
34
+ apply_vignette = st.checkbox("Apply Vignette effect",False)
35
+ if apply_vignette:
36
+ vignette_effect = st.slider("Vignette Intensity",1,120,1)
37
+ rows, cols = result.shape[:2]
38
+ kernel_x = cv2.getGaussianKernel(cols, vignette_effect + 139)
39
+ kernel_y = cv2.getGaussianKernel(rows, vignette_effect + 139)
40
+ kernel = kernel_y*kernel_x.T
41
+ filter = 255 * kernel / np.linalg.norm(kernel)
42
+ vignette_img = np.copy(result)
43
+ for i in range(3):
44
+ vignette_img[:,:,i] = vignette_img[:,:,i]*filter
45
+ result = vignette_img
46
+
47
+ hsvImg = cv2.cvtColor(result, cv2.COLOR_BGR2HSV)
48
+ hsvImg[..., 1] = np.clip(hsvImg[..., 1] * saturation, 0, 255)
49
+ hsvImg[..., 2] = np.power((hsvImg[..., 2] / 255.0), 1 / (gamma + 0.1)) * 255.0
50
+ result = cv2.cvtColor(hsvImg, cv2.COLOR_HSV2BGR)
51
+ elif filter == "Cartoonie":
52
+ line_size = st.slider("Number of edges",3,101,7,2)
53
+ blurVal = st.slider("Blurr effect",3,101,7,2)
54
+ totalCols = st.slider("Total Color in images",2,100,11,1)
55
+ result = cartoon(result,[line_size,blurVal,totalCols])
56
+ if np.all(result != None):
57
+ st.image(result, use_column_width=True, clamp=True, channels="BGR")
58
+ filename = img_extension[0] + "." + img_extension[-1]
59
+ cv2.imwrite(filename, result)
60
+ st.markdown(get_binary_file_downloader_html(filename,
61
+ 'From Here '),
62
+ unsafe_allow_html=True)
modules/Blurr/main.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ from helper.utils import points2array
4
+
5
+ def blur_all_faces(input_imag,landmark_files):
6
+ detector,predictor = landmark_files
7
+ msg = None
8
+ detections = detector(input_imag, 1)
9
+ if len(detections) == 0:
10
+ msg = "No faces detected"
11
+ return input_imag, msg
12
+
13
+ canvas = input_imag.copy()
14
+ for rect in detections:
15
+ landmarks = predictor(input_imag, rect)
16
+ landmarks = points2array(landmarks.parts())
17
+ indices = list(range(16)) + [26,25,24,19,18,17,0]
18
+ pts = np.array(landmarks)[indices].reshape(-1,1,2)
19
+ canvas = cv2.fillPoly(canvas,[pts],(255,255,255))
20
+ canvas = cv2.cvtColor(canvas,cv2.COLOR_BGR2GRAY)
21
+ face_mask = cv2.threshold(canvas, 250, 255, cv2.THRESH_BINARY)[1]
22
+ face_mask_in = cv2.bitwise_not(face_mask)
23
+ blurred_face = cv2.GaussianBlur(input_imag, (37, 37), 150)
24
+ blurred_face = cv2.bitwise_and(blurred_face, blurred_face, mask=face_mask_inv)
25
+ bg = cv2.bitwise_and(input_imag, input_imag, mask=face_mask_in)
26
+ input_img = cv2.bitwise_or(bg,blurred_face)
27
+
28
+ return input_img,msg
29
+
30
+
31
+
modules/Cartoon/__pycache__/main.cpython-310.pyc ADDED
Binary file (1.33 kB). View file
 
modules/Cartoon/main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ def edge_mask(img, line_size=7, blur_value=7):
6
+ gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
7
+ gray_blur = cv2.medianBlur(gray, blur_value)
8
+ edges = cv2.adaptiveThreshold(gray_blur, 255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,line_size, blur_value)
9
+ return edges
10
+
11
+ def color_quantization(img,k):
12
+ data = np.float32(img).reshape((-1,3))
13
+ criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,20,0.001)
14
+ ret, label, center = cv2.kmeans(data, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
15
+ center = np.uint8(center)
16
+ result = center[label.flatten()]
17
+ result = result.reshape(img.shape)
18
+ return result
19
+ def cartoon(img,params=[7,7,11]):
20
+
21
+ edges = edge_mask(img, params[0], params[1])
22
+ res = color_quantization(img,params[2])
23
+ blurr = cv2.bilateralFilter(res, d=7, sigmaColor=200,sigmaSpace=200)
24
+ c = cv2.bitwise_and(blurr,blurr,mask=edges)
25
+ return c
requiremments.txt ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.2.0
2
+ attrs==23.2.0
3
+ blinker==1.7.0
4
+ cachetools==5.3.2
5
+ certifi==2023.11.17
6
+ charset-normalizer==3.3.2
7
+ click==8.1.7
8
+ colorama==0.4.6
9
+ contourpy==1.2.0
10
+ cycler==0.12.1
11
+ fonttools==4.47.0
12
+ gitdb==4.0.11
13
+ GitPython==3.1.40
14
+ helper==2.5.0
15
+ helper-utils==0.0.8
16
+ idna==3.6
17
+ importlib-metadata==6.11.0
18
+ imutils==0.5.4
19
+ Jinja2==3.1.2
20
+ jsonschema==4.20.0
21
+ jsonschema-specifications==2023.12.1
22
+ kiwisolver==1.4.5
23
+ markdown-it-py==3.0.0
24
+ MarkupSafe==2.1.3
25
+ matplotlib==3.8.2
26
+ mdurl==0.1.2
27
+ numpy==1.26.3
28
+ opencv-python==4.9.0.80
29
+ packaging==23.2
30
+ pandas==2.1.4
31
+ peppercorn==0.6
32
+ pillow==10.2.0
33
+ protobuf==4.25.1
34
+ pyarrow==14.0.2
35
+ pydeck==0.8.1b0
36
+ Pygments==2.17.2
37
+ pyparsing==3.1.1
38
+ python-dateutil==2.8.2
39
+ python-helper-utils==0.1.1
40
+ pytz==2023.3.post1
41
+ PyYAML==6.0.1
42
+ referencing==0.32.1
43
+ requests==2.31.0
44
+ rich==13.7.0
45
+ rpds-py==0.16.2
46
+ six==1.16.0
47
+ smmap==5.0.1
48
+ streamlit==1.29.0
49
+ tenacity==8.2.3
50
+ toml==0.10.2
51
+ toolz==0.12.0
52
+ tornado==6.4
53
+ typing_extensions==4.9.0
54
+ tzdata==2023.4
55
+ tzlocal==5.2
56
+ urllib3==2.1.0
57
+ utils==1.0.2
58
+ validators==0.22.0
59
+ watchdog==3.0.0
60
+ webcam==1.34
61
+ zipp==3.17.0