-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
313 lines (284 loc) · 12.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
from flask import Flask, render_template ,request,flash,Response, send_file
from werkzeug.utils import secure_filename
import cv2
import os
import calendar
import time
import getpass
import platform
from effects import color_pop, cool, alchemy,wacko,unstable,ore,contour,snicko,indus,spectra,molecule,lynn
from edit import brightness,contrast,blur,resize,denoise,rotate,sharp
from filter import hind,flora,handlebar,bella,tilak,thug,lido,polychrome,visor,rcb,mi,nags
from nightMode import night
app = Flask(__name__)
app.config['SECRET_KEY']='codeBytes'
@app.after_request
def add_header(response):
response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
response.headers['Cache-Control'] = 'public, max-age=0'
return response
###################################################################################################home page
@app.route('/')
def home():
return render_template('edit.html')
#################################################################################about page
@app.route('/about')
def about():
return render_template('about.html')
############################################################################################edit page
file_type=''
edit_img=''
edited=''
brightness_value='0'
contrast_value='1'
sharp_value=''
resize_value=''
rotate_value=''
denoise_value=''
blur_value='1'
effected=''
filter_val='None'
@app.route('/edit',methods=['GET','POST'])
def edit():
if request.method=='POST':
global edit_img
global effected
global edited
global brightness_value
global contrast_value
global sharp_value
global resize_value
global rotate_value
global denoise_value
global blur_value
global filter_val
global file_type
if request.form['button']=='Upload' and request.files['local_file'].filename!='':
f = request.files['local_file']
previous = os.getcwd()
eff_img=previous+'/static/images/trash/'+f.filename
edit_img=previous+'/static/images/trash/'+f.filename
com_img=previous+'/static/images/trash/'+f.filename
folder = previous +'/static/images/trash/'
os.chdir(folder)
f.save(secure_filename(f.filename))
os.chdir(previous)
return render_template('edit.html',image_filename='../static/images/trash/'+f.filename,brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
elif request.form['button']=='Apply' and edit_img!='':
brightness_value = request.form['brightness']
contrast_value = request.form['Contrast']
sharp_value = request.form['type']
resize_value = request.form['type2']
rotate_value = request.form['type1']
denoise_value = request.form['type3']
blur_value = request.form['Blur']
filter_val=request.form['filters']
previous = os.getcwd()
folder = previous +'/static/images/trash/'
if edit_img.count('jpeg')>0 or edit_img.count("jpg")>0:
file_type='jpg'
edited=folder+'edited.jpg'
elif edit_img.count('png')>0:
file_type='png'
edited=folder+'edited.png'
os.chdir(folder)
if brightness_value:
brightness(edit_img,int(brightness_value))
if contrast_value:
contrast(edited,float(contrast_value))
if sharp_value!='none':
sharp(edited,sharp_value)
if resize_value!='none':
resize(edited,resize_value)
if rotate_value!='none':
rotate(edited,rotate_value)
if denoise_value!='none':
denoise(edited,denoise_value)
if blur_value:
blur(edited,int(blur_value))
if filter_val!='':
if filter_val=='Oreo':
color_pop(edited)
elif filter_val=='Alchemy':
alchemy(edited)
elif filter_val=='Contour':
contour(edited)
elif filter_val=='Indus':
indus(edited)
elif filter_val=='Molecule':
molecule(edited)
elif filter_val=='Mercury':
cool(edited)
elif filter_val=='Wacko':
wacko(edited)
elif filter_val=='Ore':
ore(edited)
elif filter_val=='Snicko':
snicko(edited)
os.chdir(previous)
if edit_img.count('jpeg')>0 or edit_img.count("jpg")>0:
return render_template('edit.html',image_filename='../static/images/trash/edited.jpg',brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
elif edit_img.count('png')>0:
return render_template('edit.html',image_filename='../static/images/trash/edited.png',brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
else:
flash("Oops Something went wrong !")
return render_template('edit.html',brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
else:
effected=''
edit_img=''
edited=''
brightness_value='0'
contrast_value='1'
sharp_value=''
resize_value=''
rotate_value=''
denoise_value=''
blur_value='1'
file_type=''
flash("Oops Something went wrong !")
return render_template('edit.html',brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
return render_template('edit.html',brightness_value=brightness_value,contrast_value=contrast_value,blur_value=blur_value,sharp_value=sharp_value,denoise_value=denoise_value,rotate_value=rotate_value,resize_value=resize_value,filter_val=filter_val)
############################################################################################filters page
cap =''
value=0
filter_img=''
flag=False
def stream():
global cap
cap=cv2.VideoCapture(0)
while True:
__,frame = cap.read()
imgencode=cv2.imencode('.jpg',frame)[1]
strinData = imgencode.tostring()
yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+strinData+b'\r\n')
def stop():
global cap
if cap.isOpened():
cap.release()
@app.route('/filters/video')
def video():
if value==0:
return Response(stream(),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==1:
print("Entered Hind video")
return Response(hind(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==2:
return Response(handlebar(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==3:
return Response(flora(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==4:
return Response(bella(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==5:
return Response(tilak(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==6:
return Response(thug(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==7:
return Response(lido(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==8:
return Response(polychrome(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==9:
return Response(visor(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==10:
return Response(mi(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==11:
return Response(rcb(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==12:
return Response(nags(cap),mimetype='multipart/x-mixed-replace;boundary=frame')
elif value==13:
return Response(stop(),mimetype='multipart/x-mixed-replace;boundary=frame')
@app.route('/filters',methods=['GET','POST'])
def filters():
global value
global filter_img
global flag
if request.method=='POST':
print("Entered")
if request.form['button']=='Hind':
print("Entered Hind")
value=1
elif request.form['button']=='Handlebar':
value=2
elif request.form['button']=='Flora':
value=3
elif request.form['button']=='Bella':
value=4
elif request.form['button']=='Tilak':
value=5
elif request.form['button']=='Thug':
value=6
elif request.form['button']=='Lido':
value=7
elif request.form['button']=='Polychrome':
value=8
elif request.form['button']=='Visor':
value=9
elif request.form['button']=='MI':
value=10
elif request.form['button']=='RCB':
value=11
elif request.form['button']=='Nags':
value=12
elif request.form['button']=='Clear':
value=0
elif request.form['button']=='Capture':
value=13
flag=True
filter_img='../static/images/trash/filter.jpg'
return render_template('filters.html',img_filename='../static/images/trash/filter.jpg')
else:
value=0
return render_template('filters.html',img_filename=None)
@app.route('/download')
def download_file():
if(file_type=='png'):
path='static/images/trash/edited.png'
else:
path='static/images/trash/edited.jpg'
return send_file(path,as_attachment=True)
@app.route('/download1')
def download_file1():
path='static/images/trash/filter.jpg'
return send_file(path,as_attachment=True)
night_img=''
file_type=''
@app.route('/nightmode',methods=['GET','POST'])
def nightmode():
if request.method == 'POST':
global night_img
global file_type
if request.form['button']=='Upload' and request.files['local_file'].filename!='':
f = request.files['local_file']
previous = os.getcwd()
night_img=previous+'/static/images/trash/'+f.filename
folder = previous +'/static/images/trash/'
os.chdir(folder)
f.save(secure_filename(f.filename))
os.chdir(previous)
return render_template('nightmode.html',image_filename='../static/images/trash/'+f.filename)
elif request.form['button']=='night' and night_img!='':
previous=os.getcwd()
folder=previous+'/static/images/trash/'
os.chdir(folder)
night(night_img)
os.chdir(previous)
if night_img.count('jpeg')>0 or night_img.count("jpg")>0:
file_type='jpg'
night_img=folder+'nightmode.jpg'
return render_template('nightmode.html',image_filename='../static/images/trash/nightimage.jpg')
elif night_img.count('png')>0:
file_type='png'
night_img=folder+'nightmode.png'
return render_template('nightmode.html',image_filename='../static/images/trash/nightimage.png')
else:
return render_template('nightmode.html')
return render_template('nightmode.html')
@app.route('/download2')
def download_file2():
if(file_type=='png'):
path='static/images/trash/nightimage.png'
else:
path='static/images/trash/nightimage.jpg'
return send_file(path,as_attachment=True)
###############################################################################################main function
if __name__ == '__main__':
app.run()