Ask Your Question

Resize while Keeping Ratio

asked 2019-03-04 05:13:23 -0500

cjacquel gravatar image


How to do a resize with Opencv while keeping the aspect ratio ?

Is it automatically integrated ?

Thank you, Christophe

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-04 08:54:25 -0500

Yashas gravatar image

The aspect ratio is preserved when both width and height are scaled by the same factor.

To resize an image to a fixed width (similar logic for fixed height), scale both the width and height by a scale factor given by:

double scale = float(width)/input.size().width;

cv::resize(inputArray, outputArray, cv::Size(0, 0), scale, scale);

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-03-04 05:13:23 -0500

Seen: 6,449 times

Last updated: Mar 04 '19