1
当我们手动添加缓冲区的地址data
对象的属性时会发生什么,然后删除该缓冲区?当我们覆盖cv :: Mat.data时发生了什么
例如,
cv::Mat test;
test.data = (address of Buffer A);
时Buffer A
被删除会发生什么test.data
?
当我们手动添加缓冲区的地址data
对象的属性时会发生什么,然后删除该缓冲区?当我们覆盖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.data
你能后的代码做你描述一下? – Tim
为什么不使用这两个构造函数之一? 'Mat(int rows,int cols,int type,void * data,size_t step = AUTO_STEP); 垫(尺寸大小,整型,无效*数据,为size_t步骤= AUTO_STEP);”他们将设置数据指针,以及正确的类型和大小。读到这里的文档http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html –