
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Calculate 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
Advertisements