Create a Security System with Your Webcam: HTML Code & Motion Detection Tutorial

preview_player
Показать описание
Convert any Webcam into a Security System

Create a Security System with Your Webcam: HTML Code & Motion Detection Tutorial

Рекомендации по теме
Комментарии
Автор

Html code to control cam and relay:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
color: #333;
}
h1 {
color: #333;
}
.container {
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 60%;
max-width: 1000px;
text-align: center;
border: 1px solid #ccc;
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
transition: background-color 0.3s;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
#connectButton {
background-color: #007bff;
color: white;
}
#detectButton {
background-color: #ccc;
}
input[type="range"] {
width: 100%;
}
video, canvas {
margin: 10px;
border: 1px solid #ccc;
}
.status {
font-size: 18px;
margin: 5px 0;
}
#popup {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #ff0000;
color: #fff;
padding: 40px;
border-radius: 10px;
z-index: 1000;
text-align: center;
animation: blink 1.5s infinite;
}
#popup img {
width: 100px;
height: 100px;
}
#popup p {
font-size: 48px;
font-weight: bold;
text-transform: uppercase;
}
#popup button {
margin-top: 20px;
background-color: #007bff;
color: white;
padding: 10px 20px;
font-size: 16px;
}
@keyframes blink {
0% { opacity: 1; }
50% { opacity: 0; }
100% { opacity: 1; }
}
#log {
margin-top: 20px;
background: #fff;
border: 1px solid #ccc;
border-radius: 10px;
padding: 0px;
width: 100%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
#log table {
width: 100%;
border-collapse: collapse;
}
#log th, #log td {
border: 1px solid #ccc;
padding: 5px;
text-align: left;
}
#exportButton, #clearButton {
background-color: #007bff;
color: white;
}
footer {
margin-top: 20px;
}
a {
color: #007bff;
text-decoration: none;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<button
<br>
<input type="range" id="sensitivitySlider" min="0" max="100" value="50">
<div class="status">Sensibilidad: <span
<br>
<button id="detectButton" disabled>Activar Deteccion de Movimiento</button>
<br>
<video id="video" width="960" height="720" autoplay></video>
<canvas id="canvas" width="960" height="720"
<div id="popup">
<p>INTRUSO DETECTADO!</p>
<button id="dismissButton">Desactivar Alarma</button>
</div>
<div id="log">
<table>
<thead>
<tr>
<th>Fecha</th>
<th>Hora</th>
<th>Video</th>
</tr>
</thead>
<tbody id="logBody">
</tbody>
</table>
<button
<button id="clearButton">Borrar Datos</button>
</div>
</div>

<script>
let port;
let isRunning = false;
let video =
let canvas =
let sensitivity = 50;
let prevFrame = null;
let threshold =
let intruderDetected = false;
let mediaRecorder;
let recordedChunks = [];
let currentTimestamp;
let downloadDirectory;
let downloadDirectoryPath;

document.getElementById('connectButton').addEventListener('click', async () => {
try {
port = await
await port.open({ baudRate: 9600 });

= false;
= true;

console.log('Conectado al puerto serial');

startCamera();
} catch (error) {
console.error('Error al conectar al puerto serial:', error);
alert('Error al conectar al puerto serial. Verifique que el dispositivo esté conectado y vuelva a intentarlo.');
}
});

KepaAlonso
welcome to shbcf.ru