【发布时间】:2017-11-14 02:09:05
【问题描述】:
from PIL import Image
def porcentaje(path):
im = Image.open(path, "r")
im.show()
width, height = im.size
type = im.mode
format = im.format
pixels=im.getdata()
n = len(pixels)
im=im.load()
nblack = 0
noblack=0
for pixel in pixels:
if pixel < 50:
nblack += 1
else:
noblack+=1
porcentajefinal=(nblack*100)/n
print(porcentajefinal)
return(porcentajefinal)
(porcentaje(path))
mainwindow.cpp (QT Creator)
void MainWindow::on_pushButton_2_clicked()
{
QString path = QFileDialog::getOpenFileName(this,
tr("All Files (*)"));
qDebug()<<path;
QDir dir1("D:/QTCProjects/prueba");
QFile file1("D:/QTCProjects/prueba/2_1.py");
QString script1 = "D:/QTCProjects/prueba/2_1.py";
QFile file2(script1);
qDebug() << dir1.exists() << file1.exists() << file2.exists();
// these all result in true, true true
QProcess *myProcess = new QProcess();
myProcess->start("python.exe D:/QTCProjects/prueba/2_1.py" );
myProcess->waitForFinished(-1);
qDebug() << "myProcess:" << myProcess->readAll(); }
这个 python 需要一个名为 path 的变量来运行,我在 qtcreator 中用 Qstring 路径获取这个变量,我如何用 Qprocess 给 python 这个变量。
【问题讨论】:
-
通过cmd调用脚本时如何将参数传递给脚本?如果您展示您如何阅读脚本中的参数的部分内容,这将对我们有所帮助。