I'm wondering is there any function in OpenCV, which operates with two cv::Mat
objects alike std::tranform
in STL?
For example,
cv::transform(src1, src2, dst, bin_function);
where
src1
and src2
: input matrices (cv::Mat) of the same size. dst
: output matrix of the same as inputs. bin_function
: binary function or function object that accepts two elements as argument (one of each of the two matrices), and returns some result value. I tried to search in documentation but not found such thing.
As far as I know there is no such function in OpenCV yet. However, you can use the STL algorithm std::transform
on the cv::Mat
iterators like this:
std::transform( src1.begin<float>(), src1.end<float>(),
src2.begin<float>(), dest.begin<float>(), bin_function );
Be sure to use the right template type argument. So if you have a 3-channel matrices with 8 bit for each channel for example, then use Vec3b
instead of float
.
Beware of the usual STL pitfalls though. src1
, src2
and dest
should have the same number of elements before your call to std::transform
. If you need this genericity, you may consider to write a wrapper function cv::transform
yourself, which checks that, reserves memory for dest
. Finding the right type for the template argument dynamically will probably be difficult, since the bin_function
needs to accept all possible arguments. However, even that may be possible in certain specific cases, if you use C++14 lambdas with auto
parameters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.