The process ended forcefully while designing an interface using Qt and OpenCV

62 Views Asked by At

Software environment: QT (5.12.10), OPENCV (4.2.0), CMAKE (3.17.1)

I have designed an image processing system using C++ , which includes an image panorama stitching module. Now, I have encountered a problem where the program throws the following error in this part: Image

Here is the detailed code of the problematic part:

void MainWindow::on_pushButton_2_clicked()
{
    srcDirPath = QFileDialog::getExistingDirectory(this, tr("Choose folder"), "/", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    qDebug() << srcDirPath;
    //FileInfo
    QFileInfo OpenFileInfo;
    OpenFileInfo = QFileInfo(srcDirPath);
    OpenFilePath = OpenFileInfo.filePath();
    ui->lineEdit->setText(OpenFilePath);
}

void MainWindow::on_btn_imgstit_clicked()
{
    // read images from folder
    vector<Mat> images;
    QDir dir(srcDirPath);
    QStringList filters;
    filters << "*.jpg" << "*.png" << "*.bmp";
    QFileInfoList fileList = dir.entryInfoList(filters, QDir::Files|QDir::NoDotAndDotDot);
    foreach(QFileInfo fileInfo, fileList) {
          Mat img = imread(fileInfo.absoluteFilePath().toStdString());
          images.push_back(img);
      }
    // stitch 
    Ptr<Stitcher> stitcher = nullptr;
    stitcher = Stitcher::create();
    cout << " stitcher successfully" << endl;

    Mat result;
    Stitcher::Status status = stitcher->stitch(images,result);

    if (status != Stitcher::OK)
    {
        QMessageBox::warning(nullptr,"提示", "Can't stitch images!",QMessageBox::Yes |  QMessageBox::Yes);
        cout << "Can't stitch images, error code = " << int(status) << endl;
    }
    waitKey();

    QString resultPath = srcDirPath + "/result.jpg";
    imwrite(resultPath.toStdString(), result);
    QImage img = cvMat2QImage(result);
    QImage Image=ImageCenter(img,ui->label_stitcher);
    ui->label_stitcher->setPixmap(QPixmap::fromImage(Image));
    ui->label_stitcher->setAlignment(Qt::AlignCenter);
    statusBar()->showMessage(tr("stitching successfully"));

    for(unsigned int i = 0; i < images.size(); ++i)
    {
        images[i].release();
    }
    cout << "images[i] release successfully " << endl;

    // clear images
    images.clear();
    cout << "images clear successfully " << endl;

    // release stitcher
    stitcher.release();
    stitcher = nullptr;
    cout << "stitcher release successfully " << endl;
}

Program function: The user selects a folder by clicking on "pushButton_2", and then clicks "btn_imgstit" to stitch all the images in the folder into a panorama image and save the result in the same folder.

Through setting breakpoints to debug, I have currently found that the error occurs in the following line of code: Stitcher::Status status = stitcher->stitch(images,result);

In Debug mode, the program throws the following error:

Image

Image

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = picture 
TEMPLATE = app 

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += mainwindow.ui

LIBS += E:\Qt\Qt5.12.10\5.12.10\mingw73_64\lib\libopencv_*.a
INCLUDEPATH += E:\Qt\Qt5.12.10\5.12.10\mingw73_64\include\OpenCV

RESOURCES += \
    myimage.qrc

RC_ICONS = picture.ico

TRANSLATIONS += en_tr.ts zh_tr.ts

Can anyone help me identify the cause of this error and provide a solution? Thank you in advance!

0

There are 0 best solutions below