Assuming that i need to show an openCV image in Qt creator.
My image declared with cv::Mat type, but openCV has no member that allows to put an image into Qt application GUI.
Furthermore, i want my code to be able to use this syntax: "image.displayinGUI()" (where image is cv::Mat type). I know how to display image in Qt but I just don't know the right design pattern to deploy inside my program reasonably ( i think the problem is inheritance in C++ , but can't solve it. Remind, i'm not ask any exactly problem , such as Qt or openCV. I wonder how to add new method to old object without edit old code. You can give your suggest with Qt , opencv expample , or any thing in C++ )!
So, what should i do?
(I'm sorry because i'm c++ newbie and my english is not good)
I wrote this scenario but it didn't work:
class usergui : public cv::Mat {
public:
displayinGUI( QLabel* label ) {
cv::Mat newimg = this->clone();
cv::cvtColor( newimg , newimg , CV_BGR2RGB );
QImage image = QImage((const unsigned char*)newimg.data , newimg.cols , newimg.rows , QImage::Format_RGB888);
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->pixmap()->size());
}
}
// in main program:
/* ... */
cv::Mat myimage;
myimage.imread("lenna.png");
myimage.displayinGUI( myQtlabel ); // this cause an error: "cv::Mat has no member named "displayinGUI()"
/* ...*/