UNPKG

@libs-scripts-mep/inv-img-tool

Version:

Ferramenta de visão computacional com implementações dedicadas à validação de displays em testes automatizados de linha de produção.

123 lines (102 loc) 4.07 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" /> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> <title>WebSocket Video Stream</title> </head> <body style="background-color:rgb(58, 62, 66)"> <style> /* Estilização para o H2 */ h2 { font-family: 'Arial', sans-serif; color: white; font-size: 2.5em; text-align: center; letter-spacing: 1.5px; margin: 20px 0; } /* Estilização para o botão */ .button { background-color: darkred; border: none; color: white; padding: 15px 30px; text-align: center; font-size: 2em; width: 100%; font-family: 'Arial', sans-serif; border-radius: 10px; cursor: pointer; transition: background-color 0.3s ease; } .button:hover { background-color: rgb(206, 0, 0); } /* Estilização da div */ .image-container { display: flex; gap: 30px; justify-content: center; align-items: center; } </style> <div> <button class="button" id="start">Start</button> </div> <div class="image-container"> <div> <h2>Video Stream</h2> <img id="video" src="" alt="Video Stream" width="640" height="480"> </div> <div> <h2>Result</h2> <img id="result" src="" alt="Video Stream" width="640" height="480"> </div> </div> <script> const ws = new WebSocket('ws://localhost:8765') const streamVideoElement = document.getElementById('video') const resultVideoElement = document.getElementById('result') const workflowResult = new Map() ws.onopen = () => { console.warn("Websocket connected") } ws.onclose = () => { console.warn("Websocket closed") } ws.onerror = (error) => { console.error(error) } ws.onmessage = (event) => { try { const obj = JSON.parse(event.data) if (obj.stream && streamVideoElement != null) { console.log(obj); streamVideoElement.src = 'data:image/jpeg;base64,' + obj.stream streamVideoElement.style.height = obj.size[0] + 'px' streamVideoElement.style.width = obj.size[1] + 'px' } else if (obj.img_result) { workflowResult.set(obj.img_result.name, obj.img_result) if (obj.img_result.image != null && resultVideoElement != null) { resultVideoElement.style.height = obj.img_result.size[0] + 'px' resultVideoElement.style.width = obj.img_result.size[1] + 'px' resultVideoElement.src = 'data:image/jpeg;base64,' + obj.img_result.image if (obj.img_result.result != null) { console.log(obj.img_result) } } } else { console.log(obj) } } catch (error) { console.log(error) } } document.getElementById('start').onclick = function () { const path = 'test/' const fileName = 'test.json' ws.send(JSON.stringify({ wfpath: path, wffilename: fileName, debug: true })) console.log('Start stream command sent.') }; </script> </body> </html>