Determining template type when accessing OpenCV Mat elements

后端 未结 3 899
粉色の甜心
粉色の甜心 2021-02-06 08:02

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
         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 08:50

    I know this comes late. However, the real solution to your problem is to use OpenCV functionality to do what you want to do.

    1. create noise vector as you do already (or use the functions that OpenCV provides hint!)
    2. shuffle noise vector so you don't need individual noise_index for each pixel; or create vector of randomised noise beforehand
    3. build a matrix header around your shuffled/random vector: cv::Mat_(noise);
    4. use matrix operations for computation: out = in + noise; or cv::add(in, noise, out);
    5. PROFIT!

    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.

提交回复
热议问题