Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I would like to add a scalar to just one row of a matrix

Tags:

c++

opencv

I created a m-by-n matrix Mat and I would like to add a scalar to just one row of this matrix. In order to add a scalar to all elements of the matrix, you can use the following statement: A += b, where A is a Mat object and b in a scalar. But if I wanted to add a scalar to just one row of this matrix, how to perform this operation just as easily?

like image 379
enzom83 Avatar asked Dec 14 '12 23:12

enzom83


1 Answers

This is very easy:

image.row(i) += Scalar(...);

Taken from docs:

There are many different ways to create a Mat object. The most popular options are listed below:

...

Construct a header for a part of another array. It can be a single row, single column, several rows, several columns, rectangular region in the array (called a minor in algebra) or a diagonal. Such operations are also O(1) because the new header references the same data. You can actually modify a part of the array using this feature

...

like image 126
ArtemStorozhuk Avatar answered Oct 17 '22 22:10

ArtemStorozhuk