【问题标题】:node js create video stream from images sequencenode js从图像序列创建视频流
【发布时间】:2019-02-18 18:41:55
【问题描述】:

我从 python opencv 获取图像,然后我想在浏览器上将图像作为视频流显示给用户。 图像按顺序出现。我在 python Flask 中使用“multipart/x-mixed-replace”执行此操作,但在节点 js 上找不到相同的功能。

【问题讨论】:

    标签: node.js opencv


    【解决方案1】:

    //index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
    
    
    </head>
    <body>
    <img id="image">
    <script>
    
        const socket = io.connect('http://localhost:3000');
        socket.on('image', (image) => {
            const imageElement = document.getElementById('image');
    
            console.log(imageElement);
    
    
            imageElement.src = `data:image/jpeg;base64,${image}`;
    
    
        });
    
    
    </script>
    </body>
    </html>
    

    //server.js

    const express = require('express');
    const cv = require('opencv4nodejs');
    const app = express();
    
    const path = require('path');
    const FPS = 30;
    const server = require('http').Server(app);
    const io = require('socket.io')(server);
    
    
    
    const wCap = new cv.VideoCapture(0);
    
    app.get('/', function (req, res) {
        res.sendFile('index.html', {root: __dirname});
    });
    
    
    setInterval(() => {
        const frame = wCap.read();
        const image = cv.imencode('.jpg', frame).toString('base64');
    
        io.emit('image', image)
    }, 1000/FPS);
    server.listen(3000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-24
      • 2013-12-04
      • 2012-04-02
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多