Utkrist Adhikari Utkrist Adhikari - 1 month ago 8
C++ Question

Subtract a vector from each row of matrix in opencv?

I have a matrix or Mat object (say M), and a row vector ,also a Mat object (say V). I want to subtract V from each row of M. I cannot find anything elegent way in openCV to do that, other than writing a custom code myself. Any help?

Answer

How about minus row by row:

for (int r = 0; r < M.rows; ++r) {
    M.row(r) = M.row(r) - V;
}