你需要從宣佈矩陣分別分配內存A,B &Ç
cv::Mat b(10, 10, CV8U_C1); //this allocates 10 rows and 10 columns of 8 bit data to matrix b
cv::Mat a; //This defines a matrix with an empty header. You *cannot* yet assign data to it - trying to do so will give a segmentation fault
a = b; //matrix a is now equal to matrix b. The underlying data (a pointer to 10 x 10 uints) is shared by both so it is a shallow copy (and thus very efficient). However modifying the data in martix a will now modify the data in matrix b
cv::Mat c(10, 10, CV8U_C1);
b = c; //This will change matrix b to point to the newly allocated data in matrix c. Matrix a now has the sole access to its data as matrix b no longer shares it. Matrix b and c share the same data;
b = a + 1 //This statement makes no sense. Even if it is valid you should never use it - it is completely unclear what it does
爲什麼b = a + 1沒有意義?幾乎每一個linalg庫都會重載操作符,所以我想這很常見。它只是一個元素明智的補充。我的問題是:爲什麼b = a + 1; // b仍然與c和s.t.共享數據b = c; b不應該與c分享數據吧?它應該指向新分配的矩陣a + 1; – memecs