Вопрос

I'm trying to access a whole channel in a 3 channel image in opencv (to replace a channel with a whole matrix, see below). Is it possible to do so without looping through the individual pixel values?

Mat RGB(320, 480, CV_8UC3)
Mat R(320, 480, CV_8UC1)
Mat G(320, 480, CV_8UC1)
Mat B(320, 480, CV_8UC1)

// First channel of RGB = R
// second channel of RGB = G
// third channel fo RGB = B
Это было полезно?

Решение

Just use split and merge

Mat RGB // source mat
Mat BGR_3[3]; 
split(RGB,RGB_3);  
BGR_3[0]//do some operation Blue channel
BGR_3[1]//do some operation Green Channel
BGR_3[2]//do some operation Red channel

//later merge
Mat dst
merge(BGR_3,3,dst);  
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top