How to calculate the number of channels of an image in OpenCV using C++?

OpenCVC++Server Side ProgrammingProgramming

In this topic, we will understand how to find out the number of channels of an image. After running the program, the number of the channel will be shown in the console window.

To get the number of the channel, we have used a class of OpenCV named 'channels()'. When we pass the image matrix as an object of the class 'channels()', it gives the channel an integer value.

The following program counts the number of the channels and show it in the console window.

Example

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
}