Reputation: 1709
I am trying to resize an cv::Mat img
with OpenCV. When I am using function cv::resize()
, I set src
and dst
img to be the same as input img like cv::resize(img, img)
. And when I test the program, so far it works correctly. But I am a bit confused how the resize function is implemented cause when I read the documentation it said we need to pre-allocate the dst
img before resizing.
Can anyone explain it to me? Thanks.
Upvotes: 1
Views: 2627
Reputation: 50717
As pointed out by @Micka, you don't need to pre-allocate dst
. But you can, if you want to, with different calling conventions.
From OpenCV documentation:
The function resize
resizes the image src
down to or up to the specified size. Note that the initial dst
type or size are not taken into account. Instead, the size and type are derived from the src
, dsize
, fx
, and fy
. If you want to resize src
so that it fits the pre-created dst
, you may call the function as follows:
// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
Upvotes: 2