我正在开发一个具有图像处理功能的web应用程序。因此,我使用opencv python并使用python shell包实现了节点js的python脚本
index.js强>
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonOptions:['-u'],
scriptPath:'C:/Users/MB/PycharmProjects/NumberPlate/venv/Lib/site-packages',
};
PythonShell.PythonShell.run('./myScript.py', options, function (err, results) {
if (err) throw err;
console.log('finished: %j', results);
});
myScript.py(前几行)
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
# Read the image file
image = cv2.imread('./t30.jpg')
# Convert to Grayscale Image
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Canny Edge Detection
canny_edge = cv2.Canny(gray_image, 170, 200)
我所有的导入、环境变量和映像路径都正常,当我运行myScript.py
时,它运行良好,并提供了输出
错误为:
----- Python Traceback -----
File "C:\Users\user\PycharmProjects\NumberPlate\venv\Lib\site-packages\platedetection2.py", line 11, in <module>
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) {
只有在使用python-shell
执行时才会出现错误
问题是什么?通过python shell运行opencv脚本可以吗
我通过将python脚本中图像的完整路径提供给imread()解决了这个错误
相关问题 更多 >
编程相关推荐