Skip to content

Commit d14cd39

Browse files
author
Paul Richards
committed
Add sample video support to Scoreboard OCR tool
1 parent c51f74d commit d14cd39

File tree

88 files changed

+44224
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+44224
-3
lines changed

04b-scoreboard-ocr/app.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ document.addEventListener('DOMContentLoaded', async function() {
5555
totalLatency: 0
5656
};
5757

58+
function setupVideoListeners() {
59+
video.addEventListener('loadedmetadata', () => {
60+
regionCanvas.width = video.videoWidth;
61+
regionCanvas.height = video.videoHeight;
62+
loadSavedRegions();
63+
drawAllRegions();
64+
updateStatus('Video ready - define OCR regions');
65+
});
66+
67+
video.addEventListener('play', () => {
68+
if (regionCanvas.width !== video.videoWidth) {
69+
regionCanvas.width = video.videoWidth;
70+
regionCanvas.height = video.videoHeight;
71+
drawAllRegions();
72+
}
73+
});
74+
}
75+
5876
async function initOCR() {
5977
ocrEngine = new OCREngine();
6078
ocrEngine.onStatusChange = (state, message) => {
@@ -425,8 +443,8 @@ document.addEventListener('DOMContentLoaded', async function() {
425443

426444
cameraSelect.addEventListener('change', () => {
427445
const deviceId = cameraSelect.value;
428-
if (deviceId) {
429-
startCamera(deviceId);
446+
if (deviceId && window.VideoSourceAdapter) {
447+
VideoSourceAdapter.switchToCamera();
430448
}
431449
});
432450

@@ -441,6 +459,17 @@ document.addEventListener('DOMContentLoaded', async function() {
441459
startExtractionBtn.addEventListener('click', startExtraction);
442460
stopExtractionBtn.addEventListener('click', stopExtraction);
443461

462+
setupVideoListeners();
444463
await initOCR();
445-
await startCamera();
464+
465+
if (window.VideoSourceAdapter) {
466+
VideoSourceAdapter.onSourceChange = (source) => {
467+
updateStatus(`Source: ${source === 'camera' ? 'Live Camera' : 'Sample Video'}`);
468+
setTimeout(() => {
469+
regionCanvas.width = video.videoWidth;
470+
regionCanvas.height = video.videoHeight;
471+
drawAllRegions();
472+
}, 500);
473+
};
474+
}
446475
});

04b-scoreboard-ocr/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ <h3>⚙️ Controls</h3>
551551
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
552552
<script src="ocr-engine.js"></script>
553553
<script src="score-parser.js"></script>
554+
<script src="../shared/video-source-adapter.js"></script>
554555
<script src="app.js"></script>
555556
<script src="../shared/ux-utils.js"></script>
556557
<script src="../shared/playground-header.js"></script>

Handbreak/Business Meeting.mp4

5.65 MB
Binary file not shown.

Handbreak/Eggs Moving.mp4

1.53 MB
Binary file not shown.
Binary file not shown.

Handbreak/Man Walking Sideways.mp4

3.23 MB
Binary file not shown.

Handbreak/Office Overhead.mp4

4.49 MB
Binary file not shown.

Handbreak/Scoreboard.mp4

405 KB
Binary file not shown.
3.17 MB
Binary file not shown.

Handbreak/Smiling.mp4

1.66 MB
Binary file not shown.

0 commit comments

Comments
 (0)