[英]Set src and dst img the same for opencv resize function
I am trying to resize an cv::Mat img
with OpenCV. 我正在尝试使用OpenCV调整
cv::Mat img
大小。 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)
. 当我使用函数
cv::resize()
,我将src
和dst
img设置为与输入img相同,例如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. 但是,当我阅读文档中所说的调整大小功能的实现方式时,我有点困惑,因为它说我们需要在调整大小之前预先分配
dst
img。
Can anyone explain it to me? 谁能向我解释? Thanks.
谢谢。
As pointed out by @Micka, you don't need to pre-allocate dst
. 正如@Micka指出的那样,您无需预先分配
dst
。 But you can, if you want to, with different calling conventions. 但是,如果需要,可以使用不同的调用约定。
From OpenCV documentation : 从OpenCV文档中 :
The function resize
resizes the image src
down to or up to the specified size. 函数
resize
大小可将图像src
调整为指定大小或最大。 Note that the initial dst
type or size are not taken into account. 请注意,未考虑初始
dst
类型或大小。 Instead, the size and type are derived from the src
, dsize
, fx
, and fy
. 而是从
src
, dsize
, fx
和fy
派生大小和类型。 If you want to resize src
so that it fits the pre-created dst
, you may call the function as follows: 如果要调整
src
大小以使其适合预先创建的dst
,则可以按以下方式调用该函数:
// explicitly specify dsize=dst.size(); fx and fy will be computed from that. resize(src, dst, dst.size(), 0, 0, interpolation);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.