-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontinuos_local master.html
134 lines (119 loc) · 4 KB
/
continuos_local master.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Threat Detection Stream</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
#video-container {
position: relative;
width: 640px;
height: 480px;
margin-bottom: 20px;
background-color: #000;
overflow: hidden;
}
#video-frame {
width: 100%;
height: 100%;
object-fit: cover;
}
#alert-banner {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 10px;
background-color: rgba(255, 0, 0, 0.7);
color: #fff;
text-align: center;
font-weight: bold;
display: none;
}
#threat-info {
position: absolute;
top: 0;
left: 0;
width: 100%;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
text-align: center;
font-weight: bold;
display: none;
}
button {
padding: 10px 20px;
font-size: 16px;
border: none;
background-color: #007bff;
color: #fff;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div id="video-container">
<img id="video-frame" alt="Video Stream" src="" />
<div id="alert-banner">Threat Detected!</div>
<div id="threat-info"></div>
</div>
<button id="acknowledge-button" onclick="acknowledgeThreat()">Acknowledge Threat</button>
<script>
const socket = new WebSocket('ws://localhost:8765/local_master');
const videoFrame = document.getElementById('video-frame');
const alertBanner = document.getElementById('alert-banner');
const threatInfo = document.getElementById('threat-info');
const acknowledgeButton = document.getElementById('acknowledge-button');
let currentThreat = null;
socket.onmessage = function (event) {
const data = JSON.parse(event.data);
// Update video frame
videoFrame.src = 'data:image/jpeg;base64,' + data.frame;
// Check for alerts
if (data.detections.length > 0) {
// Show the alert banner
alertBanner.style.display = 'block';
playAlarmSound();
// Update threat info
let threatText = 'Detected Threats:\n';
data.detections.forEach(detection => {
threatText += `${detection.class} ${detection.confidence.toFixed(2)}\n`;
});
threatInfo.textContent = threatText;
threatInfo.style.display = 'block';
// Set current threat
currentThreat = data.detections[0].class; // or you can choose a different approach to handle multiple threats
}
};
function playAlarmSound() {
const audio = new Audio('alarm.mp3'); // Path to your alarm sound file
audio.play();
}
function acknowledgeThreat() {
if (currentThreat) {
alertBanner.style.display = 'none';
threatInfo.style.display = 'none';
socket.send(JSON.stringify({ acknowledge: true, threat: currentThreat }));
currentThreat = null; // Clear current threat
}
}
</script>
</body>
</html>