Nibin Jose
Nibin Jose

Reputation: 111

Copy one channel data to another channel in Opencv

how can I copy red channel value of a mat image to blue channel using opencv. Thanks in advance.

Upvotes: 1

Views: 2009

Answers (1)

niranjan reddy
niranjan reddy

Reputation: 31

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;
    }
}

Upvotes: 1

Related Questions