title: Resize an image to a square but keep aspect ratio c++ opencv
body: <p>Is there a way of resizing images of any shape or size to say <code>[500x500]</code> but have the image's aspect ratio be maintained, levaing the empty space be filled with white/black filler?</p>
  
  <p>So say the image is <code>[2000x1000]</code>, after getting resized to <code>[500x500]</code> making the actual image itself would be <code>[500x250]</code>, with <code>125</code> either side being white/black filler. </p>
  
  <p>Something like this:</p>
  
  <p><strong>Input</strong></p>
  
  <p><img src="https://i.stack.imgur.com/L2Fko.png" alt="enter image description here"></p>
  
  <p><strong>Output</strong></p>
  
  <p><img src="https://i.stack.imgur.com/tvXUj.png" alt="enter image description here"></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I don't wish to simply display the image in a square window, rather have the image changed to that state and then saved to file creating a collection of same size images with as little image distortion as possible.</p>
  
  <p>The only thing I came across asking a similar question was <a href="https://stackoverflow.com/questions/16235089/image-resize-to-square-but-keep-aspect-ratio-and-fill-with-transparency?rq=1"><strong>this post</strong></a>, but its in <code>php</code>. </p>