[英]Pass arguments from nodejs to python script using python-shell
I'm trying to run a python script inside a Nodejs project.我正在尝试在 Nodejs 项目中运行 python 脚本。 Everything works pretty well passing a local video URL in my python script, but I need to retrieve the video URL from my MongoDB and pass it to the python script.
Everything works pretty well passing a local video URL in my python script, but I need to retrieve the video URL from my MongoDB and pass it to the python script. Is there a way I can do this?
有没有办法我可以做到这一点? I have made some research and couldn't find a way to solve this issue.
我进行了一些研究,但找不到解决此问题的方法。
app.get('/test', callName);
function callName(req, res) {
PythonShell.run('ai_part/test.py', null, function (err) {
if (err) throw err;
console.log('finished');
});
}
Python code: Python代码:
#Loading the video input
cap = cv2.VideoCapture('test.wmv')
_, img = cap.read()
height, width, _ = img.shape
copy = img.copy()
I don't know if it is clear enough, but I need to pass a video URL acquired from my mongo database into the python function 'VideoCapture(url)'.不知道够不够清楚,不过需要将从我的mongo数据库获取的视频URL传到python function'Video.Capture Thanks in advance!
提前致谢!
Like the documentation tells you,就像文档告诉你的那样,
function callName(req, res) {
let options = {
mode: 'text',
args: [res]
};
PythonShell.run('ai_part/test.py', options, function (err) {
if (err) throw err;
console.log('finished');
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.