簡體   English   中英

QCommandLineOption讀取輸入文件

[英]QCommandLineOption reading input files

我正在使用QCommandLineOption讀取輸入文件(在這種情況下為jpg文件)的代碼。 我試圖將注意力集中在如何正確地向其添加文件路徑和名稱以訪問數據上,但這是行不通的。 這是代碼:

#include <iostream>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QString>
#include <QImage>
#include "imageconvert.h"
#include "clanu_process.h"

//--input=/Users/fakepath/coming-soon.jpg --     mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg

int main(int argc, char *argv[])
 {
    // ------------------------------------------
    //Command line parameters management
    QCoreApplication app(argc, argv);
    QCoreApplication::setApplicationName("clanu-inpainting");
    QCoreApplication::setApplicationVersion("1.0");

    QCommandLineParser parser;
    parser.setApplicationDescription("Inpainting Console");
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption inputFileOption(QStringList() << "i" << "input", "Fullpath and extension of the input <file>.", "file");
    parser.addOption(inputFileOption);

    QCommandLineOption maskFileOption(QStringList() << "m" << "mask", "Fullpath and extension of the mask <file>.", "file");
    parser.addOption(maskFileOption);

    QCommandLineOption outputFileOption(QStringList() << "o" << "output", "Fullpath and extension of the output <file>.", "file");
    parser.addOption(outputFileOption);

    // Process the actual command line arguments given by the user
    parser.process(app);

    QString inputFileName  = parser.value(inputFileOption);
    QString maskFileName   = parser.value(maskFileOption);
    QString outputFileName = parser.value(outputFileOption);

    std::cout << " input  " << inputFileName.toStdString()  <<  std::endl;
    std::cout << " output " << outputFileName.toStdString() <<  std::endl;
    std::cout << " mask   " << maskFileName.toStdString()   <<  std::endl;

    if(   maskFileName.isEmpty() ) { std::cout << "!! Mask is NOT SET and must be set!"   << std::endl; return -1; }
    if(  inputFileName.isEmpty() ) { std::cout << "!! Input is NOT SET and must be set!"  << std::endl; return -1; }
    if( outputFileName.isEmpty() ) { std::cout << "!! Output is NOT SET and must be set!" << std::endl; return -1; }

    std::cout << " - Input image file read : " << inputFileName.toStdString() << std::endl;
    std::cout << " - Mask image file read  : " << maskFileName.toStdString() << std::endl;
    std::cout << " - Output image file     : " << outputFileName.toStdString() << std::endl;
    // ------------------------------------------
return 0;
}

我收到“ !!未設置面具,必須設置!” 編譯時,這意味着字符串maskFileName為空。 有任何想法嗎 ?

您的程序運行正常。 我只是編譯並嘗試了,它起作用了。

問題出在您給它的示例參數上:

--input=/Users/fakepath/coming-soon.jpg --     mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg

您需要刪除的空間-- mask 因此將ti更改為:

--input=/Users/fakepath/coming-soon.jpg --mask=/Users/fakepath/coming-soon_mask.jpg --output=/Users/fakepath/coming-soon_out_IFQ1.jpg

附帶說明一下,在處理文件路徑時,最好將它們用雙引號引起來,以在路徑中留出空格:

--input="/Users/fakepath/coming soon.jpg" --mask="/Users/fakepath/coming soon mask.jpg" --output="/Users/fakepath/coming soon out IFQ1.jpg"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM