【发布时间】:2021-07-13 14:55:36
【问题描述】:
我有一个垫子。我想根据 Rect 定义的某些区域更新垫子。当我像下面显示的代码一样传递它时,我得到了提到的错误。
void temp2(Mat &A){
//this function updates the value of A in the region defined by the rect.
for(i = 0 to A.rows){
Vec2f *p = reinterpret_cast<Vec2f * >(A.ptr(i));
for(j = 0 to A.cols){
// p[j] = Vec2f(5,5);
}
}
}
void temp1(Mat &A){
Point a(0,0), b(10,10);
Rect t(a,b);
temp2(A(t));
}
void temp(Mat &A){
A = Mat(500, 500, CV_32FC2, Scalar(-1.0, -1.0));
temp1(A);
}
int main(){
Mat A;
temp(A);
}
我查看了解决方案,它说要在 temp2 函数中使 mat A const。我不能在 temp2 函数中使 mat A const,因为我必须更新由 rect 中的 rect 定义的垫子的特定区域temp2 函数。如何以这种方式更新特定区域?
【问题讨论】:
-
temp2(A(t));将修改A类型的新临时对象,然后临时对象及其所有更改在结束时被丢弃;- 这可能是你现在想要做的.请显示Mat的定义并阅读minimal reproducible example -
for(i = 0 to A.rows)- 我不知道你从哪里得到这个语法,但它是错误的。 -
@Yksisarvinen 这是一个伪代码
-
@RichardCritten 它是 cv::Mat