Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Guidance on mouse draggable ROI (camera embedded on QGraphicsView widget
Forum Updated to NodeBB v4.3 + New Features

Guidance on mouse draggable ROI (camera embedded on QGraphicsView widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nevind7
    wrote on last edited by
    #1

    Hey, I am new to using Qt and was wanting some assistance in creating a mouse draggable ROI on a webcam.

    My completed application will have a webcam, and will allow the user to drag their mouse across a region of the webcam to create three different regions of interest. I am tracking the changes in light intensity of each region. Essentially, that ROI will create a new Mat object so I can perform the necessary functions on it. At the moment, I am finding it difficult to create the mouse draggable region of interest!

    At the moment, the webcam is up and running nicely.
    I have ui->graphicsView->setDragMode(QGraphicsView::RubberBandDrag); so that I can drag across the camera. I imagine I'll need mouse events? QRubberBand class? QPoint?

    I'm quite new, and would very much appreciate some help on doing this. Here is the portion of code that runs the camera.

        while(video.isOpened())
        {
            video >> frame;
            if(!frame.empty())
            {
                QImage qimg(frame.data,
                            frame.cols,
                            frame.rows,
                            frame.step,
                            QImage::Format_RGB888);
    
                pixmap.setPixmap( QPixmap::fromImage(qimg.rgbSwapped()) );
                ui->graphicsView->fitInView(&pixmap, Qt::IgnoreAspectRatio);
    
    
    
            }
            qApp->processEvents();
        }
    

    Thanks a lot!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @nevind7 said in Guidance on mouse draggable ROI (camera embedded on QGraphicsView widget:

      QGraphicsView::RubberBandDrag

      Well if you use that selection mode, you can get the area with
      QPainterPath QGraphicsScene::selectionArea() const
      for all items selected by the rect area.

      But im not sure it works 100% like you like.
      I imagine, you want the ROIs to stay on screen and there will be multiple and for that
      and hence using a rubberband might be easier/works better.
      I assume you have one Image item and nothing more so user will be drawing rect on that and thats
      should be the ROis ?

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nevind7
        wrote on last edited by
        #3

        Yes that is correct

        mrjjM 1 Reply Last reply
        0
        • N nevind7

          Yes that is correct

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @nevind7
          So its seems more sensible if you use rubberband to specify the rect. Then maybe create
          QGraphicsRectItem object and put lowest in z- order to show user where Area is.
          Then user can also select and delete a ROI.
          I assume that should be possible too ?

          N 1 Reply Last reply
          1
          • mrjjM mrjj

            @nevind7
            So its seems more sensible if you use rubberband to specify the rect. Then maybe create
            QGraphicsRectItem object and put lowest in z- order to show user where Area is.
            Then user can also select and delete a ROI.
            I assume that should be possible too ?

            N Offline
            N Offline
            nevind7
            wrote on last edited by
            #5

            @mrjj

            Okay cool thanks! I'll see what I can come up with

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved