简体   繁体   中英

Set src and dst img the same for opencv resize function

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.

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM