Repository navigation
Expand file tree
/
Copy pathfilters_dump.txt
More file actions
1149 lines (1044 loc) · 46.2 KB
/
Copy pathfilters_dump.txt
File metadata and controls
1149 lines (1044 loc) · 46.2 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# UPDATED FILE: filters.py
# (Full file content to replace previous filters.py)
#
# This version adds:
# - STYLE_PARAMS: parameter definitions for styles (used by GUI to create sliders)
# - apply_style_to_frame accepts a 'params' dict and forwards it to specific filters
# - filters read their parameters from the params dict when available
#
import cv2
import numpy as np
from PIL import Image
# Optional CUDA acceleration toggle (used by OpenCVEngine)
_USE_CUDA = False
def set_use_cuda(flag: bool):
global _USE_CUDA
_USE_CUDA = bool(flag)
def _cuda_available():
try:
return hasattr(cv2, 'cuda') and cv2.cuda.getCudaEnabledDeviceCount() > 0
except Exception:
return False
AVAILABLE_STYLES = [
"Original",
"Drawn",
"Comic",
"Outline",
"Trippy",
"Posterize",
"Face Overlay",
"Style Transfer",
"Vignette",
"Motion Blur",
"Bloom",
"Emboss",
"Chroma Shift",
"Kaleidoscope",
"Glitch",
"Brightness/Contrast",
"Color Balance",
"Saturation",
"Hue Shift",
"Sharpen",
"Sepia",
"Gamma",
"Pixelate",
"Noise",
"Edge Glow",
"Invert Colors",
"Median Blur",
"CLAHE",
"Cartoon",
"Oil Paint",
"Ink Sketch",
"Thermal Vision",
"Chromatic Aberration",
"Wave Distortion",
"Color Grade",
"Echo Trail",
"TimeShift Blend",
"Chroma Key",
"Chroma Key Reverse",
"Color Replace",
"Torch: Invert",
"Torch: Brightness",
"Torch: Sobel",
"Torch: Box Blur",
"Torch: Quantize",
"Torch: Sharpen",
"Torch: Contrast",
"Torch: Saturation",
"Torch: Gaussian Blur",
"Torch: Vignette",
"Torch: Sepia",
"Torch: Gamma",
"Torch: Pixelate",
"Torch: Noise",
"Torch: Edge Glow",
"Torch: Thermal Vision",
"Torch: Chromatic Aberration",
"Torch: Wave Distortion",
"Torch: Color Grade",
"Torch: Cartoon",
"Torch: Oil Paint",
"Torch: Ink Sketch",
"Torch: Echo Trail",
"Torch: TimeShift Blend"
]
# Helper: style lists by engine
def styles_for_opencv():
try:
return [s for s in AVAILABLE_STYLES if not str(s).startswith("Torch:")]
except Exception:
return AVAILABLE_STYLES
def styles_for_torch():
try:
base = ["Original"]
torch_only = [s for s in AVAILABLE_STYLES if str(s).startswith("Torch:")]
return base + torch_only
except Exception:
return ["Original"]
def get_styles_for_engine(engine_name: str):
if (engine_name or "").lower().startswith("torch"):
return styles_for_torch()
return styles_for_opencv()
# Parameter definitions used by GUI to create sliders dynamically.
# Format per param: { "key": str, "label": str, "type": "int"/"float", "min": val, "max": val, "step": val, "default": val }
STYLE_PARAMS = {
"Drawn": [
{"key": "shade_factor", "label": "Shade", "type": "float", "min": 0.0, "max": 0.2, "step": 0.005, "default": 0.02}
],
"Comic": [
{"key": "sigma_s", "label": "Smoothness", "type": "int", "min": 10, "max": 120, "step": 1, "default": 60},
{"key": "sigma_r", "label": "Range", "type": "float", "min": 0.1, "max": 1.0, "step": 0.005, "default": 0.45}
],
"Outline": [
{"key": "canny_low", "label": "Canny Low", "type": "int", "min": 10, "max": 200, "step": 1, "default": 80},
{"key": "canny_high", "label": "Canny High", "type": "int", "min": 50, "max": 300, "step": 1, "default": 180}
],
"Trippy": [
{"key": "blend", "label": "Blend (orig)", "type": "float", "min": 0.0, "max": 1.0, "step": 0.005, "default": 0.5},
{"key": "colormap", "label": "Colormap (0=JET,1=HSV,2=TURBO,3=RAINBOW)", "type": "int", "min": 0, "max": 3, "step": 1, "default": 2}
],
"Posterize": [
{"key": "levels", "label": "Levels", "type": "int", "min": 2, "max": 32, "step": 1, "default": 6}
],
"Face Overlay": [
{"key": "scale", "label": "Overlay Scale", "type": "float", "min": 0.5, "max": 2.0, "step": 0.005, "default": 1.1}
],
"Style Transfer": [
{"key": "blend_alpha", "label": "Style Blend", "type": "float", "min": 0.0, "max": 1.0, "step": 0.005, "default": 0.6}
],
"Vignette": [
{"key": "radius_scale", "label": "Radius", "type": "float", "min": 0.5, "max": 3.0, "step": 0.005, "default": 1.5}
],
"Motion Blur": [
{"key": "ksize", "label": "Kernel Size", "type": "int", "min": 3, "max": 51, "step": 1, "default": 21}
],
"Bloom": [
{"key": "threshold", "label": "Threshold", "type": "int", "min": 100, "max": 255, "step": 1, "default": 200},
{"key": "intensity", "label": "Intensity", "type": "float", "min": 0.0, "max": 1.5, "step": 0.005, "default": 0.6},
{"key": "blur_strength", "label": "Blur", "type": "int", "min": 3, "max": 101, "step": 1, "default": 35}
],
"Chroma Shift": [
{"key": "max_shift", "label": "Max Shift", "type": "int", "min": 1, "max": 64, "step": 1, "default": 8}
],
"Glitch": [
{"key": "intensity", "label": "Intensity", "type": "float", "min": 0.01, "max": 0.25, "step": 0.005, "default": 0.06}
],
"Brightness/Contrast": [
{"key": "brightness", "label": "Brightness", "type": "float", "min": -100, "max": 100, "step": 1, "default": 0},
{"key": "contrast", "label": "Contrast", "type": "float", "min": 0.5, "max": 2.0, "step": 0.005, "default": 1.0}
],
"Color Balance": [
{"key": "r_gain", "label": "Red Gain", "type": "float", "min": 0.5, "max": 2.0, "step": 0.005, "default": 1.0},
{"key": "g_gain", "label": "Green Gain", "type": "float", "min": 0.5, "max": 2.0, "step": 0.005, "default": 1.0},
{"key": "b_gain", "label": "Blue Gain", "type": "float", "min": 0.5, "max": 2.0, "step": 0.005, "default": 1.0}
],
"Saturation": [
{"key": "saturation", "label": "Saturation", "type": "float", "min": 0.0, "max": 3.0, "step": 0.025, "default": 1.0}
],
"Hue Shift": [
{"key": "hue_shift", "label": "Hue Shift", "type": "int", "min": 0, "max": 180, "step": 1, "default": 0}
],
"Sharpen": [
{"key": "amount", "label": "Sharpness", "type": "float", "min": 0.0, "max": 3.0, "step": 0.05, "default": 1.0}
],
"TrippyShift": [
{"key": "shift", "label": "RGB Shift (px)", "type": "int", "min": 0, "max": 30, "step": 1, "default": 5},
{"key": "blend", "label": "Blend", "type": "float", "min": 0.0, "max": 1.0, "step": 0.025, "default": 0.5}
],
"Sepia": [
{"key": "strength", "label": "Strength", "type": "float", "min": 0.0, "max": 1.0, "step": 0.01, "default": 1.0}
],
"Gamma": [
{"key": "gamma", "label": "Gamma", "type": "float", "min": 0.2, "max": 3.0, "step": 0.01, "default": 1.0}
],
"Pixelate": [
{"key": "block", "label": "Block Size", "type": "int", "min": 4, "max": 50, "step": 1, "default": 12}
],
"Noise": [
{"key": "sigma", "label": "StdDev", "type": "int", "min": 0, "max": 50, "step": 1, "default": 10}
],
"Edge Glow": [
{"key": "amount", "label": "Amount", "type": "float", "min": 0.0, "max": 2.0, "step": 0.05, "default": 0.6},
{"key": "blur", "label": "Blur", "type": "int", "min": 1, "max": 31, "step": 1, "default": 9}
],
"Echo Trail": [
{"key": "length", "label": "Length", "type": "int", "min": 1, "max": 20, "step": 1, "default": 8},
{"key": "decay", "label": "Decay", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.6}
],
"TimeShift Blend": [
{"key": "delay", "label": "Delay", "type": "int", "min": 1, "max": 30, "step": 1, "default": 6},
{"key": "alpha", "label": "Alpha", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.5}
],
"Torch: Brightness": [
{"key": "delta", "label": "Delta (±)", "type": "int", "min": -128, "max": 128, "step": 1, "default": 0}
]
}
# Extend parameters with additional Torch/OpenCV styles without touching original dict order
EXTRA_STYLE_PARAMS = {
"Invert Colors": [],
"Median Blur": [
{"key": "ksize", "label": "Kernel", "type": "int", "min": 1, "max": 31, "step": 2, "default": 5}
],
"CLAHE": [
{"key": "clip", "label": "Clip Limit", "type": "float", "min": 0.2, "max": 5.0, "step": 0.1, "default": 2.0},
{"key": "tile", "label": "Tile Size", "type": "int", "min": 2, "max": 16, "step": 1, "default": 8}
],
"Cartoon": [
{"key": "d", "label": "Bilateral d", "type": "int", "min": 3, "max": 15, "step": 2, "default": 9},
{"key": "sigmaColor", "label": "SigmaColor", "type": "int", "min": 20, "max": 200, "step": 5, "default": 75},
{"key": "sigmaSpace", "label": "SigmaSpace", "type": "int", "min": 20, "max": 200, "step": 5, "default": 75},
{"key": "edge_th", "label": "Edge Th", "type": "int", "min": 30, "max": 250, "step": 5, "default": 150}
],
"Oil Paint": [
{"key": "levels", "label": "Levels", "type": "int", "min": 2, "max": 16, "step": 1, "default": 8}
],
"Ink Sketch": [
{"key": "th", "label": "Threshold", "type": "int", "min": 10, "max": 255, "step": 1, "default": 120}
],
"Thermal Vision": [
{"key": "map", "label": "Map (0=HOT,1=INFERNO)", "type": "int", "min": 0, "max": 1, "step": 1, "default": 1}
],
"Chromatic Aberration": [
{"key": "dx", "label": "Shift X", "type": "int", "min": -10, "max": 10, "step": 1, "default": 2},
{"key": "dy", "label": "Shift Y", "type": "int", "min": -10, "max": 10, "step": 1, "default": 1}
],
"Wave Distortion": [
{"key": "amp", "label": "Amplitude", "type": "float", "min": 0.0, "max": 50.0, "step": 0.5, "default": 10.0},
{"key": "freq", "label": "Frequency", "type": "float", "min": 0.5, "max": 10.0, "step": 0.1, "default": 3.0}
],
"Color Grade": [
{"key": "preset", "label": "Preset (0=TealOrange,1=Vintage,2=Cyberpunk)", "type": "int", "min": 0, "max": 2, "step": 1, "default": 0},
{"key": "strength", "label": "Strength", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.6}
],
"Chroma Key": [
{"key": "key_h", "label": "Key Hue", "type": "int", "min": 0, "max": 179, "step": 1, "default": 60},
{"key": "tol", "label": "Tolerance", "type": "int", "min": 5, "max": 60, "step": 1, "default": 30},
{"key": "out_r", "label": "Out R", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "out_g", "label": "Out G", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "out_b", "label": "Out B", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0}
],
"Chroma Key Reverse": [
{"key": "key_h", "label": "Key Hue", "type": "int", "min": 0, "max": 179, "step": 1, "default": 60},
{"key": "tol", "label": "Tolerance", "type": "int", "min": 5, "max": 60, "step": 1, "default": 30},
{"key": "out_r", "label": "Out R", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "out_g", "label": "Out G", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "out_b", "label": "Out B", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0}
],
"Color Replace": [
{"key": "src_r", "label": "Src R", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "src_g", "label": "Src G", "type": "int", "min": 0, "max": 255, "step": 1, "default": 255},
{"key": "src_b", "label": "Src B", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "dst_r", "label": "Dst R", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "dst_g", "label": "Dst G", "type": "int", "min": 0, "max": 255, "step": 1, "default": 0},
{"key": "dst_b", "label": "Dst B", "type": "int", "min": 0, "max": 255, "step": 1, "default": 255},
{"key": "tol", "label": "Tolerance", "type": "int", "min": 5, "max": 120, "step": 1, "default": 30}
],
"Torch: Box Blur": [
{"key": "ksize", "label": "Kernel", "type": "int", "min": 1, "max": 19, "step": 2, "default": 5}
],
"Torch: Quantize": [
{"key": "levels", "label": "Levels", "type": "int", "min": 2, "max": 16, "step": 1, "default": 6}
],
"Torch: Sharpen": [
{"key": "amount", "label": "Amount", "type": "float", "min": 0.0, "max": 2.0, "step": 0.05, "default": 1.0}
],
"Torch: Contrast": [
{"key": "contrast", "label": "Contrast", "type": "float", "min": 0.5, "max": 2.0, "step": 0.05, "default": 1.0},
{"key": "brightness", "label": "Brightness", "type": "float", "min": -0.5, "max": 0.5, "step": 0.05, "default": 0.0}
],
"Torch: Saturation": [
{"key": "s", "label": "Saturation", "type": "float", "min": 0.0, "max": 3.0, "step": 0.05, "default": 1.0}
],
"Torch: Gaussian Blur": [
{"key": "sigma", "label": "Sigma", "type": "float", "min": 0.5, "max": 5.0, "step": 0.1, "default": 1.2}
],
"Torch: Vignette": [
{"key": "strength", "label": "Strength", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.5}
],
"Torch: Sepia": [
{"key": "strength", "label": "Strength", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 1.0}
],
"Torch: Gamma": [
{"key": "gamma", "label": "Gamma", "type": "float", "min": 0.2, "max": 3.0, "step": 0.01, "default": 1.0}
],
"Torch: Pixelate": [
{"key": "block", "label": "Block Size", "type": "int", "min": 2, "max": 50, "step": 1, "default": 8}
],
"Torch: Noise": [
{"key": "sigma", "label": "Sigma", "type": "float", "min": 0.0, "max": 0.3, "step": 0.01, "default": 0.08}
],
"Torch: Edge Glow": [
{"key": "amount", "label": "Amount", "type": "float", "min": 0.0, "max": 2.0, "step": 0.05, "default": 0.6}
],
"Torch: Thermal Vision": [
{"key": "map", "label": "Map (0=HOT,1=INFERNO)", "type": "int", "min": 0, "max": 1, "step": 1, "default": 1}
],
"Torch: Chromatic Aberration": [
{"key": "dx", "label": "Shift X", "type": "int", "min": -10, "max": 10, "step": 1, "default": 2},
{"key": "dy", "label": "Shift Y", "type": "int", "min": -10, "max": 10, "step": 1, "default": 1}
],
"Torch: Wave Distortion": [
{"key": "amp", "label": "Amplitude", "type": "float", "min": 0.0, "max": 50.0, "step": 0.5, "default": 10.0},
{"key": "freq", "label": "Frequency", "type": "float", "min": 0.5, "max": 10.0, "step": 0.1, "default": 3.0}
],
"Torch: Color Grade": [
{"key": "preset", "label": "Preset (0=TealOrange,1=Vintage,2=Cyberpunk)", "type": "int", "min": 0, "max": 2, "step": 1, "default": 0},
{"key": "strength", "label": "Strength", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.6}
],
"Torch: Cartoon": [
{"key": "edge_th", "label": "Edge Th", "type": "int", "min": 30, "max": 250, "step": 5, "default": 150}
],
"Torch: Oil Paint": [
{"key": "levels", "label": "Levels", "type": "int", "min": 2, "max": 16, "step": 1, "default": 8}
],
"Torch: Ink Sketch": [
{"key": "th", "label": "Threshold", "type": "int", "min": 10, "max": 255, "step": 1, "default": 120}
],
"Torch: Echo Trail": [
{"key": "length", "label": "Length", "type": "int", "min": 1, "max": 20, "step": 1, "default": 8},
{"key": "decay", "label": "Decay", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.6}
],
"Torch: TimeShift Blend": [
{"key": "delay", "label": "Delay", "type": "int", "min": 1, "max": 30, "step": 1, "default": 6},
{"key": "alpha", "label": "Alpha", "type": "float", "min": 0.0, "max": 1.0, "step": 0.05, "default": 0.5}
],
}
try:
STYLE_PARAMS.update(EXTRA_STYLE_PARAMS)
except Exception:
pass
def face_overlay_requires_overlay(style_name):
return style_name == "Face Overlay"
def style_transfer_requires_template(style_name):
return style_name == "Style Transfer"
def apply_style_to_frame(frame, style_name, overlays=None, templates=None, params=None, preview=False):
"""
frame: BGR numpy array (H, W, 3)
style_name: string, one of AVAILABLE_STYLES
overlays: list of overlay filepaths (PNG) - used by Face Overlay
templates: list of style-template filepaths (jpg/png) - used by Style Transfer
params: dict of parameter values (key->value coming from GUI sliders)
preview: if True, use faster/light parameters
returns BGR numpy array
"""
if params is None:
params = {}
if style_name == "Original" or style_name is None:
return frame
# Standard Styles
if style_name == "Drawn":
return drawn(frame, params=params, preview=preview)
if style_name == "Comic":
return comic(frame, params=params, preview=preview)
if style_name == "Outline":
return outline(frame, params=params, preview=preview)
if style_name == "Trippy":
return trippy(frame, params=params, preview=preview)
if style_name == "Posterize":
levels = int(params.get("levels", 6))
return posterize(frame, levels=levels)
if style_name == "Face Overlay":
if overlays and len(overlays) > 0:
return face_overlay(frame, overlays, params=params, preview=preview)
else:
return frame
if style_name == "Style Transfer":
if templates and len(templates) > 0:
return style_transfer(frame, templates, params=params, preview=preview)
else:
return frame
if style_name == "Vignette":
radius = float(params.get("radius_scale", 1.5))
return vignette(frame, preview=preview, radius_scale=radius)
if style_name == "Motion Blur":
k = int(params.get("ksize", 21))
return motion_blur(frame, preview=preview, ksize=k)
if style_name == "Bloom":
thr = int(params.get("threshold", 200))
inten = float(params.get("intensity", 0.6))
blur_s = int(params.get("blur_strength", 35))
return bloom(frame, preview=preview, threshold=thr, intensity=inten, blur_strength=blur_s)
if style_name == "Emboss":
return emboss(frame, preview=preview)
if style_name == "Chroma Shift":
ms = int(params.get("max_shift", 8))
return chroma_shift(frame, preview=preview, max_shift=ms)
if style_name == "Kaleidoscope":
return kaleidoscope(frame, preview=preview)
if style_name == "Glitch":
inten = float(params.get("intensity", 0.06))
return glitch(frame, preview=preview, intensity=inten)
# Neue Filter – PARAM NAMES exakt wie in STYLE_PARAMS
elif style_name == "Brightness/Contrast":
brightness = params.get("brightness", 0)
contrast = params.get("contrast", 1.0)
return adjust_brightness_contrast(frame, brightness, contrast)
elif style_name == "Color Correction":
r_gain = params.get("r_gain", 1.0)
g_gain = params.get("g_gain", 1.0)
b_gain = params.get("b_gain", 1.0)
contrast = params.get("contrast", 1.0)
brightness = params.get("brightness", 0.0)
return apply_color_correction(frame, r_gain, g_gain, b_gain, contrast, brightness)
elif style_name == "Color Balance":
r_mult = params.get("r_gain", 1.0)
g_mult = params.get("g_gain", 1.0)
b_mult = params.get("b_gain", 1.0)
return color_balance(frame, r_mult, g_mult, b_mult)
elif style_name == "Saturation":
saturation = params.get("saturation", 1.0)
return adjust_saturation(frame, saturation)
elif style_name == "Hue Shift":
hue_shift = params.get("hue_shift", 0)
return adjust_hue(frame, hue_shift)
elif style_name == "Sharpen":
amount = params.get("amount", 1.0)
return sharpen(frame, amount)
elif style_name == "TrippyShift":
shift = params.get("shift", 5)
blend = params.get("blend", 0.5)
return trippy_color_shift(frame, shift, blend)
# Extra OpenCV filters
if style_name == "Sepia":
strength = float(params.get("strength", 1.0))
return sepia(frame, strength=strength)
if style_name == "Gamma":
gamma = float(params.get("gamma", 1.0))
return gamma_correction(frame, gamma=gamma)
if style_name == "Pixelate":
block = int(params.get("block", 12))
return pixelate(frame, block_size=block)
if style_name == "Noise":
sigma = int(params.get("sigma", 10))
return add_noise(frame, sigma=sigma)
if style_name == "Edge Glow":
amount = float(params.get("amount", 0.6))
blur = int(params.get("blur", 9))
return edge_glow(frame, amount=amount, blur=blur)
if style_name == "Oil Paint":
levels = int(params.get("levels", 8))
return oil_paint(frame, levels=levels)
if style_name == "Ink Sketch":
th = int(params.get("th", 120))
return ink_sketch(frame, th=th)
if style_name == "Thermal Vision":
m = int(params.get("map", 1))
return thermal_vision(frame, m=m)
if style_name == "Chromatic Aberration":
dx = int(params.get("dx", 2)); dy = int(params.get("dy", 1))
return chromatic_aberration(frame, dx=dx, dy=dy)
if style_name == "Wave Distortion":
amp = float(params.get("amp", 10.0)); freq = float(params.get("freq", 3.0))
return wave_distortion(frame, amp=amp, freq=freq)
if style_name == "Color Grade":
preset = int(params.get("preset", 0)); strength = float(params.get("strength", 0.6))
return color_grade(frame, preset=preset, strength=strength)
if style_name == "Echo Trail":
length = int(params.get("length", 8)); decay = float(params.get("decay", 0.6))
return echo_trail(frame, length=length, decay=decay)
if style_name == "TimeShift Blend":
delay = int(params.get("delay", 6)); alpha = float(params.get("alpha", 0.5))
return timeshift_blend(frame, delay=delay, alpha=alpha)
if style_name == "Invert Colors":
return invert_colors(frame)
if style_name == "Median Blur":
k = int(params.get("ksize", 5))
return median_blur(frame, ksize=k)
if style_name == "CLAHE":
clip = float(params.get("clip", 2.0))
tile = int(params.get("tile", 8))
return clahe_enhance(frame, clip=clip, tile=tile)
if style_name == "Cartoon":
d = int(params.get("d", 9)); sc = int(params.get("sigmaColor", 75)); ss = int(params.get("sigmaSpace", 75)); et = int(params.get("edge_th", 150))
return cartoonize(frame, d=d, sigmaColor=sc, sigmaSpace=ss, edge_th=et)
if style_name == "Chroma Key":
key_h = int(params.get("key_h", 60))
tol = int(params.get("tol", 30))
out_r = int(params.get("out_r", 0)); out_g = int(params.get("out_g", 0)); out_b = int(params.get("out_b", 0))
return chroma_key(frame, key_h=key_h, tol=tol, out_color=(out_b, out_g, out_r), reverse=False)
if style_name == "Chroma Key Reverse":
key_h = int(params.get("key_h", 60))
tol = int(params.get("tol", 30))
out_r = int(params.get("out_r", 0)); out_g = int(params.get("out_g", 0)); out_b = int(params.get("out_b", 0))
return chroma_key(frame, key_h=key_h, tol=tol, out_color=(out_b, out_g, out_r), reverse=True)
if style_name == "Color Replace":
src = (int(params.get("src_b", 0)), int(params.get("src_g", 255)), int(params.get("src_r", 0)))
dst = (int(params.get("dst_b", 255)), int(params.get("dst_g", 0)), int(params.get("dst_r", 0)))
tol = int(params.get("tol", 30))
return color_replace(frame, src_color=src, dst_color=dst, tol=tol)
# fallback
return frame
# --- Existing filters (drawn, comic, outline, trippy, posterize, face_overlay, style_transfer, etc.) ---
# For brevity we keep function implementations similar to before but read from params when appropriate.
def drawn(frame, params=None, preview=False):
sigma_s = 60 if not preview else 40
sigma_r = 0.07 if not preview else 0.12
shade_factor = float(params.get("shade_factor", 0.02)) if params else (0.02 if not preview else 0.05)
try:
dst_gray, dst_color = cv2.pencilSketch(frame, sigma_s=sigma_s, sigma_r=sigma_r, shade_factor=shade_factor)
out = cv2.cvtColor(dst_gray, cv2.COLOR_GRAY2BGR)
return out
except Exception:
return comic(frame, params=params, preview=preview)
def comic(frame, params=None, preview=False):
sigma_s = int(params.get("sigma_s", 60)) if params else (60 if not preview else 40)
sigma_r = float(params.get("sigma_r", 0.45)) if params else (0.45 if not preview else 0.6)
try:
sm = cv2.bilateralFilter(frame, d=9, sigmaColor=75 if not preview else 50, sigmaSpace=75)
styl = cv2.stylization(sm, sigma_s=sigma_s, sigma_r=sigma_r)
return styl
except Exception:
p = posterize(frame, levels=int(params.get("levels", 6)) if params else 6)
e = outline(frame, params=params, preview=preview)
e_gray = cv2.cvtColor(e, cv2.COLOR_BGR2GRAY)
_, mask = cv2.threshold(e_gray, 10, 255, cv2.THRESH_BINARY_INV)
mask3 = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR).astype(float)/255.0
out = (p.astype(float) * mask3 + frame.astype(float) * (1-mask3)).astype(np.uint8)
return out
def outline(frame, params=None, preview=False):
low = int(params.get("canny_low", 80)) if params else 80
high = int(params.get("canny_high", 180)) if params else 180
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
try:
if _USE_CUDA and _cuda_available():
g = cv2.cuda_GpuMat()
g.upload(gray)
try:
gf = cv2.cuda.createGaussianFilter(g.type(), g.type(), (5,5), 0)
g = gf.apply(g)
except Exception:
pass
try:
canny = cv2.cuda.createCannyEdgeDetector(low, high)
ge = canny.detect(g)
edges = ge.download()
except Exception:
edges = cv2.Canny(gray, low, high)
else:
raise RuntimeError
except Exception:
blurred = cv2.GaussianBlur(gray, (5,5), 0)
edges = cv2.Canny(blurred, low, high)
inv = cv2.bitwise_not(edges)
inv_color = cv2.cvtColor(inv, cv2.COLOR_GRAY2BGR)
out = cv2.bitwise_and(frame, inv_color)
white_lines = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
white_lines[white_lines>0] = 255
out = cv2.addWeighted(out, 0.9, white_lines, 0.8, 0)
return out
def trippy(frame, params=None, preview=False):
blend_alpha = float(params.get("blend", 0.5)) if params else 0.5
cmap_idx = int(params.get("colormap", 2)) if params else 2
cmap_map = {0: cv2.COLORMAP_JET, 1: cv2.COLORMAP_HSV, 2: cv2.COLORMAP_TURBO, 3: cv2.COLORMAP_RAINBOW}
cmap = cmap_map.get(cmap_idx, cv2.COLORMAP_TURBO)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
colored = cv2.applyColorMap(gray, cmap)
blend_orig = float(1.0 - blend_alpha)
out = cv2.addWeighted(colored, blend_alpha, frame, blend_orig, 0)
return out
def posterize(frame, levels=6):
div = max(1, int(256 / max(2, levels)))
quant = (frame // div) * div + div//2
return quant.astype(np.uint8)
def face_overlay(frame, overlays, params=None, preview=False):
cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30,30))
out = frame.copy()
if len(faces) == 0:
return out
overlay_path = overlays[0]
ov = cv2.imread(overlay_path, cv2.IMREAD_UNCHANGED)
if ov is None:
return out
scale = float(params.get("scale", 1.1)) if params else 1.1
for (x,y,w,h) in faces:
factor = scale
ow = int(w * factor)
oh = int(ow * ov.shape[0] / ov.shape[1]) if ov.shape[1] != 0 else int(h * factor)
x1 = int(x + w/2 - ow/2)
y1 = int(y + h/2 - oh/2)
x2 = x1 + ow
y2 = y1 + oh
fx1, fx2 = max(0, x1), min(out.shape[1], x2)
fy1, fy2 = max(0, y1), min(out.shape[0], y2)
if fx1 >= fx2 or fy1 >= fy2:
continue
ov_x1 = fx1 - x1
ov_y1 = fy1 - y1
ov_x2 = ov_x1 + (fx2 - fx1)
ov_y2 = ov_y1 + (fy2 - fy1)
ov_resized_full = cv2.resize(ov, (ow, oh), interpolation=cv2.INTER_AREA)
ov_region = ov_resized_full[ov_y1:ov_y2, ov_x1:ov_x2]
if ov_region.shape[2] == 4:
ov_bgr = ov_region[:,:,0:3]
alpha = ov_region[:,:,3] / 255.0
alpha = alpha[..., np.newaxis]
bg_region = out[fy1:fy2, fx1:fx2].astype(float)
blended = (alpha * ov_bgr.astype(float) + (1 - alpha) * bg_region).astype(np.uint8)
out[fy1:fy2, fx1:fx2] = blended
else:
out[fy1:fy2, fx1:fx2] = ov_region[:, :, :3]
return out
def style_transfer(frame, style_image_path_or_list, params=None, preview=False):
"""
Multi-template lightweight style transfer (weighted LAB stats + stylization).
style_image_path_or_list: either single path or list of paths
params: may contain 'blend_alpha' to control final blend
"""
try:
if isinstance(style_image_path_or_list, str):
templates = [style_image_path_or_list]
else:
templates = list(style_image_path_or_list)
if len(templates) == 0:
return frame
weights = None
# If params contains per-template weights, ignore here (GUI could extend)
# For now use equal weights
weights = [1.0] * len(templates)
wsum = sum(weights)
if wsum == 0:
weights = [1.0/len(weights)] * len(weights)
else:
weights = [w/wsum for w in weights]
lab_stats = {"l_mean":0.0, "a_mean":0.0, "b_mean":0.0, "l_std":0.0, "a_std":0.0, "b_std":0.0}
for path, wt in zip(templates, weights):
st = cv2.imread(path)
if st is None:
continue
h, w = frame.shape[:2]
st_small = cv2.resize(st, (max(64, min(256, w//4)), max(64, min(256, h//4))), interpolation=cv2.INTER_AREA)
st_lab = cv2.cvtColor(st_small, cv2.COLOR_BGR2LAB).astype(np.float32)
l_mean, a_mean, b_mean = cv2.mean(st_lab)[:3]
l_std = st_lab[:,:,0].std()
a_std = st_lab[:,:,1].std()
b_std = st_lab[:,:,2].std()
lab_stats["l_mean"] += wt * l_mean
lab_stats["a_mean"] += wt * a_mean
lab_stats["b_mean"] += wt * b_mean
lab_stats["l_std"] += wt * l_std
lab_stats["a_std"] += wt * a_std
lab_stats["b_std"] += wt * b_std
frame_lab = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB).astype(np.float32)
l_mean_src = frame_lab[:,:,0].mean()
a_mean_src = frame_lab[:,:,1].mean()
b_mean_src = frame_lab[:,:,2].mean()
l_std_src = max(frame_lab[:,:,0].std(), 1e-6)
a_std_src = max(frame_lab[:,:,1].std(), 1e-6)
b_std_src = max(frame_lab[:,:,2].std(), 1e-6)
l_mean_tar = lab_stats["l_mean"]
a_mean_tar = lab_stats["a_mean"]
b_mean_tar = lab_stats["b_mean"]
l_std_tar = max(lab_stats["l_std"], 1e-6)
a_std_tar = max(lab_stats["a_std"], 1e-6)
b_std_tar = max(lab_stats["b_std"], 1e-6)
result_lab = frame_lab.copy()
result_lab[:,:,0] = ((result_lab[:,:,0] - l_mean_src) * (l_std_tar / l_std_src)) + l_mean_tar
result_lab[:,:,1] = ((result_lab[:,:,1] - a_mean_src) * (a_std_tar / a_std_src)) + a_mean_tar
result_lab[:,:,2] = ((result_lab[:,:,2] - b_mean_src) * (b_std_tar / b_std_src)) + b_mean_tar
result_lab = np.clip(result_lab, 0, 255).astype(np.uint8)
color_transferred = cv2.cvtColor(result_lab, cv2.COLOR_LAB2BGR)
sigma_s = 60 if not preview else 40
sigma_r = 0.45 if not preview else 0.6
try:
stylized = cv2.stylization(frame, sigma_s=sigma_s, sigma_r=sigma_r)
except Exception:
stylized = frame.copy()
blend_alpha = float(params.get("blend_alpha", 0.6)) if params else 0.6
out = cv2.addWeighted(color_transferred, blend_alpha, stylized, 1.0 - blend_alpha, 0)
return out
except Exception:
return frame
# --- NEW EFFECTS (Vignette, Motion Blur, Bloom, Emboss, Chroma Shift, Kaleidoscope, Glitch) ---
def vignette(frame, preview=False, radius_scale=1.5):
try:
rows, cols = frame.shape[:2]
X_resultant_kernel = cv2.getGaussianKernel(cols, cols / (radius_scale * 1.5))
Y_resultant_kernel = cv2.getGaussianKernel(rows, rows / (radius_scale * 1.5))
kernel = Y_resultant_kernel @ X_resultant_kernel.T
mask = kernel / kernel.max()
mask = cv2.merge([mask, mask, mask])
out = (frame.astype(np.float32) * mask).astype(np.uint8)
return out
except Exception:
return frame
def motion_blur(frame, preview=False, ksize=15):
try:
k = ksize if not preview else max(3, ksize//3)
if k % 2 == 0:
k += 1
kernel = np.zeros((k, k))
kernel[int((k - 1)/2), :] = np.ones(k)
kernel = kernel / k
out = cv2.filter2D(frame, -1, kernel)
return out
except Exception:
return frame
def bloom(frame, preview=False, threshold=200, intensity=0.6, blur_strength=25):
try:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
_, mask = cv2.threshold(gray, threshold, 255, cv2.THRESH_BINARY)
mask = cv2.GaussianBlur(mask, (7,7), 0)
mask3 = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR).astype(np.float32)/255.0
bsize = blur_strength if not preview else max(5, blur_strength//3)
if bsize % 2 == 0:
bsize += 1
try:
if _USE_CUDA and _cuda_available():
g = cv2.cuda_GpuMat()
g.upload(frame)
gf = cv2.cuda.createGaussianFilter(g.type(), g.type(), (bsize, bsize), 0)
gb = gf.apply(g)
blurred = gb.download()
else:
raise RuntimeError
except Exception:
blurred = cv2.GaussianBlur(frame, (bsize, bsize), 0)
glow = (blurred.astype(np.float32) * mask3).astype(np.uint8)
out = cv2.addWeighted(frame, 1.0, glow, intensity, 0)
return out
except Exception:
return frame
def emboss(frame, preview=False):
try:
kernel = np.array([[ -2, -1, 0],
[ -1, 1, 1],
[ 0, 1, 2]])
embossed = cv2.filter2D(frame, -1, kernel) + 128
embossed = np.clip(embossed, 0, 255).astype(np.uint8)
return embossed
except Exception:
return frame
def chroma_shift(frame, preview=False, max_shift=8):
try:
h, w = frame.shape[:2]
shift = max_shift if not preview else max(2, max_shift//3)
b, g, r = cv2.split(frame)
tx = shift // 2
ty = shift // 3
M1 = np.float32([[1, 0, tx], [0, 1, 0]])
M2 = np.float32([[1, 0, -tx], [0, 1, ty]])
b_s = cv2.warpAffine(b, M1, (w, h), borderMode=cv2.BORDER_REFLECT)
r_s = cv2.warpAffine(r, M2, (w, h), borderMode=cv2.BORDER_REFLECT)
out = cv2.merge([b_s, g, r_s])
return out
except Exception:
return frame
def kaleidoscope(frame, preview=False, segments=4):
try:
h, w = frame.shape[:2]
out = np.zeros_like(frame)
qh, qw = h//2, w//2
tl = frame[0:qh, 0:qw]
tr = frame[0:qh, qw:w]
bl = frame[qh:h, 0:qw]
br = frame[qh:h, qw:w]
a = tl
b = cv2.flip(tr, 1)
c = cv2.flip(bl, 0)
d = cv2.flip(br, -1)
out[0:qh, 0:qw] = a
out[0:qh, qw:w] = b
out[qh:h, 0:qw] = c
out[qh:h, qw:w] = d
out = cv2.GaussianBlur(out, (3,3), 0)
return out
except Exception:
return frame
def glitch(frame, preview=False, intensity=0.06):
try:
out = frame.copy()
h, w = frame.shape[:2]
rng = np.random.RandomState()
slices = max(2, int(h * (intensity if not preview else intensity/3)))
for i in range(slices):
y = rng.randint(0, h)
hslice = rng.randint(4, max(6, h//20))
shift = rng.randint(-w//12, w//12)
y2 = min(h, y+hslice)
if shift > 0:
out[y:y2, shift:] = out[y:y2, :-shift]
out[y:y2, :shift] = frame[y:y2, :shift]
elif shift < 0:
s = -shift
out[y:y2, :-s] = out[y:y2, s:]
out[y:y2, -s:] = frame[y:y2, -s:]
b, g, r = cv2.split(out)
dx = 1 if preview else max(2, w//120)
M = np.float32([[1,0,dx],[0,1,0]])
r = cv2.warpAffine(r, M, (w,h), borderMode=cv2.BORDER_REFLECT)
M2 = np.float32([[1,0,-dx],[0,1,0]])
b = cv2.warpAffine(b, M2, (w,h), borderMode=cv2.BORDER_REFLECT)
out = cv2.merge([b,g,r])
line_strength = 10 if not preview else 4
for y in range(0, h, 2):
out[y:y+1,:,:] = np.clip(out[y:y+1,:,:].astype(int) - line_strength, 0, 255).astype(np.uint8)
return out
except Exception:
return frame
# --------------------------
# ✨ BASIC FILTERS SECTION ✨
# --------------------------
def adjust_brightness_contrast(frame, brightness=0, contrast=1.0):
"""
frame: BGR uint8
brightness: additive (-100..100)
contrast: multiplicative (0.5..2.0)
"""
f = frame.astype(np.float32)
f = f * contrast + brightness
f = np.clip(f, 0, 255)
return f.astype(np.uint8)
def adjust_saturation(frame, saturation=1.0):
"""Saturation control in HSV space"""
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV).astype(np.float32)
hsv[..., 1] *= saturation
hsv[..., 1] = np.clip(hsv[..., 1], 0, 255)
return cv2.cvtColor(hsv.astype(np.uint8), cv2.COLOR_HSV2BGR)
def adjust_hue(frame, hue_shift=0):
"""Shift hue (color tint)"""
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
hsv[..., 0] = (hsv[..., 0].astype(np.int32) + hue_shift) % 180
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
def sharpen(frame, intensity=1.0):
"""Sharpen image edges"""
kernel = np.array([[0, -1, 0],
[-1, 5 + intensity, -1],
[0, -1, 0]])
return cv2.filter2D(frame, -1, kernel)
def color_balance(frame, r_mult=1.0, g_mult=1.0, b_mult=1.0):
"""RGB color correction"""
b, g, r = cv2.split(frame.astype(np.float32))
r *= r_mult
g *= g_mult
b *= b_mult
merged = cv2.merge((np.clip(b, 0, 255), np.clip(g, 0, 255), np.clip(r, 0, 255)))
return merged.astype(np.uint8)
def trippy_color_shift(frame, shift=5, blend=0.5):
"""RGB channel shift with blend.
shift: pixel shift for channels (int)
blend: 0..1, weight of original image in the mix
"""
try:
h, w = frame.shape[:2]
b, g, r = cv2.split(frame)
dx = int(max(0, shift))
# create slight opposing shifts on R and B
M_r = np.float32([[1, 0, dx], [0, 1, 0]])
M_b = np.float32([[1, 0, -dx], [0, 1, 0]])
r_s = cv2.warpAffine(r, M_r, (w, h), borderMode=cv2.BORDER_REFLECT)
b_s = cv2.warpAffine(b, M_b, (w, h), borderMode=cv2.BORDER_REFLECT)
shifted = cv2.merge([b_s, g, r_s])
alpha = float(max(0.0, min(1.0, blend)))
out = cv2.addWeighted(frame, alpha, shifted, 1.0 - alpha, 0)
return out
except Exception:
return frame
# ---- Extra OpenCV filter implementations ----
def sepia(frame, strength=1.0):
import numpy as np
s = float(max(0.0, min(1.0, strength)))
kernel = np.array(
[
[0.272, 0.534, 0.131],
[0.349, 0.686, 0.168],
[0.393, 0.769, 0.189],
]
)
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
sep = np.clip(rgb @ kernel.T, 0, 255).astype(np.uint8)
out = cv2.addWeighted(rgb, 1.0 - s, sep, s, 0)
return cv2.cvtColor(out, cv2.COLOR_RGB2BGR)
def gamma_correction(frame, gamma=1.0):
import numpy as np
g = max(0.01, float(gamma))
invG = 1.0 / g
table = ((np.arange(256) / 255.0) ** invG * 255.0).astype('uint8')
return cv2.LUT(frame, table)
def pixelate(frame, block_size=12):
h, w = frame.shape[:2]
b = int(max(1, block_size))
small = cv2.resize(frame, (max(1, w // b), max(1, h // b)), interpolation=cv2.INTER_LINEAR)
return cv2.resize(small, (w, h), interpolation=cv2.INTER_NEAREST)
def add_noise(frame, sigma=10):
import numpy as np
s = float(max(0.0, sigma))
noise = np.random.normal(0, s, frame.shape).astype(np.float32)
out = np.clip(frame.astype(np.float32) + noise, 0, 255).astype(np.uint8)
return out
def edge_glow(frame, amount=0.6, blur=9):
amt = float(max(0.0, amount))
k = int(max(1, blur))
if k % 2 == 0:
k += 1
edges = outline(frame, params={"canny_low": 50, "canny_high": 150})
edges_gray = cv2.cvtColor(edges, cv2.COLOR_BGR2GRAY)
edges_col = cv2.cvtColor(edges_gray, cv2.COLOR_GRAY2BGR)
blurred = cv2.GaussianBlur(frame, (k, k), 0)
glow = cv2.addWeighted(blurred, 1.0, edges_col, amt, 0)
return glow
def invert_colors(frame):
return (255 - frame).astype(np.uint8)
def median_blur(frame, ksize=5):
k = int(max(1, ksize))
if k % 2 == 0:
k += 1
return cv2.medianBlur(frame, k)
def clahe_enhance(frame, clip=2.0, tile=8):
clip = float(max(0.1, clip))
tile = int(max(2, tile))
lab = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
clahe = cv2.createCLAHE(clipLimit=clip, tileGridSize=(tile, tile))
l2 = clahe.apply(l)
lab2 = cv2.merge([l2, a, b])
return cv2.cvtColor(lab2, cv2.COLOR_LAB2BGR)
def cartoonize(frame, d=9, sigmaColor=75, sigmaSpace=75, edge_th=150):