如何使用 QPushButton 和 OpenCV::imwrite 保存在 QGraphicsView 上加载的增量图像

How to save incrementally images loaded on a QGraphicsView using QPushButton & OpenCV::imwrite

我在图 1 中准备了这个小的可验证文件。ui 复制了我遇到的问题:

我正在尝试使用 QPushButton "Print Screen Both Images" 将 QGraphicsView 左侧和右侧的图像增量保存到桌面上存在的两个不同文件夹中,请参见下图 2:

我可以打印 leftScenerightScene 的打印屏幕,只需单击它们相关的 QPushButton 打印屏幕左侧和打印屏幕右侧。

但是,对于这种特定情况,我正在尝试不使用 QFileDialog,因为我需要在继续使用 right/left 箭头时静默地逐步将图像保存在两个不同的目标文件夹中.

请参阅下面我正在使用的代码片段:

mainwindow.h

public:
    void bothPrintScreen(const std::string& pathImg);
private slots:
    void on_bothPrintScreen_clicked(const std::string& imgPath);
private:
    int counterA=0;
    int counterB=0;

mainwindow.cpp

void MainWindow::on_bothPrintScreen_clicked(const std::string& imgPath)
{
    bothPrintScreen(imgPath);
}

void MainWindow::bothPrintScreen(const std::string& pathImg){
    cv::Mat left, right;
    std::string outA = pathImg+"/printScreenA_"+std::to_string(counterA++)+".png";
    cv::imwrite(outA,left);
    std::string outB = pathImg+"/printScreenB_"+std::to_string(counterB++)+".png";
    cv::imwrite(outB,right);
}

我在代码中遗漏了一些东西,但我不确定到底是什么。

编译器正在搜索这个我不理解的 allocate()/deallocate() 错误:

请说明此事。

需要将 OpenCV 库添加到您的 Qt 项目中 ()

INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries