gpt4 book ai didi

c++ - 将 Mat 转换为不同类型的自身是否安全?

转载 作者:太空狗 更新时间:2023-10-29 22:59:28 25 4
gpt4 key购买 nike

假设我想使用一个 Mat 作为 float。下面的代码可以编译无误。但是,这样做安全吗?

Mat im = imread('test.jpg', CV_LOAD_IMAGE_GRAYSCALE);
im.convertTo(im, CV_32F1);

我想这样做是因为它写得更紧凑,否则我需要创建一个临时的Mat

documentation Mat::convertTo() 没有给出太多关于函数内存使用的信息。

最佳答案

Mat::convertTo 函数在使用就地调用时应该是安全的(即相同的输入和输出 Mat 对象)。

According to OpenCV DevZone ,这个函数在使用inplace calls时确实有一个bug,不过几年前就修复了。

关于c++ - 将 Mat 转换为不同类型的自身是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36820387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com