1

【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)

Original Image

【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).

program

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

enter image description here

【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.

Embedding an OpenCV window into a Qt GUI

9
  • I apologize, you add cv:Mat in Scan and not working? maybe I misunderstood the question? Commented Jul 24, 2019 at 9:07
  • My apologize, too long for this post. The core of my problem is how to openCV's setMouseCallback function on Qt's QGraphicsScene. setMouseCallback( const string &winname, onMouse, 0 ) works on a namedWindow, but I dont know how to make it works in Qt's QGraphicsScene, as in【Question 】 【What I have tried】 Commented Jul 24, 2019 at 9:30
  • I can give an alternative solution, since I had a project similar to your project. Commented Jul 24, 2019 at 9:37
  • I suggest you go purely to QT , OpenCV let them work hard on the core , and let the interface be clean QT Commented Jul 24, 2019 at 9:40
  • 1
    doc.qt.io/archives/qt-5.11/… Commented Jul 24, 2019 at 10:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.