在Opencv中将一个通道数据复制到另一个通道

时间:2016-06-21 07:52:50

标签: c++ opencv c++11 opencv3.0

如何使用opencv将mat图像的红色通道值复制到蓝色通道。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

cv::Mat Image =cv::imread("image.jpg");
uint8_t * orig_ptr = (uint8_t*)Image.data;
for (int y = 0; y < Image.rows; y++)
        {
            for (int x = 0; x < Image.cols; x++)
            {
                int R = orig_ptr[x * 3 + y*Image.step + 2];
                orig_ptr[x * 3 + y*Image.step + 1] = R;
                orig_ptr[x * 3 + y*Image.step] = R;
   }
}