[nodeJS][python-shell ]如何使用python-shell发送图像?(nodejs to pyth



我正在做一个项目,我需要实时发送图像(帧(。 服务器是 NodeJs,我将在 python-shell 中使用 OpenCV 处理此图像 但是我不知道如何通过python shell将图像发送到python代码。 你能告诉我如何将图像从nodeJS发送到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');
}
)

这是我的代码。 谢谢。

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);
}
});

我解决了它,这是我的代码。

最新更新