Unsolved Guidance on mouse draggable ROI (camera embedded on QGraphicsView widget
-
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!
-
@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 ? -
Yes that is correct
-
@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 ? -
Okay cool thanks! I'll see what I can come up with