【abstraction】
I am trying to finish a GraphCut segmentation program. Segmentation part is writtern in openCV and GUI part is written in Qt. Segmentation part works just fine. I have a problem in integrating them, that is, I cannot use scribble function (one function in GraphCut) in GUI.
【openCV's Segmentation part】
The code of scribble on a openCV's namedWindow is as following (it works)
namedWindow("Scribble");
Mat myImg = imread(imgFileName, CV_LOAD_IMAGE_COLOR);
imshow("Scribble", myImg);
setMouseCallback("Scribble", onMouse, 0);
in last line, onMouse is the function for scribbling red and blue lines (see pic)
【Qt's GUI part】
I created a ui using QtCreator. The ui is as following pic. Original Image is in QWidget::graphicsView. To show this original image, I used the following code (it works too).
My code for this:
Mat myImg = imread(imgFileName, CV_LOAD_IMAGE_COLOR);
QImage disImage = QImage((const unsigned char*)(myImg.data), myImg.cols, myImg.rows, QImage::Format_RGB888);
QGraphicsScene* scene = new QGraphicsScene;
scene->addPixmap(QPixmap::fromImage(disImage));
ui->graphicsView_OriginalImage->setScene(scene);
ui->graphicsView_OriginalImage->show();
【My Goal】
My goal is to do scribble in this GUI, (in other word, comnbine openCV's segmentation and Qt's GUI) the goal is something like the following pic
【What I have tried】
Main issue is openCV's setMouseCallback function last line in 【openCV's Segmentation part】 takes openCV's namedWindow as input and Original Image in 【Qt's GUI part】is given in Qt's graphicsView.
So I thought if I could convert openCV's namedWindow to Qt's graphicsView, then problem is solved.
I looked up online, trying to use cvGetWindowHandle , but it didn't work, (failed code as following)
QGraphicsScene* scene = new QGraphicsScene;
scene = (QGraphicsScene*)cvGetWindowHandle("Scribble");
scene->addWidget(ui->graphicsView_1, 0);
QImage disImage = QImage((const unsigned char*)(myImg.data), myImg.cols, myImg.rows, QImage::Format_RGB888);
scene->addPixmap(QPixmap::fromImage(disImage));
ui->graphicsView_1->setScene(scene);
ui->graphicsView_1->show();
Also I read the following post, but it seems not an answer to my question.


