[SOLVED]Rotation of ROI
-
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
-
hmmm, use QGraphicsItem::setRotation ?
-
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 againimg = 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)
--} -
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.