gpt4 book ai didi

c++ - 当我们覆盖 cv::Mat.data 时会发生什么

转载 作者:太空宇宙 更新时间:2023-11-03 22:25:26 24 4
gpt4 key购买 nike

当我们在 cv::Mat 对象的 data 属性中手动添加缓冲区地址,然后删除该缓冲区时,会发生什么情况?

例如,

cv::Mat test;
test.data = (address of Buffer A);

Buffer A 被删除时,test.data 会发生什么?

最佳答案

文档:http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html

int rows, cols, type; // you need initialize them
void* data = (address of Buffer A)
cv::Mat test = cv::Mat(rows, cols, type, data); // according to documentation, test does not own data
cv::Mat copy = test.clone() // copy copies is a deep copy of test

因此,由于测试不拥有缓冲区 A,一旦它被删除,如果您访问 test.data,它就是 UB。但是,由于copy是深拷贝,所以可以访问copy.data

关于c++ - 当我们覆盖 cv::Mat.data 时会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40753467/

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