Cycle through pixels with opencv

后端 未结 7 2191
情深已故
情深已故 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:40

    Since OpenCV 3.3 (see changelog) it is also possible to use C++11 style for loops:

    // Example 1
    Mat_ img = imread("lena.jpg");
    for( auto& pixel: img ) {
        pixel[0] = gamma_lut[pixel[0]];
        pixel[1] = gamma_lut[pixel[1]];
        pixel[2] = gamma_lut[pixel[2]];
    }
    
    // Example 2
    Mat_ img2 = imread("float_image.exr", cv::IMREAD_UNCHANGED);
    for(auto& p : img2) p *= 2;
    

提交回复
热议问题