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. [SOLVED]Rotation of ROI

[SOLVED]Rotation of ROI

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k 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.
  • S Offline
    S Offline
    soheil1365
    wrote on last edited by
    #1

    Hello my friends...

    I have drawn a rectangle in one image which is loaded on qgraphicsView.
    I got all of the dimensions from user and drew this rectangle.Now I am going to rotate this rectangle with respect to angle which is given by user...
    How can I do that?

    thanks in advance

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vidar
      wrote on last edited by
      #2

      hmmm, use QGraphicsItem::setRotation ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soheil1365
        wrote on last edited by
        #3

        hello
        excuse me ...can you guide me a little more? I am new comer in Qt and opencv world...
        this is my code...I want to rotate these drawn rectangles as much as angle which is given by user...

        /////////////////////////////////////////////////

        void MainWindow::on_btnSetROI_clicked()
        {
        CvRect rect,rectb,rectn;

        cv::Mat img;
        QGraphicsScene* scene = new QGraphicsScene();
        scene->clear(); //for cleaning the qgraphicsview and loading the image again

        img = imread(filename.toAscii().data());

        //Drawing ROIs

        rect.x=ui->txtx0->toPlainText().toInt();

        rect.y=ui->txty0->toPlainText().toInt();

        rect.height=ui->txtheight->toPlainText().toInt();

        rect.width=ui->txtwidth->toPlainText().toInt();

        cv::rectangle(img,rect,COLOR_RGB2RGBA,1,8,0);

        //ROI white

        rectb.x=ui->txtxb1->toPlainText().toInt();

        rectb.y=ui->txtyb1->toPlainText().toInt();

        rectb.height=ui->txtheightwhite->toPlainText().toInt();

        rectb.width=ui->txtwidthWhite->toPlainText().toInt();

        cv::rectangle(img,rectb,COLOR_RGB2RGBA,1,8,0);

        //ROI black

        rectn.x=ui->txtxn1->toPlainText().toInt();

        rectn.y=ui->txtyn1->toPlainText().toInt();

        rectn.height=ui->txtheightBlack->toPlainText().toInt();

        rectn.width=ui->txtwidthBlack->toPlainText().toInt();

        cv::rectangle(img,rectn,COLOR_RGB2RGBA,1,8,0);
        /////////////////////////////////
        QImage img1 = QImage((const unsigned char*)(img.data), img.cols, img.rows, img.step, QImage::Format_RGB888);
        QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(img1));

        QGraphicsItem* i=new QGraphicsItem() ;
        ui->View->setScene(scene); //"View" is the name of object that I have on my .ui file(form)
        --}

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          I am puzzled what you are trying to achieve.

          All of your image manipulation is being done with OpenCV, which has nothing to do with Qt. If you want OpenCV to draw a rotated rectangle on top of the image you load from a file then you need to refer to the OpenCV documentation as to how you do that.

          If you want to rotate the entire image after you place it into the QGraphicsScene then you use QGraphicsItem::setRotation() on the QGraphicsPixmapItem you create as vidar suggested.

          All of this can be done without OpenCV.

          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