OpenCV is a popular computer vision library that provides a variety of tools for tasks like video capture and image processing. The Mat class is central to many of these tasks, providing a flexible data structure for storing and manipulating images.
One of the most powerful features of Mat is the ability to split an image into its component color channels. This is useful for tasks like color balancing and analysis.
Here is an example of splitting an RGB image into its red, green, and blue channels using OpenCV:
```c++
#include
#include
#include
using namespace cv;
int main(int argc, char** argv)
{
Mat image = imread("example.jpg");
Mat channels[3];
split(image, channels);
Mat red_channel = channels[2];
Mat green_channel = channels[1];
Mat blue_channel = channels[0];
imshow("Red Channel", red_channel);
imshow("Green Channel", green_channel);
imshow("Blue Channel", blue_channel);
waitKey(0);
return 0;
}
```
In this example, we load an RGB image from file using imread(). We then create an array of Mat objects to store the three color channels, and use the split() function to populate the array with the channels.
We then create individual Mat objects for each color channel by indexing into the array. Finally, we display each channel in its own window using imshow().
This code uses OpenCV library.
C++ (Cpp) Mat::channels - 30 examples found. These are the top rated real world C++ (Cpp) examples of Mat::channels from package ACM extracted from open source projects. You can rate examples to help us improve the quality of examples.