Display Function in OpenCV C ++

I am not sure if there is a function for this in OpenCV (C ++).

I want to call a user defined function for each cv :: Mat pixel in OpenCV, and the whole result needs to be stored in the matrix.

Can I do this in one line of code (something similar to a map function in Python)?

+4
source share
1 answer

I have not tried this, but according to docs there are STL style iterators for accessing matrix elements:

// compute sum of positive matrix elements, iterator-based variant double sum=0; MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>(); for(; it != it_end; ++it) sum += std::max(*it, 0.); 

If they are implemented correctly, you can use them with std :: for_each something like this:

 std::for_each(M.begin<double>(), M.end<double>(), [](double& e) { /* do something with e */ }); 
+6
source

All Articles