-
Notifications
You must be signed in to change notification settings - Fork 12
/
README.html
947 lines (756 loc) · 27.9 KB
/
README.html
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
<!DOCTYPE html><html><head><meta charset="utf-8"><style>@font-face {
font-family: octicons-anchor;
src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUkXUH0+U27RoRpOIyCKjbMCVejwypzJJG4jIwb43rfl6wbwanocrJm9XFYfskuVC5K/TPyczNU7b84CXcbxks1Un6H6tLH9vf2LRnn8Ax7A5WQAAAHicY2BkYGAA4teL1+yI57f5ysDNwgAC529f0kOmWRiYVgEpDgYmEA8AUzEKsQAAAHicY2BkYGB2+O/AEMPCAAJAkpEBFbAAADgKAe0EAAAiAAAAAAQAAAAEAAAAAAAAKgAqACoAiAAAeJxjYGRgYGBhsGFgYgABEMkFhAwM/xn0QAIAD6YBhwB4nI1Ty07cMBS9QwKlQapQW3VXySvEqDCZGbGaHULiIQ1FKgjWMxknMfLEke2A+IJu+wntrt/QbVf9gG75jK577Lg8K1qQPCfnnnt8fX1NRC/pmjrk/zprC+8D7tBy9DHgBXoWfQ44Av8t4Bj4Z8CLtBL9CniJluPXASf0Lm4CXqFX8Q84dOLnMB17N4c7tBo1AS/Qi+hTwBH4rwHHwN8DXqQ30XXAS7QaLwSc0Gn8NuAVWou/gFmnjLrEaEh9GmDdDGgL3B4JsrRPDU2hTOiMSuJUIdKQQayiAth69r6akSSFqIJuA19TrzCIaY8sIoxyrNIrL//pw7A2iMygkX5vDj+G+kuoLdX4GlGK/8Lnlz6/h9MpmoO9rafrz7ILXEHHaAx95s9lsI7AHNMBWEZHULnfAXwG9/ZqdzLI08iuwRloXE8kfhXYAvE23+23DU3t626rbs8/8adv+9DWknsHp3E17oCf+Z48rvEQNZ78paYM38qfk3v/u3l3u3GXN2Dmvmvpf1Srwk3pB/VSsp512bA/GG5i2WJ7wu430yQ5K3nFGiOqgtmSB5pJVSizwaacmUZzZhXLlZTq8qGGFY2YcSkqbth6aW1tRmlaCFs2016m5qn36SbJrqosG4uMV4aP2PHBmB3tjtmgN2izkGQyLWprekbIntJFing32a5rKWCN/SdSoga45EJykyQ7asZvHQ8PTm6cslIpwyeyjbVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');
}
* {
box-sizing: border-box;
}
body {
width: 980px;
margin-right: auto;
margin-left: auto;
}
body .markdown-body {
padding: 45px;
border: 1px solid #ddd;
border-radius: 3px;
word-wrap: break-word;
}
pre {
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.markdown-body {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
color: #333;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
}
.markdown-body a {
background-color: transparent;
}
.markdown-body a:active,
.markdown-body a:hover {
outline: 0;
}
.markdown-body strong {
font-weight: bold;
}
.markdown-body h1 {
font-size: 2em;
margin: 0.67em 0;
}
.markdown-body img {
border: 0;
}
.markdown-body hr {
box-sizing: content-box;
height: 0;
}
.markdown-body pre {
overflow: auto;
}
.markdown-body code,
.markdown-body kbd,
.markdown-body pre {
font-family: monospace, monospace;
font-size: 1em;
}
.markdown-body input {
color: inherit;
font: inherit;
margin: 0;
}
.markdown-body html input[disabled] {
cursor: default;
}
.markdown-body input {
line-height: normal;
}
.markdown-body input[type="checkbox"] {
box-sizing: border-box;
padding: 0;
}
.markdown-body table {
border-collapse: collapse;
border-spacing: 0;
}
.markdown-body td,
.markdown-body th {
padding: 0;
}
.markdown-body input {
font: 13px / 1.4 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.markdown-body a {
color: #4078c0;
text-decoration: none;
}
.markdown-body a:hover,
.markdown-body a:active {
text-decoration: underline;
}
.markdown-body hr {
height: 0;
margin: 15px 0;
overflow: hidden;
background: transparent;
border: 0;
border-bottom: 1px solid #ddd;
}
.markdown-body hr:before {
display: table;
content: "";
}
.markdown-body hr:after {
display: table;
clear: both;
content: "";
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 15px;
margin-bottom: 15px;
line-height: 1.1;
}
.markdown-body h1 {
font-size: 30px;
}
.markdown-body h2 {
font-size: 21px;
}
.markdown-body h3 {
font-size: 16px;
}
.markdown-body h4 {
font-size: 14px;
}
.markdown-body h5 {
font-size: 12px;
}
.markdown-body h6 {
font-size: 11px;
}
.markdown-body blockquote {
margin: 0;
}
.markdown-body ul,
.markdown-body ol {
padding: 0;
margin-top: 0;
margin-bottom: 0;
}
.markdown-body ol ol,
.markdown-body ul ol {
list-style-type: lower-roman;
}
.markdown-body ul ul ol,
.markdown-body ul ol ol,
.markdown-body ol ul ol,
.markdown-body ol ol ol {
list-style-type: lower-alpha;
}
.markdown-body dd {
margin-left: 0;
}
.markdown-body code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 12px;
}
.markdown-body pre {
margin-top: 0;
margin-bottom: 0;
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.markdown-body .select::-ms-expand {
opacity: 0;
}
.markdown-body .octicon {
font: normal normal normal 16px/1 octicons-anchor;
display: inline-block;
text-decoration: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.markdown-body .octicon-link:before {
content: '\f05c';
}
.markdown-body:before {
display: table;
content: "";
}
.markdown-body:after {
display: table;
clear: both;
content: "";
}
.markdown-body>*:first-child {
margin-top: 0 !important;
}
.markdown-body>*:last-child {
margin-bottom: 0 !important;
}
.markdown-body a:not([href]) {
color: inherit;
text-decoration: none;
}
.markdown-body .anchor {
display: inline-block;
padding-right: 2px;
margin-left: -18px;
}
.markdown-body .anchor:focus {
outline: none;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 1em;
margin-bottom: 16px;
font-weight: bold;
line-height: 1.4;
}
.markdown-body h1 .octicon-link,
.markdown-body h2 .octicon-link,
.markdown-body h3 .octicon-link,
.markdown-body h4 .octicon-link,
.markdown-body h5 .octicon-link,
.markdown-body h6 .octicon-link {
color: #000;
vertical-align: middle;
visibility: hidden;
}
.markdown-body h1:hover .anchor,
.markdown-body h2:hover .anchor,
.markdown-body h3:hover .anchor,
.markdown-body h4:hover .anchor,
.markdown-body h5:hover .anchor,
.markdown-body h6:hover .anchor {
text-decoration: none;
}
.markdown-body h1:hover .anchor .octicon-link,
.markdown-body h2:hover .anchor .octicon-link,
.markdown-body h3:hover .anchor .octicon-link,
.markdown-body h4:hover .anchor .octicon-link,
.markdown-body h5:hover .anchor .octicon-link,
.markdown-body h6:hover .anchor .octicon-link {
visibility: visible;
}
.markdown-body h1 {
padding-bottom: 0.3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
.markdown-body h1 .anchor {
line-height: 1;
}
.markdown-body h2 {
padding-bottom: 0.3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
.markdown-body h2 .anchor {
line-height: 1;
}
.markdown-body h3 {
font-size: 1.5em;
line-height: 1.43;
}
.markdown-body h3 .anchor {
line-height: 1.2;
}
.markdown-body h4 {
font-size: 1.25em;
}
.markdown-body h4 .anchor {
line-height: 1.2;
}
.markdown-body h5 {
font-size: 1em;
}
.markdown-body h5 .anchor {
line-height: 1.1;
}
.markdown-body h6 {
font-size: 1em;
color: #777;
}
.markdown-body h6 .anchor {
line-height: 1.1;
}
.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre {
margin-top: 0;
margin-bottom: 16px;
}
.markdown-body hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
}
.markdown-body ul,
.markdown-body ol {
padding-left: 2em;
}
.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
margin-top: 0;
margin-bottom: 0;
}
.markdown-body li>p {
margin-top: 16px;
}
.markdown-body dl {
padding: 0;
}
.markdown-body dl dt {
padding: 0;
margin-top: 16px;
font-size: 1em;
font-style: italic;
font-weight: bold;
}
.markdown-body dl dd {
padding: 0 16px;
margin-bottom: 16px;
}
.markdown-body blockquote {
padding: 0 15px;
color: #777;
border-left: 4px solid #ddd;
}
.markdown-body blockquote>:first-child {
margin-top: 0;
}
.markdown-body blockquote>:last-child {
margin-bottom: 0;
}
.markdown-body table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}
.markdown-body table th {
font-weight: bold;
}
.markdown-body table th,
.markdown-body table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
.markdown-body table tr {
background-color: #fff;
border-top: 1px solid #ccc;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f8f8f8;
}
.markdown-body img {
max-width: 100%;
box-sizing: content-box;
background-color: #fff;
}
.markdown-body code {
padding: 0;
padding-top: 0.2em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0,0,0,0.04);
border-radius: 3px;
}
.markdown-body code:before,
.markdown-body code:after {
letter-spacing: -0.2em;
content: "\00a0";
}
.markdown-body pre>code {
padding: 0;
margin: 0;
font-size: 100%;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}
.markdown-body .highlight {
margin-bottom: 16px;
}
.markdown-body .highlight pre,
.markdown-body pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}
.markdown-body .highlight pre {
margin-bottom: 0;
word-break: normal;
}
.markdown-body pre {
word-wrap: normal;
}
.markdown-body pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}
.markdown-body pre code:before,
.markdown-body pre code:after {
content: normal;
}
.markdown-body kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.markdown-body .pl-c {
color: #969896;
}
.markdown-body .pl-c1,
.markdown-body .pl-s .pl-v {
color: #0086b3;
}
.markdown-body .pl-e,
.markdown-body .pl-en {
color: #795da3;
}
.markdown-body .pl-s .pl-s1,
.markdown-body .pl-smi {
color: #333;
}
.markdown-body .pl-ent {
color: #63a35c;
}
.markdown-body .pl-k {
color: #a71d5d;
}
.markdown-body .pl-pds,
.markdown-body .pl-s,
.markdown-body .pl-s .pl-pse .pl-s1,
.markdown-body .pl-sr,
.markdown-body .pl-sr .pl-cce,
.markdown-body .pl-sr .pl-sra,
.markdown-body .pl-sr .pl-sre {
color: #183691;
}
.markdown-body .pl-v {
color: #ed6a43;
}
.markdown-body .pl-id {
color: #b52a1d;
}
.markdown-body .pl-ii {
background-color: #b52a1d;
color: #f8f8f8;
}
.markdown-body .pl-sr .pl-cce {
color: #63a35c;
font-weight: bold;
}
.markdown-body .pl-ml {
color: #693a17;
}
.markdown-body .pl-mh,
.markdown-body .pl-mh .pl-en,
.markdown-body .pl-ms {
color: #1d3e81;
font-weight: bold;
}
.markdown-body .pl-mq {
color: #008080;
}
.markdown-body .pl-mi {
color: #333;
font-style: italic;
}
.markdown-body .pl-mb {
color: #333;
font-weight: bold;
}
.markdown-body .pl-md {
background-color: #ffecec;
color: #bd2c00;
}
.markdown-body .pl-mi1 {
background-color: #eaffea;
color: #55a532;
}
.markdown-body .pl-mdr {
color: #795da3;
font-weight: bold;
}
.markdown-body .pl-mo {
color: #1d3e81;
}
.markdown-body kbd {
display: inline-block;
padding: 3px 5px;
font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.markdown-body .plan-price-unit {
color: #767676;
font-weight: normal;
}
.markdown-body .task-list-item {
list-style-type: none;
}
.markdown-body .task-list-item+.task-list-item {
margin-top: 3px;
}
.markdown-body .task-list-item input {
margin: 0 0.35em 0.25em -1.6em;
vertical-align: middle;
}
.markdown-body .plan-choice {
padding: 15px;
padding-left: 40px;
display: block;
border: 1px solid #e0e0e0;
position: relative;
font-weight: normal;
background-color: #fafafa;
}
.markdown-body .plan-choice.open {
background-color: #fff;
}
.markdown-body .plan-choice.open .plan-choice-seat-breakdown {
display: block;
}
.markdown-body .plan-choice-free {
border-radius: 3px 3px 0 0;
}
.markdown-body .plan-choice-paid {
border-radius: 0 0 3px 3px;
border-top: 0;
margin-bottom: 20px;
}
.markdown-body .plan-choice-radio {
position: absolute;
left: 15px;
top: 18px;
}
.markdown-body .plan-choice-exp {
color: #999;
font-size: 12px;
margin-top: 5px;
}
.markdown-body .plan-choice-seat-breakdown {
margin-top: 10px;
display: none;
}
.markdown-body :checked+.radio-label {
z-index: 1;
position: relative;
border-color: #4078c0;
}
</style><title>README</title></head><body><article class="markdown-body"><h1>
<a id="user-content-what-is-happening-in-this-gif-" class="anchor" href="#what-is-happening-in-this-gif-" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>What is happening in this gif ?</h1>
<p><strong>OpenCV</strong> is calculating <strong>Optical Flow</strong> from a video.<br>
Then <strong>Processing</strong> draws arrows showing the vector field.<br>
And a double <strong>Frame Buffer</strong> is applying texture coordinates displacement.</p>
<p><a href="https://floptic.tumblr.com"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/141.gif" alt="Gif Example" style="max-width:100%;"></a></p>
<p><a href="https://floptic.tumblr.com">You can find more gifs here</a></p>
<h1>
<a id="user-content-code-sources" class="anchor" href="#code-sources" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Code Sources</h1>
<p>If you are familiar with Processing you can check directly the <a href="///C://Users/Leon/Documents/OpticalFlowExample/FrameBufferAndOpticalFlow/FrameBufferAndOpticalFlow.pde">FrameBufferAndOpticalFlow.pde</a>.<br>
If not, I've made a little tutorial to explain all the layers behind the effect. </p>
<h1>
<a id="user-content-user-tool" class="anchor" href="#user-tool" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>User Tool</h1>
<p>I am working on a custom tool that can be used by non-coders.<br>
Meanwhile you have to know how to code to make the effect. </p>
<h1>
<a id="user-content-tutorial" class="anchor" href="#tutorial" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Tutorial</h1>
<h2>
<a id="user-content-setup-processing" class="anchor" href="#setup-processing" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Setup Processing</h2>
<p>Download and install <a href="https://processing.org/">Processing</a>.<br>
Start a new sketch and open Contribution Manager. </p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/p1.png" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/p1.png" alt="Open Contribution Manager" style="max-width:100%;"></a></p>
<p>Add librairy "OpenCV" by Greg Borenstein (<a href="https://github.com/atduskgreg/opencv-processing/">https://github.com/atduskgreg/opencv-processing/</a>). </p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/p2.png" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/p2.png" alt="Add OpenCV" style="max-width:100%;"></a></p>
<p>Add librairy "Video" (<a href="https://processing.org/reference/libraries/video/index.html">https://processing.org/reference/libraries/video/index.html</a>). </p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/p3.png" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/p3.png" alt="Add Video" style="max-width:100%;"></a></p>
<h2>
<a id="user-content-opencv-optical-flow-example" class="anchor" href="#opencv-optical-flow-example" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>OpenCV Optical Flow example</h2>
<p>You can check the full OpenCV for Processing code sources here :<br>
<a href="https://github.com/atduskgreg/opencv-processing">https://github.com/atduskgreg/opencv-processing</a></p>
<p>OpenCV for Processing reference :<br>
<a href="http://atduskgreg.github.io/opencv-processing/reference/">http://atduskgreg.github.io/opencv-processing/reference/</a></p>
<p>You can start looking at this example to get familiar with OpenCV :<br>
<a href="https://github.com/atduskgreg/opencv-processing/blob/master/examples/OpticalFlow/OpticalFlow.pde">https://github.com/atduskgreg/opencv-processing/blob/master/examples/OpticalFlow/OpticalFlow.pde</a></p>
<div class="highlight highlight-source-java"><pre><span class="pl-k">import</span> <span class="pl-smi">gab.opencv.*</span>;
<span class="pl-k">import</span> <span class="pl-smi">processing.video.*</span>;
<span class="pl-smi">OpenCV</span> opencv;
<span class="pl-smi">Movie</span> video;
<span class="pl-k">void</span> setup() {
size(<span class="pl-c1">1136</span>, <span class="pl-c1">320</span>);
video <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">Movie</span>(<span class="pl-v">this</span>, <span class="pl-s"><span class="pl-pds">"</span>sample1.mov<span class="pl-pds">"</span></span>);
opencv <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">OpenCV</span>(<span class="pl-v">this</span>, <span class="pl-c1">568</span>, <span class="pl-c1">320</span>);
video<span class="pl-k">.</span>loop();
video<span class="pl-k">.</span>play();
}
<span class="pl-k">void</span> draw() {
background(<span class="pl-c1">0</span>);
opencv<span class="pl-k">.</span>loadImage(video);
opencv<span class="pl-k">.</span>calculateOpticalFlow();
image(video, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>);
translate(video<span class="pl-k">.</span>width,<span class="pl-c1">0</span>);
stroke(<span class="pl-c1">255</span>,<span class="pl-c1">0</span>,<span class="pl-c1">0</span>);
opencv<span class="pl-k">.</span>drawOpticalFlow();
<span class="pl-smi">PVector</span> aveFlow <span class="pl-k">=</span> opencv<span class="pl-k">.</span>getAverageFlow();
<span class="pl-k">int</span> flowScale <span class="pl-k">=</span> <span class="pl-c1">50</span>;
stroke(<span class="pl-c1">255</span>);
strokeWeight(<span class="pl-c1">2</span>);
line(video<span class="pl-k">.</span>width<span class="pl-k">/</span><span class="pl-c1">2</span>, video<span class="pl-k">.</span>height<span class="pl-k">/</span><span class="pl-c1">2</span>, video<span class="pl-k">.</span>width<span class="pl-k">/</span><span class="pl-c1">2</span> <span class="pl-k">+</span> aveFlow<span class="pl-k">.</span>x<span class="pl-k">*</span>flowScale, video<span class="pl-k">.</span>height<span class="pl-k">/</span><span class="pl-c1">2</span> <span class="pl-k">+</span> aveFlow<span class="pl-k">.</span>y<span class="pl-k">*</span>flowScale);
}
<span class="pl-k">void</span> movieEvent(<span class="pl-smi">Movie</span> m) {
m<span class="pl-k">.</span>read();
}</pre></div>
<h2>
<a id="user-content-frame-buffer-with-processing" class="anchor" href="#frame-buffer-with-processing" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Frame Buffer with Processing</h2>
<p>What I call frame buffer is a render texture. All draw calls are drawn to a texture.<br>
The idea is to apply a persistent effect with shaders, and it implies that we have to read and write on the same texture. And that is not possible because of how hardware process memory.<br>
The solution is to have a double frame buffer, one for reading and another one for writing. </p>
<p>An example of a custom displacement : </p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/44.gif" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/44.gif" alt="Frame Buffer Example" style="max-width:100%;"></a></p>
<p>This code shows how to setup and use a double frame buffer with Processing : </p>
<div class="highlight highlight-source-java"><pre><span class="pl-c">// frame buffer</span>
<span class="pl-k">PGraphics</span>[] renderArray;
<span class="pl-k">int</span> currentRender;
<span class="pl-c">// get the current frame buffer</span>
<span class="pl-smi">PGraphics</span> getCurrentRender () {
<span class="pl-k">return</span> renderArray[currentRender];
}
<span class="pl-c">// swap between writing frame and reading frame</span>
<span class="pl-k">void</span> nextRender () {
currentRender <span class="pl-k">=</span> (currentRender <span class="pl-k">+</span> <span class="pl-c1">1</span>) <span class="pl-k">%</span> renderArray<span class="pl-k">.</span>length;
}
<span class="pl-k">void</span> setup ()
{
size(<span class="pl-c1">300</span>, <span class="pl-c1">300</span>, <span class="pl-c1">P3D</span>);
<span class="pl-c">// create a double frame buffer</span>
renderArray <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">PGraphics</span>[<span class="pl-c1">2</span>];
currentRender <span class="pl-k">=</span> <span class="pl-c1">0</span>;
<span class="pl-k">for</span> (<span class="pl-k">int</span> i <span class="pl-k">=</span> <span class="pl-c1">0</span>; i <span class="pl-k"><</span> renderArray<span class="pl-k">.</span>length; <span class="pl-k">++</span>i)
{
<span class="pl-c">// PGraphics is like a render texture</span>
renderArray[i] <span class="pl-k">=</span> createGraphics(width, height, <span class="pl-c1">P3D</span>);
renderArray[i]<span class="pl-k">.</span>beginDraw();
renderArray[i]<span class="pl-k">.</span>background(<span class="pl-c1">0</span>);
renderArray[i]<span class="pl-k">.</span>endDraw();
}
}
<span class="pl-k">void</span> draw ()
{
<span class="pl-c">// the frame buffer magic happen here</span>
<span class="pl-smi">PGraphics</span> bufferWrite <span class="pl-k">=</span> getCurrentRender();
nextRender();
<span class="pl-smi">PGraphics</span> bufferRead <span class="pl-k">=</span> getCurrentRender();
<span class="pl-c">// start recording render texture</span>
bufferWrite<span class="pl-k">.</span>beginDraw();
<span class="pl-c">// draw something using the PGraphics</span>
bufferWrite<span class="pl-k">.</span>shader([<span class="pl-c1">...</span>])
bufferWrite<span class="pl-k">.</span>image([<span class="pl-c1">...</span>])
<span class="pl-c">// end of recording render texture</span>
bufferWrite<span class="pl-k">.</span>endDraw();
<span class="pl-c">// draw final image</span>
image(bufferWrite);
}</pre></div>
<h2>
<a id="user-content-glsl-shader" class="anchor" href="#glsl-shader" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>GLSL Shader</h2>
<p>To apply displacement on frame buffer, we can use shaders.<br>
It is great because we are using GPU to calculate all the displacement. </p>
<p>This is pixel shader, also called fragment shader.<br>
It will return the color for a given pixel coordinate. </p>
<div class="highlight highlight-source-java"><pre><span class="pl-c">// textures send from Processing main script</span>
uniform sampler2D motion;
uniform sampler2D frame;
<span class="pl-c">// interpolated values from vertex shader</span>
varying vec4 vertColor;
varying vec4 vertTexCoord;
<span class="pl-k">void</span> main()
{
<span class="pl-c">// get motion and video colors</span>
vec4 motionColor <span class="pl-k">=</span> texture2D(motion, vertTexCoord<span class="pl-k">.</span>st);
<span class="pl-c">// fix uv inversion</span>
vec2 uv <span class="pl-k">=</span> vertTexCoord<span class="pl-k">.</span>st;
uv<span class="pl-k">.</span>y <span class="pl-k">=</span> <span class="pl-c1">1.0</span> <span class="pl-k">-</span> uv<span class="pl-k">.</span>y;
<span class="pl-c">// extract angle from color</span>
<span class="pl-k">float</span> angle <span class="pl-k">=</span> atan(motionColor<span class="pl-k">.</span>g <span class="pl-k">*</span> <span class="pl-c1">2.0</span> <span class="pl-k">-</span> <span class="pl-c1">1.0</span>, motionColor<span class="pl-k">.</span>r <span class="pl-k">*</span> <span class="pl-c1">2.0</span> <span class="pl-k">-</span> <span class="pl-c1">1.0</span>);
<span class="pl-c">// create offset with angle and vector magnitude</span>
vec2 offset <span class="pl-k">=</span> vec2(cos(angle), sin(angle)) <span class="pl-k">*</span> motionColor<span class="pl-k">.</span>b <span class="pl-k">*</span> <span class="pl-c1">0.01</span>;
<span class="pl-c">// apply uv displacement</span>
vec4 framebufferColor <span class="pl-k">=</span> texture2D(frame, uv <span class="pl-k">-</span> offset);
<span class="pl-c">// assign color</span>
gl_FragColor <span class="pl-k">=</span> framebufferColor;
}</pre></div>
<p>We get the angle and the length of the vector from the color.<br>
This information is encoded from CPU like this : </p>
<div class="highlight highlight-source-java"><pre>motionTexture<span class="pl-k">.</span>pixels[index] <span class="pl-k">=</span> color(direction<span class="pl-k">.</span>x <span class="pl-k">*</span> <span class="pl-c1">0.5</span> <span class="pl-k">+</span> <span class="pl-c1">0.5</span>, direction<span class="pl-k">.</span>y <span class="pl-k">*</span> <span class="pl-c1">0.5</span> <span class="pl-k">+</span> <span class="pl-c1">0.5</span>, min(<span class="pl-c1">1</span>, motion<span class="pl-k">.</span>mag()));</pre></div>
<p>Vector direction is normalized, we compress his range from [-1, 1] to [0, 1] so the color dont get negative value.<br>
So red is x, green is y and blue is the vector magnitude. </p>
<p>Then we extract the angle from the red and green color : </p>
<div class="highlight highlight-source-java"><pre>atan(motionColor<span class="pl-k">.</span>g <span class="pl-k">*</span> <span class="pl-c1">2.0</span> <span class="pl-k">-</span> <span class="pl-c1">1.0</span>, motionColor<span class="pl-k">.</span>r <span class="pl-k">*</span> <span class="pl-c1">2.0</span> <span class="pl-k">-</span> <span class="pl-c1">1.0</span>);</pre></div>
<h2>
<a id="user-content-voila" class="anchor" href="#voila" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Voila</h2>
<p>With this, you can make a lot of thing.<br>
You can start from the code sources provided and add your own layers of effects. </p>
<p>This is what the example does :</p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/149b.gif" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/149b.gif" alt="Voila" style="max-width:100%;"></a></p>
<p>Press Space to toggle frame buffer effect :</p>
<p><a href="///C://Users/Leon/Documents/OpticalFlowExample/images/150.gif" target="_blank"><img src="///C://Users/Leon/Documents/OpticalFlowExample/images/150.gif" alt="Voila" style="max-width:100%;"></a></p>
<p>If you do anything cool with is, I would love to know.<br>
You can contact me on twitter here : <a href="https://www.twitter.com/leondenise">@leondenise</a>.<br>
And please share your code like everyone else in this open source community. <3 </p>
</article></body></html>