title: Center of rotated cv::Rect
body: <p>I have an image, and I place a rectangle on the image. Then I rotate the image. How do I get the center of the rectangle on the rotated image?</p>
  
  <p>Or can I rotate a rectangle somehow to put on rotated image? I think in this case rotation must be done along same point with point used to rotate image.</p>
  
  <p>This is the image with a rectangle placed on it.</p>
  
  <p><img src="https://i.stack.imgur.com/JQ7ls.png" alt="enter image description here"></p>
  
  <p>This is the rotated image.</p>
  
  <p><img src="https://i.stack.imgur.com/JVbJX.png" alt="enter image description here"></p>
  
  <p>Here is the code I use to rotate my image:</p>
  
  <pre><code>cv::Mat frame, frameRotated;
  frame = cv::imread("lena.png");
  
  cv::Rect rect(225,250,150,150);
  cv::rectangle(frame, rect, cv::Scalar(0,0,255),2);
  
  int theta = 30;
  double radians = theta * PI / 180.0;            
  
  double sin = abs(std::sin(radians));
  double cos = abs(std::cos(radians));
  
  int newWidth = (int) (frame.cols * cos + frame.rows * sin);
  int newHeight = (int) (frame.cols * sin + frame.rows * cos);
  
  cv::Mat targetMat(cv::Size(newWidth, newHeight), frame.type());
  
  int offsetX = (newWidth - frame.cols) / 2;
  int offsetY = (newHeight - frame.rows) / 2;
  
  frame.copyTo(targetMat.rowRange(offsetY, offsetY + frame.rows).colRange(offsetX, offsetX + frame.cols));
  
  cv::Point2f src_center(targetMat.cols/2.0F, targetMat.rows/2.0F);
  cv::Mat rot_mat = cv::getRotationMatrix2D(src_center, theta, 1.0);
  cv::warpAffine(targetMat, frameRotated, rot_mat, targetMat.size());
  
  imshow("frame", frame); 
  imshow("rotated frame", frameRotated);  
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Suppose I have a point in the rotated image, how do I get corresponding point in the original image using rotation matrix?</p>