0

I am trying to display the images using the following method in c++ where rows and columns are the maximum number of rows and columns in the display window respectively.

Need help on how to maintain the aspect ratio of the image by showing in the same window dimensions where the dimensions are rows and columns.

void showImagesFromVector(vector<String> imagesVector, int rows, int columns) {
      Mat resizedImage;
            cv::resize(image, resizedImage, cv::Size(rows, columns), INTER_LINEAR);
            imshow("image", resizedImage);

}
maanvi m
  • 1
  • 1
  • If the image and the window have different aspect ratios you need to specify how you want to handle that for someone to be able to answer the question. You can either scale the image such that it is bigger than the window viewport in which case it will be clipped or you can letter box/pillar box it so that it fits with black bars either on the top/bottom or right/left? Which do you want? – jwezorek Sep 15 '22 at 00:10
  • 1
    cv::resize can be used with scaling factors by: cv::resize(image, resizedImage, cv::Size(), factorX, factorY, INTER_LINEAR); make sure to choose factorX == factorY to keep aspect ratio. – Micka Sep 15 '22 at 05:05
  • In my case the window size can vary like (640*920). will same condition work. – maanvi m Sep 15 '22 at 13:11

0 Answers0