I'm working with QT and OpenCV, I have this square that I need to extract but I need to use conversion from RGB to one channel (RED basically). Any advice will be more than welcome, please feel free to advice which functions to use. Thanks in advance.
I think cvSplit
is what you're looking for (docs). You can use it, for example, to split RGB into R, G, and B:
/* assuming src is your source image */
CvSize s = cvSize(src->width, src->height);
int d = src->depth;
IplImage* R = cvCreateImage(s, d, 1);
IplImage* G = cvCreateImage(s, d, 1);
IplImage* B = cvCreateImage(s, d, 1);
cvSplit(src, R, G, B, null);
Note you'll need to be careful about the ordering; make sure that the original image is actually ordered as R, G, B (there's a decent chance it's B, G, R).
Since this is tagged qt
I'll give a C++ answer.
// Create Windows
namedWindow("Red",1);
namedWindow("Green",1);
namedWindow("Blue",1);
// Create Matrices (make sure there is an image in input!)
Mat input;
Mat channel[3];
// The actual splitting.
split(input, channel);
// Display
imshow("Blue", channel[0]);
imshow("Green", channel[1]);
imshow("Red", channel[2]);
Tested on OpenCV 2.4.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With