- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to calculate the number of channels of an image in OpenCV using C++?
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) { Mat image_load;//Declaring a matrix to load the image// image_load = imread("colors.jpg");//Loading image in the matrix// int number_of_channel = image_load.channels();//Storing the number of channels in the variable// cout << "The number of channel(s)=" << number_of_channel << endl;//Showing the number of channels// system("pause");//Pausing the system to check the number of channel// waitKey(0); return 0; }
Output
- Related Articles
- How to split an image into different color channels in OpenCV Python?
- How to change the brightness of an image in OpenCV using C++?
- How to decrease the Brightness of an image in OpenCV using C++?
- How to save an Image in OpenCV using C++?
- How to rotate an image in OpenCV using C++?
- How to split images into different channels in OpenCV using C++?
- How to extract the foreground of an image using OpenCV Python?
- How to compute the morphological gradient of an image using OpenCV in Python?
- How to compute the extent of an object in image using OpenCV Python?
- How to change the size of an image and add a border in OpenCV using C++?
- How to put a text in an image in OpenCV using C++?
- How to alter the contrast of an image using Java OpenCV library?
- How to alter the brightness of an image using Java OpenCV library?
- How to alter the sharpness of an image using Java OpenCV library?
- How to find the Fourier Transform of an image using OpenCV Python?

Advertisements