title: Rotate an image without cropping in OpenCV in C++
body: <p>I'd like to rotate an image, but I can't obtain the rotated image without cropping</p>
  <p>My original image:</p>
  <p><img src="https://i.stack.imgur.com/DrWo9.png" alt="enter image description here" /></p>
  <p>Now I use this code:</p>
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  
  // Compile with g++ code.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc
  
  int main()
  {
      cv::Mat src = cv::imread(&quot;im.png&quot;, CV_LOAD_IMAGE_UNCHANGED);
      cv::Mat dst;
  
      cv::Point2f pc(src.cols/2., src.rows/2.);
      cv::Mat r = cv::getRotationMatrix2D(pc, -45, 1.0);
  
      cv::warpAffine(src, dst, r, src.size()); // what size I should use?
  
      cv::imwrite(&quot;rotated_im.png&quot;, dst);
  
      return 0;
  }
  </code></pre>
  <p>And obtain the following image:</p>
  <p><img src="https://i.stack.imgur.com/9Gnvo.png" alt="enter image description here" /></p>
  <p><strong>But I'd like to obtain this:</strong></p>
  <p><img src="https://i.stack.imgur.com/aaHhV.png" alt="enter image description here" /></p>