我有一个使用OpenCV的python脚本。如果我单独运行它会很好,但如果我在Node.js child_process.spawn()旁边运行它会给我一个意想不到的错误。
这是剧本的第一行:
import cv2
import numpy as np
import argparse
import json
parser = argparse.ArgumentParser(description='Analyze a picture of the connector to check the ratio ....')
parser.add_argument('--filename', dest='filename', help='the filename of the picture to be analyzed', required=True)
parser.add_argument('--method', dest='method', help='the method used in the analysis: \'R\' for ROOT histo-fit method, \'M\' for a simple mathematical calculus', choices=['M', 'R'], default='M')
args = parser.parse_args()
print args
print "-------------------"
source_img = cv2.imread(args.filename)
gray_img=cv2.cvtColor(source_img, cv2.COLOR_BGR2GRAY)
这是Node.JS中的代码:
script_path=__dirname+'/../../scripts/connector_check.py';
var pic_analysis = spawn ('python', [script_path, '--filename' , req.body.filename]);
pic_analysis.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
当我运行它时,我在控制台上读到:
stderr: Traceback (most recent call last):
stderr: File "/home/osboxes/NSW-PCB-QC/app/oracle_calls/../../scripts/connector_check.py", line 21, in <module>
stderr:
stderr: gray_img=cv2.cvtColor(source_img, cv2.COLOR_BGR2GRAY)
stderr: cv2
stderr: .
stderr: error
stderr: :
stderr: /home/osboxes/OpenCV/opencv-2.4.13/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor
stderr:
child process exited with code 1
当然,我尝试使用相同的文件。
有人可以帮助我理解我错在哪里吗?
谢谢你们