Ruchir
Ruchir

Reputation: 845

OpenCV: In a matrix, how to assign same value to all elements in a row

For the following expressions in Matlab, what is the OpenCV equivalent?

A(2,:)=3;

From what I know, I can do it in OpenCV as follows:

Mat Arepeated;
repeat(value, 1, A.cols, Arepeated);
Arepeated.copyTo(A.row(1));

Here value is a 1x1 Mat with value 3. Is there a more efficient way than what I wrote above?

This post suggested about std::fill but the examples show its usage only for a vector object. I'm not sure if it can be applied for Mat objects as well, or is there any other function. Can someone guide please on this?

Upvotes: 4

Views: 4574

Answers (1)

m.s.
m.s.

Reputation: 16334

How about:

A.row(1).setTo(Scalar(value));

Upvotes: 14

Related Questions