我将 Mat 传递给另一个函数并在被调用函数内更改它。我原以为它是一种更复杂的类型,它会通过引用自动传递,因此矩阵在调用函数中会发生变化,但事实并非如此。有人可以向我解释如何从函数中正确返回更改后的 Mat 吗?
这是代码片段:
void callingFunction(Mat img)
{
Mat tst(100,500,CV_8UC3, Scalar(0,255,0));
saveImg(tst, "Original image", true);
testImg(tst);
saveImg(tst, "Want it to be same as inside testImg but is same as Original", true);
}
void testImg(Mat img)
{
int rs = 50; // rows
int cs = 100; // columns
img = Mat(rs, cs, CV_8UC3, Scalar(255,0,0));
Mat roi(img, Rect(0, 0, cs, rs/2));
roi = Scalar(0,0,255); // change a subsection to a different color
saveImg(img, "inside testImg", true);
}
谢谢!