Reputation: 111
how can I copy red channel value of a mat image to blue channel using opencv. Thanks in advance.
Upvotes: 1
Views: 2009
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