【问题标题】:How to save incrementally images loaded on a QGraphicsView using QPushButton & OpenCV::imwrite如何使用 QPushButton 和 OpenCV::imwrite 保存在 QGraphicsView 上加载的增量图像
【发布时间】:2019-03-01 22:11:18
【问题描述】:

我在图 1 中准备了这个小的可验证 .ui,它复制了我遇到的问题:

我正在尝试使用QPushButton“打印屏幕两个图像”将QGraphicsView 左侧和右侧的图像增量保存到我桌面上的两个不同文件夹中,见下图 2:

我可以获取leftScenerightScene 的打印屏幕,只需单击它们相关的QPushButton Print Screen Left 和 Print Screen Right。

但是,对于这种特定情况,我尝试不使用 QFileDialog,因为当我使用右/左箭头继续前进时,我需要静默增量地将图像保存在两个不同的目标文件夹中。

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

ma​​inwindow.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;

ma​​inwindow.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 项目文件或 CMake 中的 LIBS。
  • 您好 Nuzhny,感谢您的评论。您能否输入几行代码,以便我可以将您的答案标记为正确? :)
  • 是的,如果您可以在此处添加那几行代码,我会将您的答案标记为正确,因为编译器现在正在工作

标签: c++11 qt5 opencv3.0 qgraphicsview qgraphicsscene


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 2018-02-07
    • 1970-01-01
    相关资源
    最近更新 更多