map function in OpenCV C++
c++, opencv
Solution
I have not tried this but according to the docs there are STL style iterators for accessing the elements of a matrix:
// 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 should be able to use them with std::for_each approximately like this
std::for_each(M.begin<double>(), M.end<double>(), [](double& e) { /* do something with e */ });
Problem
I'm not sure if there exists a function in OpenCV (C++) to do this. I want to call a custom defined function for every pixel of an cv::Mat in OpenCV and the entire result should be stored in a matrix. Can I do this in a single line of code (something similar to map function in Python)?