简体   繁体   English

[nodeJS][python-shell]如何使用python-shell发送图片?(nodejs到python)

[英][nodeJS][python-shell]How to send image using python-shell?(nodejs to python)

I'm working on a project and I need to send image(frame) in realtime.我正在做一个项目,我需要实时发送图像(帧)。 Server is NodeJs, and I will process this image using OpenCV in python-shell But I don't know how to send Image through python shell, to python code.. can you tell me how to send image from nodejs to python? Server is NodeJs, and I will process this image using OpenCV in python-shell But I don't know how to send Image through python shell, to python code.. can you tell me how to send image from nodejs to python?

var PythonShell = require('python-shell');


var options = {
    mode: 'text',
    pythonOptions:['-u'],
    scriptPath:'C:/Users/multi/'
};


PythonShell.PythonShell.run("pycudacode.py",options,function(err){
    if(err) console.log('err msg:', err);
    console.log('finishied');
}
)

this is my code.这是我的代码。 thank you.谢谢你。

global.pyshell = require('python-shell');
var fs = require("fs");


var data = fs.readFileSync("testimg.jpg"); // I will get video frame from the client.
var base64 = data.toString("base64");

var options = {
    mode: 'text',
    pythonOptions:['-u'],
    scriptPath:'C:/Users/multi/'
};



shell = new pyshell.PythonShell("sendex.py",options,function(err){
    if(err) console.log('err msg:', err);
    console.log('finishied');
}
)

shell.send(base64);

shell.on("message", rebase64 => {
    var err = null;
    result = Buffer.from(rebase64, "base64");
    console.log(result);
    console.timeEnd("time")
    fs.writeFileSync("result.jpeg",result);
});
shell.end(err=>{
    if(err){
        console.log(err);
    }
});

I solved it and it is my code.我解决了它,这是我的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM