Cycle through pixels with opencv

后端 未结 7 2199
情深已故
情深已故 2020-12-07 17:46

How would I be able to cycle through an image using opencv as if it were a 2d array to get the rgb values of each pixel? Also, would a mat be preferable over an iplimage for

7条回答
  •  天命终不由人
    2020-12-07 18:33

    This is an old question but needs to get updated since opencv is being actively developed. Recently, OpenCV has introduce parallel_for_ which complies with c++11 lambda functions. Here is the example

    parallel_for_(Range(0 , img.rows * img.cols), [&](const Range& range){
        for(int r = range.start; r(i)[j] = doSomethingWithPixel(img.at(i,j));
        }
    });
    

    This is mention-worthy that this method uses the CPU cores in modern computer architectures.

提交回复
热议问题