I'm having trouble passing cv::mat data between forms on a qt gui application, for the moment I simply want to pass the Image chosen by the user on the main window and display it on the results page
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.bmp)"));
Lateral= cv::imread(fileName.toAscii().data());
}
In the header file of the main window I definded:-
public:
cv::Mat get_Lateral(cv::Mat img);
cv::Mat get_Posteroanterior();
In the MainWindow.cpp file I have defined the folowing (i've tried a few variations of the method):-
cv::Mat MainWindow::get_Lateral(cv::Mat img ){
Lateral.copyTo(img);
return img;
}
cv::Mat MainWindow::get_Posteroanterior(){
return Posteroanterior;
}
Finally on the new form I have something like this:-
MainWindow Mw ;
cv::Mat op;
Mw.get_Lateral(op);
//(Mw.get_Posteroanterior()).copyTo(op);
cv::namedWindow("Lateral Image");
cv::imshow("Lateral Image",op);
When I run this I get a runtime error, so I added an if statment to check the contents of cv::mat op like this:-
MainWindow Mw ;
cv::Mat op;
Mw.get_Lateral(op);
//(Mw.get_Posteroanterior()).copyTo(op);
if (!op.data)
cv::namedWindow("dud Image");
else{
cv::namedWindow("Lateral Image");
cv::imshow("Lateral Image",op);
}
And I am given the dud image window implying that op is empty.
Any advice on how to do this process properly will be apppreciated, I am fairly new to opencv and c++ so I apologize for any blatant mistakes.
Cheers