-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayground.html
More file actions
1699 lines (1498 loc) · 70 KB
/
playground.html
File metadata and controls
1699 lines (1498 loc) · 70 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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GlyphMotion Playground - Experimental AI</title>
<meta name="description" content="Experiment with real-time AI in the browser and advanced server-side tracking configurations.">
<link rel="icon" type="image/x-icon" href="images/project-glyph-motion.ico">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Press+Start+2P&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<!-- TensorFlow.js and COCO-SSD for Neural Cam -->
<!-- Force high-performance GPU (discrete GPU like RTX 3050) -->
<script>
// Set WebGL flags BEFORE loading TensorFlow.js to request discrete GPU
window.tf = window.tf || {};
window.tf.env = window.tf.env || {};
// Create a test canvas to detect GPU
const testCanvas = document.createElement('canvas');
const gl = testCanvas.getContext('webgl2', { powerPreference: 'high-performance' }) ||
testCanvas.getContext('webgl', { powerPreference: 'high-performance' });
if (gl) {
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
if (debugInfo) {
window.detectedGPU = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
console.log('[GPU Detected]', window.detectedGPU);
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd"></script>
<style>
* { box-sizing: border-box; }
body {
font-family: 'Inter', sans-serif;
background-color: #0B0A0F;
color: #EDEDF3;
min-height: 100vh;
display: flex;
flex-direction: column;
padding: 0;
margin: 0;
overflow-x: hidden;
}
.background-glow-container {
position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -10; pointer-events: none; overflow: hidden;
}
.glow-element {
position: absolute; border-radius: 50%; opacity: 0.15; mix-blend-mode: screen; filter: blur(120px);
}
.glow-1 { width: 800px; height: 800px; background: radial-gradient(circle, #FDA136 0%, transparent 70%); top: -200px; left: -200px; }
.glow-2 { width: 600px; height: 600px; background: radial-gradient(circle, #FF5733 0%, transparent 70%); bottom: -150px; right: -150px; }
.glow-3 { width: 500px; height: 500px; background: radial-gradient(circle, #8B5CF6 0%, transparent 70%); top: 50%; left: 50%; transform: translate(-50%, -50%); }
/* Full width layout */
.main-container {
width: 100%;
max-width: 100%;
padding: 1rem 2rem;
flex: 1;
}
@media (min-width: 1400px) {
.main-container { padding: 1.5rem 4rem; }
}
.content-card {
background-color: rgba(10, 10, 15, 0.8);
border: 1px solid rgba(253, 161, 54, 0.2);
border-radius: 1rem;
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
width: 100%;
padding: 1.5rem;
margin-bottom: 1.5rem;
backdrop-filter: blur(12px);
}
.page-title {
font-family: 'Press Start 2P', cursive;
font-weight: normal;
background: linear-gradient(to right, #FDA136, #FFD700);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 2px 3px rgba(0,0,0,0.3);
text-align: center;
font-size: clamp(1.1rem, 3vw, 2rem);
line-height: 1.4;
}
.page-subtitle {
color: rgba(255, 255, 255, 0.6);
font-size: 1rem;
margin-top: 0.75rem;
font-weight: 300;
}
.section-title {
font-family: 'Inter', sans-serif;
font-weight: 700;
color: #FDA136;
margin-bottom: 1rem;
border-bottom: 1px solid rgba(253, 161, 54, 0.3);
padding-bottom: 0.5rem;
font-size: 1.1rem;
}
.btn {
background: linear-gradient(135deg, #EA580C, #D97706);
color: white;
padding: 0.6rem 1.25rem;
border-radius: 0.5rem;
font-weight: 600;
transition: all 0.3s ease;
border: none;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(234, 88, 12, 0.4); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.15); }
.btn-danger {
background: linear-gradient(135deg, #DC2626, #B91C1C);
}
.btn-danger:hover { box-shadow: 0 4px 15px rgba(220, 38, 38, 0.4); }
.btn-success {
background: linear-gradient(135deg, #059669, #047857);
}
/* Back Button - Below title */
.back-btn {
display: inline-flex;
align-items: center;
gap: 0.5rem;
background: rgba(10, 10, 15, 0.9);
border: 1px solid rgba(253, 161, 54, 0.3);
padding: 0.5rem 1.25rem;
border-radius: 2rem;
color: #FDA136;
font-size: 0.85rem;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
text-decoration: none;
margin-top: 1rem;
}
.back-btn:hover {
background: rgba(253, 161, 54, 0.1);
transform: translateY(-2px);
}
/* Neural Cam Styles */
#camContainer {
position: relative;
width: 100%;
max-width: var(--cam-max-width, 900px);
margin: 0 auto;
border-radius: 1rem;
overflow: hidden;
background: #111;
box-shadow: 0 0 30px rgba(253, 161, 54, 0.15);
aspect-ratio: var(--cam-aspect-ratio, 16/9);
transition: max-width 0.3s ease, aspect-ratio 0.3s ease;
}
/* Portrait mode container */
#camContainer.portrait-mode {
max-width: min(var(--cam-max-width, 400px), 90vw);
aspect-ratio: 9/16;
}
/* Mobile optimizations */
@media (max-width: 768px) {
#camContainer {
border-radius: 0.5rem;
max-width: 100% !important;
}
#camContainer.portrait-mode {
max-width: 85vw !important;
}
.size-control {
display: none; /* Hide size control on mobile */
}
}
/* Mobile disclaimer */
.mobile-disclaimer {
display: none;
background: rgba(251, 191, 36, 0.15);
border: 1px solid rgba(251, 191, 36, 0.3);
border-radius: 0.5rem;
padding: 0.75rem 1rem;
margin-bottom: 1rem;
font-size: 0.8rem;
color: #fbbf24;
}
.mobile-disclaimer i { margin-right: 0.5rem; }
@media (max-width: 768px) {
.mobile-disclaimer { display: block; }
}
/* Fullscreen landscape mode */
.fullscreen-landscape {
position: fixed !important;
top: 0 !important;
left: 0 !important;
width: 100vw !important;
height: 100vh !important;
max-width: 100vw !important;
z-index: 9999 !important;
background: #000 !important;
border-radius: 0 !important;
margin: 0 !important;
}
.fullscreen-landscape video#webcam,
.fullscreen-landscape canvas#overlay {
object-fit: contain !important;
}
.fullscreen-controls {
position: fixed;
bottom: 1rem;
left: 50%;
transform: translateX(-50%);
z-index: 10000;
display: flex;
gap: 0.75rem;
background: rgba(0, 0, 0, 0.8);
padding: 0.75rem 1.5rem;
border-radius: 2rem;
backdrop-filter: blur(10px);
}
.fullscreen-controls.hidden { display: none; }
/* Mobile camera buttons */
.mobile-cam-buttons {
display: none;
flex-wrap: wrap;
gap: 0.5rem;
justify-content: center;
margin-top: 0.75rem;
}
@media (max-width: 768px) {
.mobile-cam-buttons { display: flex; }
}
.cam-mode-btn {
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-size: 0.8rem;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.05);
color: #fff;
cursor: pointer;
transition: all 0.2s ease;
}
.cam-mode-btn:hover, .cam-mode-btn.active {
background: rgba(253, 161, 54, 0.2);
border-color: #FDA136;
color: #FDA136;
}
/* Size control */
.size-control {
display: flex;
align-items: center;
gap: 0.75rem;
justify-content: center;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.size-btn {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.15);
color: #fff;
padding: 0.4rem 0.8rem;
border-radius: 0.4rem;
font-size: 0.75rem;
cursor: pointer;
transition: all 0.2s ease;
}
.size-btn:hover { background: rgba(255, 255, 255, 0.1); }
.size-btn.active {
background: rgba(253, 161, 54, 0.2);
border-color: #FDA136;
color: #FDA136;
}
.size-label {
font-size: 0.75rem;
color: rgba(255, 255, 255, 0.5);
}
video#webcam {
width: 100%;
height: 100%;
object-fit: cover;
transform: var(--video-mirror, scaleX(-1)); /* Mirror for selfie cam, controllable */
}
canvas#overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
transform: var(--video-mirror, scaleX(-1)); /* Mirror to match video */
}
/* No mirror for rear camera or portrait */
#camContainer.no-mirror video#webcam,
#camContainer.no-mirror canvas#overlay {
transform: none;
}
.cam-controls {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
justify-content: center;
margin-top: 1rem;
}
.cam-stats {
display: flex;
justify-content: center;
gap: 1.5rem;
margin-top: 0.75rem;
font-family: 'JetBrains Mono', monospace;
font-size: 0.8rem;
flex-wrap: wrap;
}
.stat-item {
background: rgba(253, 161, 54, 0.1);
padding: 0.4rem 0.8rem;
border-radius: 0.5rem;
border: 1px solid rgba(253, 161, 54, 0.2);
}
.stat-value { color: #FDA136; font-weight: 600; }
/* Recording indicator */
.recording-indicator {
position: absolute;
top: 1rem;
right: 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
background: rgba(220, 38, 38, 0.9);
padding: 0.4rem 0.8rem;
border-radius: 2rem;
font-size: 0.75rem;
font-weight: 600;
animation: pulse 1.5s ease-in-out infinite;
}
.recording-dot {
width: 8px;
height: 8px;
background: white;
border-radius: 50%;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
/* Camera selector */
.camera-select {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.15);
color: #fff;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-size: 0.85rem;
cursor: pointer;
min-width: 150px;
max-width: 200px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.camera-select:focus { outline: none; border-color: #FDA136; }
.camera-select option {
background: #1a1a1a;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
}
/* Hide camera select on mobile (use switch button) */
@media (max-width: 768px) {
.camera-select {
display: none;
}
}
/* Studio Form Styles */
.glass-input {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: #fff;
padding: 0.75rem;
border-radius: 0.5rem;
width: 100%;
transition: all 0.3s ease;
}
.glass-input:focus { outline: none; border-color: #FDA136; background: rgba(255, 255, 255, 0.08); }
.glass-input::placeholder { color: rgba(255, 255, 255, 0.4); }
/* Custom File Input */
.file-input-wrapper {
position: relative;
overflow: visible;
display: block;
width: 100%;
margin-top: 0;
}
.file-input-wrapper input[type="file"] {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
z-index: 2;
}
.file-input-display {
display: flex;
align-items: center;
gap: 0.75rem;
background: rgba(255, 255, 255, 0.05);
border: 1px dashed rgba(253, 161, 54, 0.4);
color: #fff;
padding: 0.875rem 1rem;
border-radius: 0.5rem;
width: 100%;
transition: all 0.3s ease;
cursor: pointer;
min-height: 70px;
}
.file-input-display:hover {
border-color: #FDA136;
background: rgba(253, 161, 54, 0.05);
}
.file-input-display i {
font-size: 1.5rem;
color: #FDA136;
}
.file-input-text {
flex: 1;
}
.file-input-text .title { font-weight: 500; }
.file-input-text .subtitle { font-size: 0.75rem; color: rgba(255, 255, 255, 0.5); margin-top: 0.25rem; }
.file-name { font-size: 0.85rem; color: #34D399; margin-top: 0.5rem; }
.checkbox-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
gap: 0.5rem;
max-height: 220px;
overflow-y: auto;
padding: 0.75rem;
background: rgba(0,0,0,0.3);
border-radius: 0.5rem;
border: 1px solid rgba(255, 255, 255, 0.05);
}
.checkbox-grid::-webkit-scrollbar { width: 6px; }
.checkbox-grid::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 3px; }
.checkbox-grid::-webkit-scrollbar-thumb { background: rgba(253, 161, 54, 0.3); border-radius: 3px; }
.checkbox-item {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.8rem;
padding: 0.3rem 0.5rem;
border-radius: 0.25rem;
transition: background 0.2s ease;
}
.checkbox-item:hover { background: rgba(255, 255, 255, 0.05); }
.checkbox-item input {
accent-color: #FDA136;
width: 16px;
height: 16px;
cursor: pointer;
}
.checkbox-item span { cursor: pointer; }
/* Slider Styling */
input[type="range"] {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
background: linear-gradient(135deg, #FDA136, #FF6B35);
border-radius: 50%;
cursor: pointer;
box-shadow: 0 2px 6px rgba(253, 161, 54, 0.4);
transition: transform 0.2s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.1);
}
/* Loading Spinner */
.spinner {
border: 3px solid rgba(255, 255, 255, 0.1);
border-left-color: #FDA136;
border-radius: 50%;
width: 24px;
height: 24px;
animation: spin 0.8s linear infinite;
display: inline-block;
}
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
/* Grid Layout for Studio */
.studio-grid {
display: grid;
grid-template-columns: 1fr;
gap: 1.5rem;
}
@media (min-width: 1024px) {
.studio-grid { grid-template-columns: 1fr 1fr; }
}
/* Status Message */
.status-msg {
padding: 1rem;
border-radius: 0.5rem;
text-align: center;
font-size: 0.9rem;
margin-top: 1rem;
}
.status-msg.info { background: rgba(253, 161, 54, 0.1); border: 1px solid rgba(253, 161, 54, 0.3); color: #FED7AA; }
.status-msg.success { background: rgba(52, 211, 153, 0.1); border: 1px solid rgba(52, 211, 153, 0.3); color: #A7F3D0; }
.status-msg.error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #FCA5A5; }
/* Footer */
.footer {
text-align: center;
padding: 1rem;
color: rgba(255, 255, 255, 0.4);
font-size: 0.8rem;
}
.footer a { color: #FDA136; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="background-glow-container">
<div class="glow-element glow-1"></div>
<div class="glow-element glow-2"></div>
<div class="glow-element glow-3"></div>
</div>
<div class="main-container">
<!-- Header -->
<header class="text-center py-8 mb-6">
<h1 class="page-title">Project GlyphMotion</h1>
<h2 class="page-title" style="font-size: clamp(0.7rem, 2vw, 1.2rem); margin-top: 0.5rem;">AI Playground</h2>
<p class="page-subtitle">Experimental AI features & advanced tracking configurations</p>
<a href="index.html" class="back-btn">
<i class="fas fa-arrow-left"></i> Back to Home
</a>
</header>
<!-- Neural Cam Section -->
<div class="content-card">
<h2 class="section-title"><i class="fas fa-brain mr-2"></i>Neural Cam — Real-time Browser AI</h2>
<p class="text-slate-400 mb-4 text-sm">Object detection runs entirely in your browser using TensorFlow.js. Zero data leaves your device.</p>
<div id="setupPanel" class="text-center py-8">
<button id="startCamBtn" class="btn text-lg px-6 py-3">
<i class="fas fa-video"></i> Start Neural Cam
</button>
<p id="camStatus" class="mt-4 text-sm text-slate-500"></p>
</div>
<div id="camWrapper" class="hidden">
<!-- Size Control -->
<div class="size-control">
<span class="size-label"><i class="fas fa-expand-arrows-alt"></i> View Size:</span>
<button class="size-btn" data-size="640">Small</button>
<button class="size-btn" data-size="900">Medium</button>
<button class="size-btn active" data-size="1200">Large</button>
<button class="size-btn" data-size="1600">XL</button>
<button class="size-btn" data-size="100%">Full</button>
</div>
<!-- Mobile Disclaimer -->
<div class="mobile-disclaimer">
<i class="fas fa-exclamation-triangle"></i>
<strong>Note:</strong> Live AI detection may have reduced accuracy on mobile devices. For best results, use desktop or server-side processing.
</div>
<div id="camContainer">
<video id="webcam" autoplay playsinline muted></video>
<canvas id="overlay"></canvas>
<div id="recordingIndicator" class="recording-indicator hidden">
<div class="recording-dot"></div>
<span>REC</span>
<span id="recordingTime">00:00</span>
</div>
</div>
<!-- Fullscreen controls (shown when in fullscreen mode) -->
<div id="fullscreenControls" class="fullscreen-controls hidden">
<button id="fsRecordBtn" class="btn btn-secondary">
<i class="fas fa-circle text-red-500"></i>
</button>
<button id="fsSwitchCamBtn" class="btn btn-secondary">
<i class="fas fa-sync-alt"></i>
</button>
<button id="fsExitBtn" class="btn btn-danger">
<i class="fas fa-compress"></i> Exit
</button>
</div>
<div class="cam-stats">
<div class="stat-item">FPS: <span id="fpsValue" class="stat-value">--</span></div>
<div class="stat-item">Objects: <span id="objectCount" class="stat-value">0</span></div>
<div class="stat-item">Inference: <span id="inferenceTime" class="stat-value">--</span>ms</div>
<div class="stat-item">Res: <span id="resValue" class="stat-value">--</span></div>
<div class="stat-item" id="gpuStatItem" style="cursor:pointer;" title="Click for GPU info">
GPU: <span id="tfBackend" class="stat-value">--</span>
</div>
</div>
<div class="cam-controls">
<!-- Camera Selection (Desktop) -->
<select id="cameraSelect" class="camera-select">
<option value="">Select Camera...</option>
</select>
<!-- Mobile Camera Switch -->
<button id="switchCameraBtn" class="btn btn-secondary hidden">
<i class="fas fa-sync-alt"></i> Use Rear
</button>
<!-- Recording Controls -->
<button id="recordBtn" class="btn btn-secondary">
<i class="fas fa-circle text-red-500"></i> Record
</button>
<button id="stopRecordBtn" class="btn btn-danger hidden">
<i class="fas fa-stop"></i> Stop & Download
</button>
<!-- Stop Camera -->
<button id="stopCamBtn" class="btn btn-secondary">
<i class="fas fa-power-off"></i> Stop
</button>
</div>
<!-- Mobile-only buttons -->
<div class="mobile-cam-buttons">
<button id="rearCamBtn" class="cam-mode-btn active">
<i class="fas fa-camera"></i> Rear
</button>
<button id="selfieCamBtn" class="cam-mode-btn">
<i class="fas fa-user"></i> Selfie
</button>
<button id="portraitModeBtn" class="cam-mode-btn">
<i class="fas fa-mobile-alt"></i> Portrait
</button>
<button id="landscapeModeBtn" class="cam-mode-btn active">
<i class="fas fa-tv"></i> Landscape
</button>
<button id="fullscreenBtn" class="cam-mode-btn">
<i class="fas fa-expand"></i> Fullscreen
</button>
</div>
</div>
</div>
<!-- Server Studio Section -->
<div class="content-card">
<h2 class="section-title"><i class="fas fa-sliders-h mr-2"></i>Tracker Studio — Server-Side Processing</h2>
<p class="text-slate-400 mb-6 text-sm">Process videos with YOLOv8 on our server. Customize class filters and detection sensitivity.</p>
<form id="studioForm">
<div class="studio-grid">
<!-- Left Column: Video Input -->
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-slate-300 mb-2">Video URL</label>
<input type="text" id="videoUrl" name="video_url" class="glass-input" placeholder="https://example.com/video.mp4">
</div>
<div class="text-center text-xs text-slate-500 py-2">— OR —</div>
<div>
<label class="block text-sm font-medium text-slate-300 mb-2">Upload Video</label>
<div class="file-input-wrapper">
<div class="file-input-display" id="fileInputDisplay">
<i class="fas fa-cloud-upload-alt"></i>
<div class="file-input-text">
<div class="title">Click to choose a file</div>
<div class="subtitle">MP4, MOV, AVI, WebM (Max 500MB)</div>
</div>
</div>
<input type="file" id="videoFile" name="video_file" accept="video/*">
</div>
<div id="fileName" class="file-name hidden"></div>
</div>
<!-- Confidence Slider -->
<div class="pt-2">
<label class="block text-sm font-medium text-slate-300 mb-3">
Confidence Threshold: <span id="confValue" class="text-orange-400 font-bold">0.25</span>
</label>
<input type="range" id="confSlider" name="confidence_threshold" min="0.1" max="0.9" step="0.05" value="0.25">
<div class="flex justify-between text-xs text-slate-500 mt-1">
<span>More Detections</span>
<span>Higher Accuracy</span>
</div>
</div>
</div>
<!-- Right Column: Class Selection -->
<div>
<div class="flex justify-between items-center mb-2">
<label class="block text-sm font-medium text-slate-300">Objects to Track</label>
<div class="space-x-3 text-xs">
<button type="button" id="selectAllBtn" class="text-orange-400 hover:text-orange-300 transition">Select All</button>
<span class="text-slate-600">|</span>
<button type="button" id="clearAllBtn" class="text-slate-400 hover:text-slate-300 transition">Clear All</button>
</div>
</div>
<div id="classGrid" class="checkbox-grid"></div>
<p class="text-xs text-slate-500 mt-2"><span id="selectedCount">80</span> classes selected</p>
</div>
</div>
<!-- Submit -->
<div class="text-center pt-6">
<button type="submit" id="processBtn" class="btn text-lg px-8 py-3">
<i class="fas fa-rocket"></i> Process Video
</button>
</div>
<div id="statusMessage" class="status-msg info hidden"></div>
</form>
</div>
</div>
<footer class="footer">
Made with ❤️ by Sayan & Shitij | <a href="index.html">Return to Dashboard</a>
</footer>
<script>
// --- COCO Classes ---
const COCO_CLASSES = [
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",
"fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow",
"elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
"skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch",
"potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard",
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase",
"scissors", "teddy bear", "hair drier", "toothbrush"
];
// --- Device Detection ---
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
// --- NEURAL CAM LOGIC ---
const video = document.getElementById('webcam');
const canvas = document.getElementById('overlay');
const ctx = canvas.getContext('2d');
const startCamBtn = document.getElementById('startCamBtn');
const stopCamBtn = document.getElementById('stopCamBtn');
const camWrapper = document.getElementById('camWrapper');
const setupPanel = document.getElementById('setupPanel');
const camStatus = document.getElementById('camStatus');
const fpsValue = document.getElementById('fpsValue');
const objectCount = document.getElementById('objectCount');
const inferenceTime = document.getElementById('inferenceTime');
const cameraSelect = document.getElementById('cameraSelect');
const switchCameraBtn = document.getElementById('switchCameraBtn');
const recordBtn = document.getElementById('recordBtn');
const stopRecordBtn = document.getElementById('stopRecordBtn');
const recordingIndicator = document.getElementById('recordingIndicator');
const recordingTimeEl = document.getElementById('recordingTime');
let model = null;
let isCamRunning = false;
let currentStream = null;
let currentFacingMode = 'environment'; // 'user' or 'environment'
let availableCameras = [];
let selectedDeviceId = null;
// Smoothing for bounding boxes
let smoothedPredictions = {};
const SMOOTHING_FACTOR = 0.15; // Lower = smoother but more lag (was 0.25)
const MIN_CONFIDENCE = 0.50; // Minimum confidence to display (was 0.45)
const PERSISTENCE_FRAMES = 12; // Frames to keep showing a lost detection (was 8)
const POSITION_TOLERANCE = 100; // Pixels tolerance for matching detections (was 80)
// Recording variables
let mediaRecorder = null;
let recordedChunks = [];
let isRecording = false;
let recordingStartTime = null;
let recordingInterval = null;
// FPS calculation
let frameCount = 0;
let lastFpsTime = performance.now();
let currentFps = 0;
async function loadModel() {
camStatus.innerHTML = '<div class="spinner"></div> Initializing TensorFlow.js...';
startCamBtn.disabled = true;
try {
// Use WebGL only - WebGPU is unstable on Linux/NVIDIA
// Set WebGL optimizations
tf.env().set('WEBGL_FORCE_F16_TEXTURES', false);
tf.env().set('WEBGL_VERSION', 2);
tf.env().set('WEBGL_CPU_FORWARD', false);
tf.env().set('WEBGL_PACK', true);
await tf.setBackend('webgl');
await tf.ready();
const backend = tf.getBackend();
// Get actual GPU name
let gpuName = backend.toUpperCase();
if (window.detectedGPU) {
gpuName = window.detectedGPU
.replace('ANGLE (', '')
.replace(')', '')
.replace('Direct3D11 vs_5_0 ps_5_0', '')
.replace('NVIDIA ', '')
.replace('GeForce ', '')
.replace(', or similar', '')
.replace('Mesa Intel', 'Intel')
.replace('Mesa ', '')
.trim();
if (gpuName.length > 18) gpuName = gpuName.substring(0, 16) + '...';
}
document.getElementById('tfBackend').textContent = gpuName;
document.getElementById('tfBackend').title = `Backend: ${backend}\nGPU: ${window.detectedGPU || 'Unknown'}`;
console.log('[TF.js] Using backend:', backend, '| GPU:', window.detectedGPU);
camStatus.innerHTML = '<div class="spinner"></div> Loading AI Model...';
// Use lite model for faster loading and better stability
model = await cocoSsd.load({
base: 'lite_mobilenet_v2' // Lighter model = faster & more stable
});
camStatus.innerText = "Model loaded! Initializing camera...";
await enumerateCameras();
startWebcam();
} catch (err) {
camStatus.innerHTML = `<span class="text-red-400">Error: ${err.message}</span>`;
startCamBtn.disabled = false;
document.getElementById('tfBackend').textContent = 'ERROR';
console.error('[TF.js Error]', err);
}
}
async function enumerateCameras() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
let cameras = devices.filter(device => device.kind === 'videoinput');
// On mobile, filter to just front and back cameras
// AOSP typically uses: cam0 = rear, cam1 = front
if (isMobile && cameras.length >= 2) {
const mainCameras = [];
let rearCam = null;
let frontCam = null;
cameras.forEach((cam, idx) => {
const label = cam.label.toLowerCase();
// Check for rear camera - cam0 or back/rear in label
if (!rearCam && (label.includes('back') || label.includes('rear') ||
label.includes('environment') || label.includes('camera 0') ||
label.includes('cam0') || label.includes('0, facing back') || idx === 0)) {
rearCam = { ...cam, friendlyName: '📷 Rear Camera', isRear: true };
}
// Check for front camera - cam1 or front/selfie in label
else if (!frontCam && (label.includes('front') || label.includes('selfie') ||
label.includes('user') || label.includes('camera 1') ||
label.includes('cam1') || label.includes('facing front') || idx === 1)) {
frontCam = { ...cam, friendlyName: '🤳 Selfie Camera', isRear: false };
}
});
// Fallback: use first two cameras
if (!rearCam && cameras[0]) {
rearCam = { ...cameras[0], friendlyName: '📷 Rear Camera', isRear: true };
}
if (!frontCam && cameras[1]) {
frontCam = { ...cameras[1], friendlyName: '🤳 Selfie Camera', isRear: false };
}
if (rearCam) mainCameras.push(rearCam);
if (frontCam) mainCameras.push(frontCam);
cameras = mainCameras;
}
availableCameras = cameras;
cameraSelect.innerHTML = '<option value="">Select Camera...</option>';
availableCameras.forEach((camera, index) => {
const option = document.createElement('option');
option.value = camera.deviceId;
option.textContent = camera.friendlyName || camera.label || `Camera ${index + 1}`;
cameraSelect.appendChild(option);
});
// On mobile, hide dropdown (use our custom buttons)
if (isMobile) {
cameraSelect.classList.add('hidden');
switchCameraBtn.classList.add('hidden'); // We use the new buttons instead
}
} catch (err) {
console.error('Error enumerating cameras:', err);
}
}
async function startWebcam(deviceId = null) {
try {
// Stop existing stream
if (currentStream) {
currentStream.getTracks().forEach(track => track.stop());
}
// Use native/source resolution for best quality
const constraints = {
video: {
width: { ideal: 1920 },
height: { ideal: 1080 },
frameRate: { ideal: 30, max: 60 }
}
};
if (deviceId) {
constraints.video.deviceId = { exact: deviceId };
} else if (isMobile) {
constraints.video.facingMode = currentFacingMode;
}
currentStream = await navigator.mediaDevices.getUserMedia(constraints);
video.srcObject = currentStream;
video.onloadedmetadata = () => {
video.play();
setupPanel.classList.add('hidden');
camWrapper.classList.remove('hidden');
const vw = video.videoWidth;
const vh = video.videoHeight;
canvas.width = vw;
canvas.height = vh;
// Detect portrait mode (height > width)
const isPortrait = vh > vw;
const camContainer = document.getElementById('camContainer');
if (isPortrait) {
camContainer.classList.add('portrait-mode');
camContainer.classList.add('no-mirror'); // No mirror for portrait
} else {
camContainer.classList.remove('portrait-mode');
// Mirror only for front/selfie camera in landscape
if (currentFacingMode === 'user' ||
(currentStream.getVideoTracks()[0]?.label?.toLowerCase().includes('front'))) {