使用nodejs接收python代码

2024-06-16 15:30:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python-shell运行一个python脚本,该脚本对一个图像进行分类,并返回yes/no(如果该图像是我想要的或不是)。你知道吗

你知道吗节点.js代码:

app.get('/classify', function(req, res) {
    var options = {
        mode: 'text',
        pythonOptions: ['-u'],
        scriptPath: 'src/',
        args: ['--image', '../../images/image.png', 'classifer.xml']
    };

    PythonShell.run('classify_images.py', options, function(err, results) {
        if (err) throw err;
        // results is an array consisting of messages collected during execution 
        console.log('results: %j', results);
    });

    res.send('classify');
});

如果我以python脚本的形式运行该命令,它可以正常工作,但是当我运行它时节点.js,它给了我所有的否定

python命令(在src中)是:

python classify_images.py --image ../../images/image.png classifer.xml

Tags: 图像imagesrc脚本节点pngjsfunction