jeudi 28 février 2019

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

I prepared this small verifiable .ui in Figure 1 that replicates the issue I have:

small example

I am trying to use the QPushButton "Print Screen Both Images" to incrementally save images on Left and Right of the QGraphicsView into two different folders present on my Desktop, see below Figure 2:

destination_folders

I can take a print screen of either the leftScene or the rightScene by just clicking on their related QPushButton Print Screen Left and Print Screen Right.

However, I am trying for this specific case not to use QFileDialog as I need to silently and incrementally save the images in the two different destination folders as I move on with the right/left arrow.

See below the snipped of code I am using:

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);
}

I am missing something in the code but I am not sure what exactly.

The compiler is seinding this allocate()/deallocate() error that I don't understand:

compiler_error

Please shed light on this matter.

Aucun commentaire:

Enregistrer un commentaire