Updating a submatrix of Mat in OpenCV

前端 未结 2 1479
旧巷少年郎
旧巷少年郎 2021-02-01 18:02

I am working with OpenCV and C++. I have a matrix X like this

Mat X = Mat::zeros(13,6,CV_32FC1);

and I want to update just a submatrix 4x3 of i

2条回答
  •  隐瞒了意图╮
    2021-02-01 18:12

    One of the quickest ways is setting a header matrix pointing to the range of columns/rows you want to update, like this:

    Mat aux = X.colRange(4,7).rowRange(4,8); // you are pointing to submatrix 4x3 at X(4,4)
    

    Now, you can copy your matrix to aux (but actually you will be copying it to X, because aux is just a pointer):

    mat43.copyTo(aux);
    

    Thats it.

提交回复
热议问题