Julius Julius - 1 month ago 10
C++ Question

Conditional assignment in c++ opencv

In Python with opencv/numpy (2D) arrays

A1, A2, B1, B2
I can do

A1[B1>B2] = A2[B1>B2]


That is, I can assign values to A1 from A2 in places based on a condition between the B arrays.

How can I do this in opencv in C++?
Is the fastest way to simply loop over the arrays, or is there a better way?

Thank you very much in advance.

Answer

Use mask.

Mat m=B1>B2;
A2.copyTo(A1,m);