I\'m using the following code to add some noise to an image (straight out of the OpenCV reference, page 449 -- explanation of cv::Mat::begin
):
void
I know this comes late. However, the real solution to your problem is to use OpenCV functionality to do what you want to do.
cv::Mat_(noise);
out = in + noise;
or cv::add(in, noise, out);
Another advantage of this method is that OpenCV might employ multithreading, SSE or whatever to speed-up this massive-element operation, which you do not. Your code is simpler, cleaner, and OpenCV does all the nasty type handling for you.