Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

opencv

matlab

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?

like image 321
Ruchir Avatar asked Oct 26 '25 11:10

Ruchir


1 Answers

How about:

A.row(1).setTo(Scalar(value));
like image 80
m.s. Avatar answered Oct 29 '25 02:10

m.s.