Ask Your Question

Does OpenCV blobFromImage preserve the aspect ratio of the input image?

asked 2018-06-12 11:12:56 -0500

mhaghighat gravatar image

updated 2018-06-12 11:44:40 -0500

berak gravatar image

I wonder if the cv::blobFromImage() preserves the aspect ratio of the input image when it applies a resize or it stretches the image to the target size.

The documentation says "If crop is false, direct resize without cropping and preserving aspect ratio is performed". The word "and" makes the sentence a bit vague raising the question if "without" applies to the "preserving aspect ratio".

edit retag flag offensive close merge delete



here's what it does

and maybe, one should say: it's preserving the train image ratio , not the aspect ratio of your input image

berak gravatar imageberak ( 2018-06-12 11:24:52 -0500 )edit

So, it does not preserve the aspect ratio. Thanks a lot.

mhaghighat gravatar imagemhaghighat ( 2018-06-12 11:34:14 -0500 )edit

yea, it's a bit backwards. in fact, setting crop to false would preserve your input ratio, but in most cases, this is not desirable, as your image could be one of a dog, 1024x256,with a 128x128 dog somewhere in the middle.

berak gravatar imageberak ( 2018-06-12 11:41:12 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-07-10 17:22:27 -0500

mhaghighat gravatar image

It seems it does notpreserve the aspect ratio:

So, the image will be stretched if the AR of your target size is different than the input image AR. This needs to be considered as the features representing an object may change dramatically with this kind of stretches.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-06-12 11:12:56 -0500

Seen: 346 times

Last updated: Jul 10 '18